leantesting 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/LICENSE +10 -0
  4. data/README.md +348 -0
  5. data/Rakefile +9 -0
  6. data/leantesting.gemspec +20 -0
  7. data/lib/BaseClass/APIRequest.rb +195 -0
  8. data/lib/BaseClass/Entity.rb +33 -0
  9. data/lib/BaseClass/EntityHandler.rb +183 -0
  10. data/lib/BaseClass/EntityList.rb +188 -0
  11. data/lib/Entity/Bug/Bug.rb +11 -0
  12. data/lib/Entity/Bug/BugAttachment.rb +7 -0
  13. data/lib/Entity/Bug/BugComment.rb +7 -0
  14. data/lib/Entity/Platform/PlatformBrowser.rb +10 -0
  15. data/lib/Entity/Platform/PlatformBrowserVersion.rb +7 -0
  16. data/lib/Entity/Platform/PlatformDevice.rb +7 -0
  17. data/lib/Entity/Platform/PlatformOS.rb +10 -0
  18. data/lib/Entity/Platform/PlatformOSVersion.rb +7 -0
  19. data/lib/Entity/Platform/PlatformType.rb +10 -0
  20. data/lib/Entity/Project/Project.rb +27 -0
  21. data/lib/Entity/Project/ProjectBugScheme.rb +7 -0
  22. data/lib/Entity/Project/ProjectSection.rb +7 -0
  23. data/lib/Entity/Project/ProjectUser.rb +7 -0
  24. data/lib/Entity/Project/ProjectVersion.rb +7 -0
  25. data/lib/Entity/User/UserOrganization.rb +7 -0
  26. data/lib/Exception/BaseException/SDKException.rb +19 -0
  27. data/lib/Exception/SDKBadJSONResponseException.rb +15 -0
  28. data/lib/Exception/SDKDuplicateRequestException.rb +19 -0
  29. data/lib/Exception/SDKErrorResponseException.rb +13 -0
  30. data/lib/Exception/SDKIncompleteRequestException.rb +19 -0
  31. data/lib/Exception/SDKInvalidArgException.rb +15 -0
  32. data/lib/Exception/SDKMissingArgException.rb +15 -0
  33. data/lib/Exception/SDKUnexpectedResponseException.rb +15 -0
  34. data/lib/Exception/SDKUnsupportedRequestException.rb +19 -0
  35. data/lib/Handler/Attachment/AttachmentsHandler.rb +17 -0
  36. data/lib/Handler/Auth/OAuth2Handler.rb +118 -0
  37. data/lib/Handler/Bug/BugAttachmentsHandler.rb +51 -0
  38. data/lib/Handler/Bug/BugCommentsHandler.rb +20 -0
  39. data/lib/Handler/Bug/BugsHandler.rb +57 -0
  40. data/lib/Handler/Platform/PlatformBrowserVersionsHandler.rb +20 -0
  41. data/lib/Handler/Platform/PlatformBrowsersHandler.rb +23 -0
  42. data/lib/Handler/Platform/PlatformDevicesHandler.rb +10 -0
  43. data/lib/Handler/Platform/PlatformHandler.rb +22 -0
  44. data/lib/Handler/Platform/PlatformOSHandler.rb +23 -0
  45. data/lib/Handler/Platform/PlatformOSVersionsHandler.rb +20 -0
  46. data/lib/Handler/Platform/PlatformTypeDevicesHandler.rb +20 -0
  47. data/lib/Handler/Platform/PlatformTypesHandler.rb +21 -0
  48. data/lib/Handler/Project/ProjectBugReproducibilitySchemeHandler.rb +20 -0
  49. data/lib/Handler/Project/ProjectBugSeveritySchemeHandler.rb +20 -0
  50. data/lib/Handler/Project/ProjectBugStatusSchemeHandler.rb +20 -0
  51. data/lib/Handler/Project/ProjectBugTypeSchemeHandler.rb +20 -0
  52. data/lib/Handler/Project/ProjectBugsHandler.rb +67 -0
  53. data/lib/Handler/Project/ProjectSectionsHandler.rb +39 -0
  54. data/lib/Handler/Project/ProjectUsersHandler.rb +20 -0
  55. data/lib/Handler/Project/ProjectVersionsHandler.rb +39 -0
  56. data/lib/Handler/Project/ProjectsHandler.rb +46 -0
  57. data/lib/Handler/User/UserHandler.rb +14 -0
  58. data/lib/Handler/User/UserOrganizationsHandler.rb +14 -0
  59. data/lib/leantesting.rb +65 -0
  60. data/lib/loader.rb +18 -0
  61. data/tests/APIRequestTest.rb +152 -0
  62. data/tests/BaseClassesTest.rb +96 -0
  63. data/tests/ClientTest.rb +52 -0
  64. data/tests/EntitiesTest.rb +97 -0
  65. data/tests/EntityListTest.rb +51 -0
  66. data/tests/ExceptionsTest.rb +70 -0
  67. data/tests/HandlersRequestsTest.rb +215 -0
  68. data/tests/MockRequestsTest.rb +556 -0
  69. data/tests/OAuth2HandlerTest.rb +75 -0
  70. data/tests/res/upload_sample.jpg +0 -0
  71. metadata +169 -0
