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,52 @@
1
+ require 'bundler'
2
+ Bundler.require(:default, :test)
3
+
4
+ require_relative '../lib/Client'
5
+
6
+ class BaseClassesTest < MiniTest::Test
7
+
8
+ def test_ClientDefined
9
+ Client.new
10
+ end
11
+
12
+
13
+
14
+
15
+ def test_ClientHasAuthObj
16
+ assert_instance_of OAuth2Handler, Client.new.auth
17
+ end
18
+ def test_ClientHasUserObj
19
+ assert_instance_of UserHandler, Client.new.user
20
+ end
21
+ def test_ClientHasProjectsObj
22
+ assert_instance_of ProjectsHandler, Client.new.projects
23
+ end
24
+ def test_ClientHasBugsObj
25
+ assert_instance_of BugsHandler, Client.new.bugs
26
+ end
27
+ def test_ClientHasAttachmentsObj
28
+ assert_instance_of AttachmentsHandler, Client.new.attachments
29
+ end
30
+ def test_ClientHasPlatformObj
31
+ assert_instance_of PlatformHandler, Client.new.platform
32
+ end
33
+
34
+
35
+
36
+ def test_InitialEmptyToken
37
+ assert !Client.new.getCurrentToken
38
+ end
39
+ def test_TokenParseStorage
40
+ tokenName = '__token__test__'
41
+ client = Client.new
42
+ client.attachToken(tokenName)
43
+
44
+ assert_equal client.getCurrentToken, tokenName
45
+ end
46
+ def test_TokenParseNonStr
47
+ assert_raises SDKInvalidArgException do
48
+ Client.new.attachToken(7182381)
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,97 @@
1
+ require 'bundler'
2
+ Bundler.require(:default, :test)
3
+
4
+ require_relative '../lib/Client'
5
+
6
+ class EntitiesTest < MiniTest::Test
7
+
8
+ def setup
9
+ @entityColllection = [
10
+ [Bug, {
11
+ 'comments' => BugCommentsHandler,
12
+ 'attachments' => BugAttachmentsHandler
13
+ }],
14
+ [BugAttachment],
15
+ [BugComment],
16
+ [PlatformBrowser, {
17
+ 'versions' => PlatformBrowserVersionsHandler
18
+ }],
19
+ [PlatformBrowserVersion],
20
+ [PlatformDevice],
21
+ [PlatformOS, {
22
+ 'versions' => PlatformOSVersionsHandler
23
+ }],
24
+ [PlatformOSVersion],
25
+ [PlatformType, {
26
+ 'devices' => PlatformTypeDevicesHandler
27
+ }],
28
+ [Project, {
29
+ 'sections' => ProjectSectionsHandler,
30
+ 'versions' => ProjectVersionsHandler,
31
+ 'users' => ProjectUsersHandler,
32
+
33
+ 'bugTypeScheme' => ProjectBugTypeSchemeHandler,
34
+ 'bugStatusScheme' => ProjectBugStatusSchemeHandler,
35
+ 'bugSeverityScheme' => ProjectBugSeveritySchemeHandler,
36
+ 'bugReproducibilityScheme' => ProjectBugReproducibilitySchemeHandler,
37
+
38
+ 'bugs' => ProjectBugsHandler
39
+ }],
40
+ [ProjectBugScheme],
41
+ [ProjectSection],
42
+ [ProjectUser],
43
+ [ProjectVersion],
44
+ [UserOrganization]
45
+ ]
46
+ end
47
+
48
+
49
+
50
+ def test_EntitiesDefined
51
+ @entityColllection.each { |e| e[0] }
52
+ end
53
+
54
+ def test_EntitiesCorrectParent
55
+ @entityColllection.each { |e| assert_kind_of Entity, e[0].new(Client.new, {'id'=> 1}) }
56
+ end
57
+
58
+ def test_EntitiesDataParsing
59
+ data = {'id'=> 1, 'YY'=> 'strstr', 'FF'=> [1, 2, 3, 'asdasdasd'], 'GG'=> {'test1'=> true, 'test2'=> []}}
60
+ @entityColllection.each do |e|
61
+ assert_equal e[0].new(Client.new, data).data, data
62
+ end
63
+ end
64
+
65
+
66
+
67
+
68
+ def test_EntitiesInstanceNonArrData
69
+ @entityColllection.each do |e|
70
+ assert_raises SDKInvalidArgException do
71
+ e[0].new(Client.new, '')
72
+ end
73
+ end
74
+ end
75
+ def test_EntitiesInstanceEmptyData
76
+ @entityColllection.each do |e|
77
+ assert_raises SDKInvalidArgException do
78
+ e[0].new(Client.new, {})
79
+ end
80
+ end
81
+ end
82
+
83
+
84
+
85
+
86
+
87
+ def test_EntitiesHaveSecondaries
88
+ @entityColllection.each do |e|
89
+ next if e[1].nil?
90
+ e[1].each do |sk, sv|
91
+ assert_instance_of sv, e[0].new(Client.new, {'id'=> 1}).instance_variable_get('@' + sk)
92
+ end
93
+ end
94
+ end
95
+
96
+
97
+ end
@@ -0,0 +1,51 @@
1
+ require 'bundler'
2
+ Bundler.require(:default, :test)
3
+
4
+ require_relative '../lib/Client'
5
+
6
+ class EntityListTest < MiniTest::Test
7
+
8
+ def test_EntityListDefined
9
+ EntityList
10
+ end
11
+
12
+
13
+
14
+ def test_EntityListBadRespMissingMeta
15
+ req = APIRequest.new(Client.new, '/any/method', 'GET')
16
+ req.expects(:call).returns({'data'=> '{"x": []}', 'status'=> 200})
17
+
18
+ ex = assert_raises SDKUnexpectedResponseException do
19
+ EntityList.new(Client.new, req, 'X')
20
+ end
21
+ assert_match 'meta', ex.message
22
+ end
23
+ def test_EntityListBadRespMissingMetaPagination
24
+ req = APIRequest.new(Client.new, '/any/method', 'GET')
25
+ req.expects(:call).returns({'data'=> '{"x": [], "meta": {}}', 'status'=> 200})
26
+
27
+ ex = assert_raises SDKUnexpectedResponseException do
28
+ EntityList.new(Client.new, req, 'X')
29
+ end
30
+ assert_match 'pagination', ex.message
31
+ end
32
+ def test_EntityListBadRespMissingCollection
33
+ req = APIRequest.new(Client.new, '/any/method', 'GET')
34
+ req.expects(:call).returns({'data'=> '{"meta": {"pagination": {}}}', 'status'=> 200})
35
+
36
+ ex = assert_raises SDKUnexpectedResponseException do
37
+ EntityList.new(Client.new, req, 'X')
38
+ end
39
+ assert_match 'collection', ex.message
40
+ end
41
+ def test_EntityListBadRespMultipleCollections
42
+ req = APIRequest.new(Client.new, '/any/method', 'GET')
43
+ req.expects(:call).returns({'data'=> '{"xxy": [], "yyx": [], "meta": {"pagination": {}}}', 'status'=> 200})
44
+
45
+ ex = assert_raises SDKUnexpectedResponseException do
46
+ EntityList.new(Client.new, req, 'X')
47
+ end
48
+ assert_match 'multiple', ex.message
49
+ end
50
+
51
+ end
@@ -0,0 +1,70 @@
1
+ require 'bundler'
2
+ Bundler.require(:default, :test)
3
+
4
+ require_relative '../lib/Client'
5
+
6
+ class ExceptionsTest < MiniTest::Test
7
+
8
+ def setup
9
+ @exceptionCollection = [
10
+ [SDKException],
11
+ [SDKBadJSONResponseException],
12
+ [SDKDuplicateRequestException],
13
+ [SDKErrorResponseException],
14
+ [SDKIncompleteRequestException],
15
+ [SDKInvalidArgException],
16
+ [SDKMissingArgException],
17
+ [SDKUnexpectedResponseException],
18
+ [SDKUnsupportedRequestException]
19
+ ]
20
+ end
21
+
22
+
23
+ def test_ExceptionsDefined
24
+ @exceptionCollection.each { |e| e[0] }
25
+ end
26
+
27
+
28
+
29
+
30
+ def test_ExceptionsRaiseNoArgs
31
+ @exceptionCollection.each do |e|
32
+ ex = assert_raises e[0] do
33
+ raise e[0]
34
+ end
35
+ assert_match 'SDK Error', ex.message
36
+ end
37
+ end
38
+ def test_ExceptionsRaiseWithStr
39
+ @exceptionCollection.each do |e|
40
+ ex = assert_raises e[0] do
41
+ raise e[0], 'XXXmsgXXX'
42
+ end
43
+ assert_match 'XXXmsgXXX', ex.message
44
+ end
45
+ end
46
+
47
+
48
+
49
+ # RAISE WITH ARR (when supported)
50
+ def test_DuplicateRequestRaiseWithArr
51
+ ex = assert_raises SDKDuplicateRequestException do
52
+ raise SDKDuplicateRequestException, ['xx', 'yy', 'zz']
53
+ end
54
+ assert_match 'Duplicate', ex.message
55
+ end
56
+ def test_IncompleteRequestRaiseWithArr
57
+ ex = assert_raises SDKIncompleteRequestException do
58
+ raise SDKIncompleteRequestException, ['xx', 'yy', 'zz']
59
+ end
60
+ assert_match 'Incomplete', ex.message
61
+ end
62
+ def test_UnsupportedRequestRaiseWithArr
63
+ ex = assert_raises SDKUnsupportedRequestException do
64
+ raise SDKUnsupportedRequestException, ['xx', 'yy', 'zz']
65
+ end
66
+ assert_match 'Unsupported', ex.message
67
+ end
68
+ # END RAISE WITH ARR
69
+
70
+ end
@@ -0,0 +1,215 @@
1
+ require 'bundler'
2
+ Bundler.require(:default, :test)
3
+
4
+ require_relative '../lib/Client'
5
+
6
+ class HandlersTest < MiniTest::Test
7
+
8
+ def setup
9
+ @handlerCollection = [
10
+ [AttachmentsHandler],
11
+ [BugAttachmentsHandler, 'requiresIDInConstructor'],
12
+ [BugCommentsHandler, 'requiresIDInConstructor'],
13
+ [BugsHandler],
14
+ [PlatformBrowsersHandler],
15
+ [PlatformBrowserVersionsHandler, 'requiresIDInConstructor'],
16
+ [PlatformDevicesHandler],
17
+ [PlatformHandler],
18
+ [PlatformOSHandler],
19
+ [PlatformOSVersionsHandler, 'requiresIDInConstructor'],
20
+ [PlatformTypeDevicesHandler, 'requiresIDInConstructor'],
21
+ [PlatformTypesHandler],
22
+ [ProjectBugReproducibilitySchemeHandler, 'requiresIDInConstructor'],
23
+ [ProjectBugSeveritySchemeHandler, 'requiresIDInConstructor'],
24
+ [ProjectBugsHandler, 'requiresIDInConstructor'],
25
+ [ProjectBugStatusSchemeHandler, 'requiresIDInConstructor'],
26
+ [ProjectBugTypeSchemeHandler, 'requiresIDInConstructor'],
27
+ [ProjectSectionsHandler, 'requiresIDInConstructor'],
28
+ [ProjectsHandler],
29
+ [ProjectUsersHandler, 'requiresIDInConstructor'],
30
+ [ProjectVersionsHandler, 'requiresIDInConstructor'],
31
+ [UserHandler],
32
+ [UserOrganizationsHandler]
33
+ ]
34
+ end
35
+
36
+
37
+
38
+
39
+ def test_HandlersDefined
40
+ @handlerCollection.each { |e| e[0] }
41
+ end
42
+
43
+
44
+
45
+
46
+ def test_HandlersCreateNonArrFields
47
+ @handlerCollection.each do |e|
48
+ if !e[1].nil? && e[1] == 'requiresIDInConstructor'
49
+ inst = e[0].new(Client.new, 999)
50
+ else
51
+ inst = e[0].new(Client.new)
52
+ end
53
+ assert_raises SDKInvalidArgException do
54
+ inst.create('')
55
+ end
56
+ end
57
+ end
58
+ def test_HandlersCreateEmptyFields
59
+ @handlerCollection.each do |e|
60
+ if !e[1].nil? && e[1] == 'requiresIDInConstructor'
61
+ inst = e[0].new(Client.new, 999)
62
+ else
63
+ inst = e[0].new(Client.new)
64
+ end
65
+ assert_raises SDKInvalidArgException do
66
+ inst.create({})
67
+ end
68
+ end
69
+ end
70
+
71
+
72
+
73
+
74
+
75
+ def test_HandlersAllNonArrFilters
76
+ @handlerCollection.each do |e|
77
+ if !e[1].nil? && e[1] == 'requiresIDInConstructor'
78
+ inst = e[0].new(Client.new, 999)
79
+ else
80
+ inst = e[0].new(Client.new)
81
+ end
82
+ assert_raises SDKInvalidArgException do
83
+ inst.all('')
84
+ end
85
+ end
86
+ end
87
+ def test_HandlersAllInvalidFilters
88
+ @handlerCollection.each do |e|
89
+ if !e[1].nil? && e[1] == 'requiresIDInConstructor'
90
+ inst = e[0].new(Client.new, 999)
91
+ else
92
+ inst = e[0].new(Client.new)
93
+ end
94
+ assert_raises SDKInvalidArgException do
95
+ inst.all({'XXXfilterXXX'=> 9999})
96
+ end
97
+ end
98
+ end
99
+ def test_HandlersAllSupportedFilters
100
+ client = Client.new
101
+ client.debugReturn = {
102
+ 'data'=> '{"x": [], "meta": {"pagination": {}}}',
103
+ 'status'=> 200
104
+ }
105
+
106
+ @handlerCollection.each do |e|
107
+ if !e[1].nil? && e[1] == 'requiresIDInConstructor'
108
+ inst = e[0].new(client, 999)
109
+ else
110
+ inst = e[0].new(client)
111
+ end
112
+
113
+ inst.all({'include'=> ''})
114
+ inst.all({'limit'=> 10})
115
+ inst.all({'page'=> 2})
116
+ end
117
+ end
118
+
119
+
120
+
121
+
122
+
123
+ def test_HandlersFindNonIntID
124
+ @handlerCollection.each do |e|
125
+ if !e[1].nil? && e[1] == 'requiresIDInConstructor'
126
+ inst = e[0].new(Client.new, 999)
127
+ else
128
+ inst = e[0].new(Client.new)
129
+ end
130
+ assert_raises SDKInvalidArgException do
131
+ inst.find('')
132
+ end
133
+ end
134
+ end
135
+
136
+
137
+
138
+
139
+ def test_HandlersDeleteNonIntID
140
+ @handlerCollection.each do |e|
141
+ if !e[1].nil? && e[1] == 'requiresIDInConstructor'
142
+ inst = e[0].new(Client.new, 999)
143
+ else
144
+ inst = e[0].new(Client.new)
145
+ end
146
+ assert_raises SDKInvalidArgException do
147
+ inst.delete('')
148
+ end
149
+ end
150
+ end
151
+
152
+
153
+
154
+
155
+
156
+ def test_HandlersUpdateNonIntID
157
+ @handlerCollection.each do |e|
158
+ if !e[1].nil? && e[1] == 'requiresIDInConstructor'
159
+ inst = e[0].new(Client.new, 999)
160
+ else
161
+ inst = e[0].new(Client.new)
162
+ end
163
+ assert_raises SDKInvalidArgException do
164
+ inst.update('', {'x'=> 5})
165
+ end
166
+ end
167
+ end
168
+ def test_HandlersUpdateNonArrFields
169
+ @handlerCollection.each do |e|
170
+ if !e[1].nil? && e[1] == 'requiresIDInConstructor'
171
+ inst = e[0].new(Client.new, 999)
172
+ else
173
+ inst = e[0].new(Client.new)
174
+ end
175
+ assert_raises SDKInvalidArgException do
176
+ inst.update(5, '')
177
+ end
178
+ end
179
+ end
180
+ def test_HandlersUpdateEmptyFields
181
+ @handlerCollection.each do |e|
182
+ if !e[1].nil? && e[1] == 'requiresIDInConstructor'
183
+ inst = e[0].new(Client.new, 999)
184
+ else
185
+ inst = e[0].new(Client.new)
186
+ end
187
+ assert_raises SDKInvalidArgException do
188
+ inst.update(5, {})
189
+ end
190
+ end
191
+ end
192
+
193
+
194
+
195
+
196
+
197
+ # HAVE SECONDARIES
198
+ def test_PlatformHandlerHasTypes
199
+ assert_instance_of PlatformTypesHandler, PlatformHandler.new(Client.new).types
200
+ end
201
+ def test_PlatformHandlerHasDevices
202
+ assert_instance_of PlatformDevicesHandler, PlatformHandler.new(Client.new).devices
203
+ end
204
+ def test_PlatformHandlerHasOS
205
+ assert_instance_of PlatformOSHandler, PlatformHandler.new(Client.new).os
206
+ end
207
+ def test_PlatformHandlerHasBrowsers
208
+ assert_instance_of PlatformBrowsersHandler, PlatformHandler.new(Client.new).browsers
209
+ end
210
+ def test_UserHandlerHasOrganizations
211
+ assert_instance_of UserOrganizationsHandler, UserHandler.new(Client.new).organizations
212
+ end
213
+ # END HAVE SECONDARIES
214
+
215
+ end