@@ -0,0 +1,20 @@
1
+ class ProjectUsersHandler < EntityHandler
2
+
3
+ def initialize(origin, projectID)
4
+ super(origin)
5
+
6
+ @projectID = projectID
7
+ end
8
+
9
+ def all(filters = nil)
10
+ if !filters
11
+ filters = {}
12
+ end
13
+
14
+ super
15
+
16
+ request = APIRequest.new(@origin, '/v1/projects/' + @projectID.to_s() + '/users', 'GET')
17
+ EntityList.new(@origin, request, ProjectUser, filters)
18
+ end
19
+
20
+ end
@@ -0,0 +1,39 @@
1
+ class ProjectVersionsHandler < EntityHandler
2
+
3
+ def initialize(origin, projectID)
4
+ super(origin)
5
+
6
+ @projectID = projectID
7
+ end
8
+
9
+ def create(fields)
10
+ super
11
+
12
+ supports = {
13
+ 'number' => true
14
+ }
15
+
16
+ if enforce(fields, supports)
17
+ req = APIRequest.new(
18
+ @origin,
19
+ '/v1/projects/' + @projectID.to_s() + '/versions',
20
+ 'POST',
21
+ {'params' => fields}
22
+ )
23
+
24
+ ProjectVersion.new(@origin, req.exec)
25
+ end
26
+ end
27
+
28
+ def all(filters = nil)
29
+ if !filters
30
+ filters = {}
31
+ end
32
+
33
+ super
34
+
35
+ request = APIRequest.new(@origin, '/v1/projects/' + @projectID.to_s() + '/versions', 'GET')
36
+ EntityList.new(@origin, request, ProjectVersion, filters)
37
+ end
38
+
39
+ end
@@ -0,0 +1,46 @@
1
+ class ProjectsHandler < EntityHandler
2
+
3
+ def create(fields)
4
+ super
5
+
6
+ supports = {
7
+ 'name' => true,
8
+ 'organization_id' => false
9
+ }
10
+
11
+ if enforce(fields, supports)
12
+ req = APIRequest.new(@origin, '/v1/projects', 'POST', {'params' => fields})
13
+ Project.new(@origin, req.exec)
14
+ end
15
+ end
16
+
17
+ def all(filters = nil)
18
+ if !filters
19
+ filters = {}
20
+ end
21
+
22
+ super
23
+
24
+ request = APIRequest.new(@origin, '/v1/projects', 'GET')
25
+ EntityList.new(@origin, request, Project, filters)
26
+ end
27
+
28
+ def allArchived(filters = nil)
29
+ if !filters
30
+ filters = {}
31
+ end
32
+
33
+ super
34
+
35
+ request = APIRequest.new(@origin, '/v1/projects/archived', 'GET')
36
+ EntityList.new(@origin, request, Project, filters)
37
+ end
38
+
39
+ def find(id)
40
+ super
41
+
42
+ req = APIRequest.new(@origin, '/v1/projects/' + id.to_s(), 'GET')
43
+ Project.new(@origin, req.exec)
44
+ end
45
+
46
+ end
@@ -0,0 +1,14 @@
1
+ class UserHandler < EntityHandler
2
+ attr_reader :organizations
3
+
4
+ def initialize(origin)
5
+ super
6
+
7
+ @organizations = UserOrganizationsHandler.new(origin)
8
+ end
9
+
10
+ def getInformation
11
+ return (APIRequest.new(@origin, '/v1/me', 'GET')).exec
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ class UserOrganizationsHandler < EntityHandler
2
+
3
+ def all(filters = nil)
4
+ if !filters
5
+ filters = {}
6
+ end
7
+
8
+ super
9
+
10
+ request = APIRequest.new(@origin, '/v1/me/organizations', 'GET')
11
+ EntityList.new(@origin, request, UserOrganization, filters)
12
+ end
13
+
14
+ end
@@ -0,0 +1,65 @@
1
+ #
2
+ # Lean Testing Ruby Client SDK
3
+ #
4
+ # https://leantesting.com/en/api-docs Adheres to official API guidelines
5
+ #
6
+
7
+ require_relative 'loader.rb'
8
+
9
+ module LeanTesting
10
+ class Client
11
+ attr_reader \
12
+ :auth,
13
+ :user,
14
+ :projects,
15
+ :bugs,
16
+ :attachments,
17
+ :platform
18
+
19
+ attr_accessor :debugReturn
20
+
21
+ def initialize
22
+ @accessToken = nil
23
+
24
+ @auth = OAuth2Handler.new(self)
25
+ @user = UserHandler.new(self)
26
+ @projects = ProjectsHandler.new(self)
27
+ @bugs = BugsHandler.new(self)
28
+ @attachments = AttachmentsHandler.new(self)
29
+ @platform = PlatformHandler.new(self)
30
+ end
31
+
32
+ #
33
+ # Function to retrieve curently attached token.
34
+ #
35
+ # Returns:
36
+ # String -- if a token is attached
37
+ # boolean -- if no token is attached
38
+ #
39
+ def getCurrentToken
40
+ if !@accessToken
41
+ return false
42
+ end
43
+
44
+ @accessToken
45
+ end
46
+
47
+ #
48
+ # Function to attach new token to SDK Client instance. Token changes are dynamic; all objects/entities
49
+ # originating from an instance which has had its token updated will utilize the new token automatically.
50
+ #
51
+ # Arguments:
52
+ # accessToken String -- the string of the token to be attached
53
+ #
54
+ # Exceptions:
55
+ # SDKInvalidArgException if provided accessToken param is not a string
56
+ #
57
+ def attachToken(accessToken)
58
+ if !accessToken.is_a? String
59
+ raise SDKInvalidArgException, '`accessToken` must be a string'
60
+ end
61
+ @accessToken = accessToken
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,18 @@
1
+ # Global inclusions
2
+ require 'bundler'
3
+ Bundler.require(:default)
4
+
5
+ # Relative autopath inclusion
6
+ sdkRoot = File.dirname(File.absolute_path(__FILE__))
7
+ [
8
+ 'Exception/BaseException/*.rb',
9
+ 'Exception/*.rb',
10
+
11
+ 'BaseClass/*.rb',
12
+
13
+ 'Entity/**/*.rb',
14
+
15
+ 'Handler/**/*.rb'
16
+ ].each do |path|
17
+ Dir.glob(sdkRoot + '/' + path){ |f| require(f) }
18
+ end
@@ -0,0 +1,152 @@
1
+ require 'bundler'
2
+ Bundler.require(:default, :test)
3
+
4
+ require_relative '../lib/Client'
5
+
6
+ class APIRequestTest < MiniTest::Test
7
+
8
+ def test_APIRequestDefined
9
+ APIRequest
10
+ end
11
+
12
+
13
+
14
+
15
+ def test_APIRequestInstanceNonStrEndpoint
16
+ assert_raises SDKInvalidArgException do
17
+ APIRequest.new(Client.new, 12751, 'GET')
18
+ end
19
+ end
20
+ def test_APIRequestInstanceNonStrMethod
21
+ assert_raises SDKInvalidArgException do
22
+ APIRequest.new(Client.new, '/', 1233)
23
+ end
24
+ end
25
+ def test_APIRequestInstanceSupportedMethod
26
+ APIRequest.new(Client.new, '/', 'GET')
27
+ APIRequest.new(Client.new, '/', 'POST')
28
+ APIRequest.new(Client.new, '/', 'PUT')
29
+ APIRequest.new(Client.new, '/', 'DELETE')
30
+ end
31
+ def test_APIRequestInstanceNonSupportedMethod
32
+ assert_raises SDKInvalidArgException do
33
+ APIRequest.new(Client.new, '/', 'XXX')
34
+ end
35
+ end
36
+ def test_APIRequestInstanceNonArrOpts
37
+ assert_raises SDKInvalidArgException do
38
+ APIRequest.new(Client.new, '/', 'GET', 12123)
39
+ end
40
+ end
41
+ def test_APIRequestBadJSONResponse
42
+ req = APIRequest.new(Client.new, '/any/method', 'GET')
43
+ req.expects(:call).returns({'data'=> '{xxxxxxxxx', 'status'=> 200})
44
+
45
+ ex = assert_raises SDKBadJSONResponseException do
46
+ req.exec
47
+ end
48
+ assert_match '{xxxxxxxxx', ex.message
49
+ end
50
+
51
+
52
+
53
+
54
+
55
+
56
+ def test_APIRequestExpectedStatus
57
+ req = APIRequest.new(Client.new, '/any/method', 'GET')
58
+ req.expects(:call).returns({'data'=> '{"X": "X"}', 'status'=> 200})
59
+ req.exec
60
+
61
+ req = APIRequest.new(Client.new, '/any/method', 'POST')
62
+ req.expects(:call).returns({'data'=> '{"X": "X"}', 'status'=> 200})
63
+ req.exec
64
+
65
+ req = APIRequest.new(Client.new, '/any/method', 'PUT')
66
+ req.expects(:call).returns({'data'=> '{"X": "X"}', 'status'=> 200})
67
+ req.exec
68
+
69
+ req = APIRequest.new(Client.new, '/any/method', 'DELETE')
70
+ req.expects(:call).returns({'data'=> '1', 'status'=> 204})
71
+ req.exec
72
+ end
73
+
74
+
75
+
76
+
77
+
78
+
79
+ def test_APIRequestUnexpectedStatusDELETE
80
+ req = APIRequest.new(Client.new, '/any/method', 'DELETE')
81
+ req.expects(:call).returns({'data'=> 'XXXyyy', 'status'=> 200})
82
+
83
+ ex = assert_raises SDKErrorResponseException do
84
+ req.exec
85
+ end
86
+ assert_match 'XXXyyy', ex.message
87
+ end
88
+
89
+
90
+
91
+
92
+
93
+ def test_APIRequestUnexpectedStatusGET
94
+ req = APIRequest.new(Client.new, '/any/method', 'GET')
95
+ req.expects(:call).returns({'data'=> 'XXXyyy', 'status'=> 204})
96
+
97
+ ex = assert_raises SDKErrorResponseException do
98
+ req.exec
99
+ end
100
+ assert_match 'XXXyyy', ex.message
101
+ end
102
+ def test_APIRequestUnexpectedStatusPOST
103
+ req = APIRequest.new(Client.new, '/any/method', 'POST')
104
+ req.expects(:call).returns({'data'=> 'XXXyyy', 'status'=> 204})
105
+
106
+ ex = assert_raises SDKErrorResponseException do
107
+ req.exec
108
+ end
109
+ assert_match 'XXXyyy', ex.message
110
+ end
111
+ def test_APIRequestUnexpectedStatusPUT
112
+ req = APIRequest.new(Client.new, '/any/method', 'PUT')
113
+ req.expects(:call).returns({'data'=> 'XXXyyy', 'status'=> 204})
114
+
115
+ ex = assert_raises SDKErrorResponseException do
116
+ req.exec
117
+ end
118
+ assert_match 'XXXyyy', ex.message
119
+ end
120
+
121
+
122
+
123
+
124
+ def test_APIRequestEmptyRespGET
125
+ req = APIRequest.new(Client.new, '/any/method', 'GET')
126
+ req.expects(:call).returns({'data'=> '{}', 'status'=> 200})
127
+
128
+ ex = assert_raises SDKUnexpectedResponseException do
129
+ req.exec
130
+ end
131
+ assert_match 'Empty', ex.message
132
+ end
133
+ def test_APIRequestEmptyRespPOST
134
+ req = APIRequest.new(Client.new, '/any/method', 'POST')
135
+ req.expects(:call).returns({'data'=> '{}', 'status'=> 200})
136
+
137
+ ex = assert_raises SDKUnexpectedResponseException do
138
+ req.exec
139
+ end
140
+ assert_match 'Empty', ex.message
141
+ end
142
+ def test_APIRequestEmptyRespPUT
143
+ req = APIRequest.new(Client.new, '/any/method', 'PUT')
144
+ req.expects(:call).returns({'data'=> '{}', 'status'=> 200})
145
+
146
+ ex = assert_raises SDKUnexpectedResponseException do
147
+ req.exec
148
+ end
149
+ assert_match 'Empty', ex.message
150
+ end
151
+
152
+ end
@@ -0,0 +1,96 @@
1
+ require 'bundler'
2
+ Bundler.require(:default, :test)
3
+
4
+ require_relative '../lib/Client'
5
+
6
+ class BaseClassesTest < MiniTest::Test
7
+
8
+ # Entity
9
+ def test_EntityDefined
10
+ Entity
11
+ end
12
+
13
+ def test_EntityDataParsing
14
+ data = {'id' => 1}
15
+ entity = Entity.new(Client.new, data)
16
+
17
+ assert_equal entity.data, data
18
+ end
19
+
20
+ def test_EntityInstanceNonArrData
21
+ assert_raises SDKInvalidArgException do
22
+ Entity.new(Client.new, '')
23
+ end
24
+ end
25
+ def test_EntityInstanceEmptyData
26
+ assert_raises SDKInvalidArgException do
27
+ Entity.new(Client.new, {})
28
+ end
29
+ end
30
+ # END Entity
31
+
32
+
33
+
34
+ # EntityHandler
35
+ def test_EntityHandlerDefined
36
+ EntityHandler
37
+ end
38
+
39
+ def test_EntityHandlerCreateNonArrFields
40
+ assert_raises SDKInvalidArgException do
41
+ EntityHandler.new(Client.new).create('')
42
+ end
43
+ end
44
+ def test_EntityHandlerCreateEmptyFields
45
+ assert_raises SDKInvalidArgException do
46
+ EntityHandler.new(Client.new).create({})
47
+ end
48
+ end
49
+
50
+ def test_EntityHandlerAllNonArrFilters
51
+ assert_raises SDKInvalidArgException do
52
+ EntityHandler.new(Client.new).all('')
53
+ end
54
+ end
55
+ def test_EntityHandlerAllInvalidFilters
56
+ ex = assert_raises SDKInvalidArgException do
57
+ EntityHandler.new(Client.new).all({'XXXfilterXXX' => 9999})
58
+ end
59
+ assert_match 'XXXfilterXXX', ex.message
60
+ end
61
+ def test_EntityHandlerAllSupportedFilters
62
+ EntityHandler.new(Client.new).all({'include' => ''})
63
+ EntityHandler.new(Client.new).all({'limit' => 10})
64
+ EntityHandler.new(Client.new).all({'page' => 2})
65
+ end
66
+
67
+ def test_EntityHandlerFindNonIntID
68
+ assert_raises SDKInvalidArgException do
69
+ EntityHandler.new(Client.new).find('')
70
+ end
71
+ end
72
+
73
+ def test_EntityHandlerDeleteNonIntID
74
+ assert_raises SDKInvalidArgException do
75
+ EntityHandler.new(Client.new).delete('')
76
+ end
77
+ end
78
+
79
+ def test_EntityHandlerUpdateNonIntID
80
+ assert_raises SDKInvalidArgException do
81
+ EntityHandler.new(Client.new).update('', {'x' => 5})
82
+ end
83
+ end
84
+ def test_EntityHandlerUpdateNonArrFields
85
+ assert_raises SDKInvalidArgException do
86
+ EntityHandler.new(Client.new).update(5, '')
87
+ end
88
+ end
89
+ def test_EntityHandlerUpdateEmptyFields
90
+ assert_raises SDKInvalidArgException do
91
+ EntityHandler.new(Client.new).update(5, {})
92
+ end
93
+ end
94
+ # END EntityHandler
95
+
96
+ end