leantesting 1.0.1 → 1.0.2

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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/leantesting.gemspec +1 -1
  4. data/lib/BaseClass/APIRequest.rb +154 -151
  5. data/lib/BaseClass/Entity.rb +25 -24
  6. data/lib/BaseClass/EntityHandler.rb +151 -149
  7. data/lib/BaseClass/EntityList.rb +163 -161
  8. data/lib/Entity/Bug/Bug.rb +10 -8
  9. data/lib/Entity/Bug/BugAttachment.rb +7 -5
  10. data/lib/Entity/Bug/BugComment.rb +7 -5
  11. data/lib/Entity/Platform/PlatformBrowser.rb +9 -7
  12. data/lib/Entity/Platform/PlatformBrowserVersion.rb +7 -5
  13. data/lib/Entity/Platform/PlatformDevice.rb +7 -5
  14. data/lib/Entity/Platform/PlatformOS.rb +9 -7
  15. data/lib/Entity/Platform/PlatformOSVersion.rb +7 -5
  16. data/lib/Entity/Platform/PlatformType.rb +9 -7
  17. data/lib/Entity/Project/Project.rb +24 -22
  18. data/lib/Entity/Project/ProjectBugScheme.rb +7 -5
  19. data/lib/Entity/Project/ProjectSection.rb +7 -5
  20. data/lib/Entity/Project/ProjectUser.rb +7 -5
  21. data/lib/Entity/Project/ProjectVersion.rb +7 -5
  22. data/lib/Entity/User/UserOrganization.rb +7 -5
  23. data/lib/Exception/BaseException/SDKException.rb +15 -13
  24. data/lib/Exception/SDKBadJSONResponseException.rb +13 -11
  25. data/lib/Exception/SDKDuplicateRequestException.rb +15 -13
  26. data/lib/Exception/SDKErrorResponseException.rb +12 -10
  27. data/lib/Exception/SDKIncompleteRequestException.rb +15 -13
  28. data/lib/Exception/SDKInvalidArgException.rb +13 -11
  29. data/lib/Exception/SDKMissingArgException.rb +13 -11
  30. data/lib/Exception/SDKUnexpectedResponseException.rb +13 -11
  31. data/lib/Exception/SDKUnsupportedRequestException.rb +15 -13
  32. data/lib/Handler/Attachment/AttachmentsHandler.rb +14 -12
  33. data/lib/Handler/Auth/OAuth2Handler.rb +102 -100
  34. data/lib/Handler/Bug/BugAttachmentsHandler.rb +44 -42
  35. data/lib/Handler/Bug/BugCommentsHandler.rb +16 -14
  36. data/lib/Handler/Bug/BugsHandler.rb +53 -51
  37. data/lib/Handler/Platform/PlatformBrowserVersionsHandler.rb +16 -14
  38. data/lib/Handler/Platform/PlatformBrowsersHandler.rb +18 -16
  39. data/lib/Handler/Platform/PlatformDevicesHandler.rb +9 -7
  40. data/lib/Handler/Platform/PlatformHandler.rb +20 -18
  41. data/lib/Handler/Platform/PlatformOSHandler.rb +18 -16
  42. data/lib/Handler/Platform/PlatformOSVersionsHandler.rb +16 -14
  43. data/lib/Handler/Platform/PlatformTypeDevicesHandler.rb +16 -14
  44. data/lib/Handler/Platform/PlatformTypesHandler.rb +17 -15
  45. data/lib/Handler/Project/ProjectBugReproducibilitySchemeHandler.rb +16 -14
  46. data/lib/Handler/Project/ProjectBugSeveritySchemeHandler.rb +16 -14
  47. data/lib/Handler/Project/ProjectBugStatusSchemeHandler.rb +16 -14
  48. data/lib/Handler/Project/ProjectBugTypeSchemeHandler.rb +16 -14
  49. data/lib/Handler/Project/ProjectBugsHandler.rb +55 -53
  50. data/lib/Handler/Project/ProjectSectionsHandler.rb +30 -28
  51. data/lib/Handler/Project/ProjectUsersHandler.rb +16 -14
  52. data/lib/Handler/Project/ProjectVersionsHandler.rb +30 -28
  53. data/lib/Handler/Project/ProjectsHandler.rb +34 -32
  54. data/lib/Handler/User/UserHandler.rb +12 -10
  55. data/lib/Handler/User/UserOrganizationsHandler.rb +12 -10
  56. data/tests/APIRequestTest.rb +33 -33
  57. data/tests/BaseClassesTest.rb +28 -28
  58. data/tests/ClientTest.rb +7 -7
  59. data/tests/EntitiesTest.rb +31 -31
  60. data/tests/EntityListTest.rb +13 -13
  61. data/tests/ExceptionsTest.rb +15 -15
  62. data/tests/HandlersRequestsTest.rb +37 -37
  63. data/tests/MockRequestsTest.rb +48 -48
  64. data/tests/OAuth2HandlerTest.rb +19 -19
  65. metadata +2 -1
@@ -1,188 +1,190 @@
1
1
  #
2
2
  # An EntityList is a list of Entity objects, obtained from compiling the results of an all() call.
3
3
  #
4
- class EntityList
5
- attr_reader :collection
6
-
7
- @origin = nil # Reference to originating Client instance
8
-
9
- @identifier = nil # Class definition identifier for the collection Entities
10
- @collection = nil # Internal collection corresponding to current page
11
-
12
- @request = nil # APIRequest definition to use for collection generation
13
- @filters = nil # Filter list for generation (origins in Handler call)
14
-
15
- @pagination = nil # Pagination object as per response (without links)
16
-
17
- #
18
- # Constructs an Entity List instance.
19
- #
20
- # Arguments:
21
- # origin Client -- Original client instance reference
22
- # request APIRequest -- An API Request definition given by the entity collection handler. This is used for any
23
- # subsequent collection regeneration, as any data updates are dependant on external requests.
24
- # identifier Class -- class definition to use for dynamic class instancing within array collection
25
- # filters Hash -- original filters passed over from originating all() call
26
- #
27
- def initialize(origin, request, identifier, filters = nil)
28
- if !filters
29
- filters = {}
30
- end
31
-
32
- @origin = origin
33
- @request = request
34
- @identifier = identifier
35
- @filters = filters
36
-
37
- generateCollectionData
4
+ module LeanTesting
5
+ class EntityList
6
+ attr_reader :collection
7
+
8
+ @origin = nil # Reference to originating Client instance
9
+
10
+ @identifier = nil # Class definition identifier for the collection Entities
11
+ @collection = nil # Internal collection corresponding to current page
12
+
13
+ @request = nil # APIRequest definition to use for collection generation
14
+ @filters = nil # Filter list for generation (origins in Handler call)
15
+
16
+ @pagination = nil # Pagination object as per response (without links)
17
+
18
+ #
19
+ # Constructs an Entity List instance.
20
+ #
21
+ # Arguments:
22
+ # origin Client -- Original client instance reference
23
+ # request APIRequest -- An API Request definition given by the entity collection handler. This is used for any
24
+ # subsequent collection regeneration, as any data updates are dependant on external requests.
25
+ # identifier Class -- class definition to use for dynamic class instancing within array collection
26
+ # filters Hash -- original filters passed over from originating all() call
27
+ #
28
+ def initialize(origin, request, identifier, filters = nil)
29
+ if !filters
30
+ filters = {}
31
+ end
32
+
33
+ @origin = origin
34
+ @request = request
35
+ @identifier = identifier
36
+ @filters = filters
37
+
38
+ generateCollectionData
38
39
 
39
- end
40
-
41
- #
42
- # Sets iterator position to first page. Ignored if already on first page.
43
- #
44
- def first
45
- if @pagination['current_page'] == 1
46
- return false
47
40
  end
48
41
 
49
- @filters['page'] = 1
50
- generateCollectionData
51
- end
42
+ #
43
+ # Sets iterator position to first page. Ignored if already on first page.
44
+ #
45
+ def first
46
+ if @pagination['current_page'] == 1
47
+ return false
48
+ end
52
49
 
53
- #
54
- # Sets iterator position to previous page. Ignored if on first page.
55
- #
56
- def previous
57
- if @pagination['current_page'] == 1
58
- return false
50
+ @filters['page'] = 1
51
+ generateCollectionData
59
52
  end
60
53
 
61
- @filters['page'] -=1
62
- generateCollectionData
63
- end
54
+ #
55
+ # Sets iterator position to previous page. Ignored if on first page.
56
+ #
57
+ def previous
58
+ if @pagination['current_page'] == 1
59
+ return false
60
+ end
64
61
 
65
- #
66
- # Sets iterator position to next page. Ignored if on last page.
67
- #
68
- def next
69
- if @pagination['current_page'] == @pagination['total_pages']
70
- return false
62
+ @filters['page'] -=1
63
+ generateCollectionData
71
64
  end
72
65
 
73
- if @filters.has_key? 'page'
74
- @filters['page'] += 1
75
- else
76
- @filters['page'] = 2
66
+ #
67
+ # Sets iterator position to next page. Ignored if on last page.
68
+ #
69
+ def next
70
+ if @pagination['current_page'] == @pagination['total_pages']
71
+ return false
72
+ end
73
+
74
+ if @filters.has_key? 'page'
75
+ @filters['page'] += 1
76
+ else
77
+ @filters['page'] = 2
78
+ end
79
+
80
+ generateCollectionData
77
81
  end
78
82
 
79
- generateCollectionData
80
- end
83
+ #
84
+ # Sets iterator position to last page. Ignored if already on last page.
85
+ #
86
+ def last
87
+ if @pagination['current_page'] == @pagination['total_pages']
88
+ return false
89
+ end
81
90
 
82
- #
83
- # Sets iterator position to last page. Ignored if already on last page.
84
- #
85
- def last
86
- if @pagination['current_page'] == @pagination['total_pages']
87
- return false
91
+ @filters['page'] = @pagination['total_pages']
92
+ generateCollectionData
88
93
  end
89
94
 
90
- @filters['page'] = @pagination['total_pages']
91
- generateCollectionData
92
- end
93
-
94
- #
95
- # Internal loop handler for emulating enumerable functionality
96
- #
97
- def each
98
- first
99
- begin
100
- yield toArray
101
- end while self.next
102
- end
103
-
104
- #
105
- # Outputs total number of Entities inside multi-page collection
106
- #
107
- # Returns:
108
- # Fixnum -- Number of total Entities
109
- #
110
- def total
111
- @pagination['total']
112
- end
113
-
114
- #
115
- # Outputs total number of pages the multi-page collection has, regardful of limit/per_page
116
- #
117
- # Returns:
118
- # Fixnum -- Number of total pages
119
- #
120
- def totalPages
121
- @pagination['total_pages']
122
- end
123
-
124
- #
125
- # Outputs number of Entities in current collection page. Will always be same as limmit/per_page if not on last page.
126
- #
127
- # Returns:
128
- # Fixnum -- Number of Entities in page
129
- #
130
- def count
131
- @pagination['count']
132
- end
95
+ #
96
+ # Internal loop handler for emulating enumerable functionality
97
+ #
98
+ def each
99
+ first
100
+ begin
101
+ yield toArray
102
+ end while self.next
103
+ end
133
104
 
134
- #
135
- # Outputs internal collection in array format (converted from Entity objects)
136
- #
137
- # Returns:
138
- # Array -- array of elements converted into hashes
139
- #
140
- def toArray
141
- @collection.map{ |entity| entity.data }
142
- end
105
+ #
106
+ # Outputs total number of Entities inside multi-page collection
107
+ #
108
+ # Returns:
109
+ # Fixnum -- Number of total Entities
110
+ #
111
+ def total
112
+ @pagination['total']
113
+ end
143
114
 
144
- private
145
-
146
- #
147
- # (Re)generates internal collection data based on current iteration position.
148
- #
149
- # Regeneration is done every time position changes (i.e. every time repositioning functions are used).
150
- #
151
- # Exceptions:
152
- # SDKUnexpectedResponseException if no `meta` field is found
153
- # SDKUnexpectedResponseException if no `pagination` field is found in `meta field`
154
- # SDKUnexpectedResponseException if no collection set is found
155
- # SDKUnexpectedResponseException if multiple collection sets are found
156
- #
157
- def generateCollectionData
158
- @collection = [] # Clear previous collection data on fresh regeneration
159
- @pagination = {} # Clear previous pagination data on fresh regeneration
160
-
161
- @request.updateOpts({'params' => @filters})
162
- raw = @request.exec
163
-
164
- if !raw.has_key? 'meta'
165
- raise SDKUnexpectedResponseException, 'missing `meta` field'
166
- elsif !raw['meta'].has_key? 'pagination'
167
- raise SDKUnexpectedResponseException, '`meta` missing `pagination` field'
115
+ #
116
+ # Outputs total number of pages the multi-page collection has, regardful of limit/per_page
117
+ #
118
+ # Returns:
119
+ # Fixnum -- Number of total pages
120
+ #
121
+ def totalPages
122
+ @pagination['total_pages']
168
123
  end
169
124
 
170
- if raw['meta']['pagination'].has_key? 'links'
171
- raw['meta']['pagination'].delete('links') # Remove not needed links sub-data
125
+ #
126
+ # Outputs number of Entities in current collection page. Will always be same as limmit/per_page if not on last page.
127
+ #
128
+ # Returns:
129
+ # Fixnum -- Number of Entities in page
130
+ #
131
+ def count
132
+ @pagination['count']
172
133
  end
173
134
 
174
- @pagination = raw['meta']['pagination'] # Pass pagination data as per response meta key
175
- raw.delete('meta')
135
+ #
136
+ # Outputs internal collection in array format (converted from Entity objects)
137
+ #
138
+ # Returns:
139
+ # Array -- array of elements converted into hashes
140
+ #
141
+ def toArray
142
+ @collection.map{ |entity| entity.data }
143
+ end
176
144
 
177
- if raw.length.zero?
178
- raise SDKUnexpectedResponseException, 'collection object missing'
179
- elsif raw.length > 1
180
- cols = raw.map{ |k,| k }.join(', ')
181
- raise SDKUnexpectedResponseException, 'expected one collection object, multiple received: ' + cols
145
+ private
146
+
147
+ #
148
+ # (Re)generates internal collection data based on current iteration position.
149
+ #
150
+ # Regeneration is done every time position changes (i.e. every time repositioning functions are used).
151
+ #
152
+ # Exceptions:
153
+ # SDKUnexpectedResponseException if no `meta` field is found
154
+ # SDKUnexpectedResponseException if no `pagination` field is found in `meta field`
155
+ # SDKUnexpectedResponseException if no collection set is found
156
+ # SDKUnexpectedResponseException if multiple collection sets are found
157
+ #
158
+ def generateCollectionData
159
+ @collection = [] # Clear previous collection data on fresh regeneration
160
+ @pagination = {} # Clear previous pagination data on fresh regeneration
161
+
162
+ @request.updateOpts({'params' => @filters})
163
+ raw = @request.exec
164
+
165
+ if !raw.has_key? 'meta'
166
+ raise SDKUnexpectedResponseException, 'missing `meta` field'
167
+ elsif !raw['meta'].has_key? 'pagination'
168
+ raise SDKUnexpectedResponseException, '`meta` missing `pagination` field'
169
+ end
170
+
171
+ if raw['meta']['pagination'].has_key? 'links'
172
+ raw['meta']['pagination'].delete('links') # Remove not needed links sub-data
173
+ end
174
+
175
+ @pagination = raw['meta']['pagination'] # Pass pagination data as per response meta key
176
+ raw.delete('meta')
177
+
178
+ if raw.length.zero?
179
+ raise SDKUnexpectedResponseException, 'collection object missing'
180
+ elsif raw.length > 1
181
+ cols = raw.map{ |k,| k }.join(', ')
182
+ raise SDKUnexpectedResponseException, 'expected one collection object, multiple received: ' + cols
183
+ end
184
+
185
+ classDef = @identifier # Definition to be used for dynamic Entity instancing
186
+ raw.values[0].each{ |entity| @collection.push(classDef.new(@origin, entity)) }
182
187
  end
183
188
 
184
- classDef = @identifier # Definition to be used for dynamic Entity instancing
185
- raw.values[0].each{ |entity| @collection.push(classDef.new(@origin, entity)) }
186
189
  end
187
-
188
- end
190
+ end
@@ -1,11 +1,13 @@
1
- class Bug < Entity
2
- attr_reader :comments, :attachments
1
+ module LeanTesting
2
+ class Bug < LeanTesting::Entity
3
+ attr_reader :comments, :attachments
3
4
 
4
- def initialize(origin, data)
5
- super
5
+ def initialize(origin, data)
6
+ super
6
7
 
7
- @comments = BugCommentsHandler.new(origin, data['id'])
8
- @attachments = BugAttachmentsHandler.new(origin, data['id'])
9
- end
8
+ @comments = BugCommentsHandler.new(origin, data['id'])
9
+ @attachments = BugAttachmentsHandler.new(origin, data['id'])
10
+ end
10
11
 
11
- end
12
+ end
13
+ end
@@ -1,7 +1,9 @@
1
- class BugAttachment < Entity
1
+ module LeanTesting
2
+ class BugAttachment < LeanTesting::Entity
2
3
 
3
- def initialize(origin, data)
4
- super
5
- end
4
+ def initialize(origin, data)
5
+ super
6
+ end
6
7
 
7
- end
8
+ end
9
+ end
@@ -1,7 +1,9 @@
1
- class BugComment < Entity
1
+ module LeanTesting
2
+ class BugComment < LeanTesting::Entity
2
3
 
3
- def initialize(origin, data)
4
- super
5
- end
4
+ def initialize(origin, data)
5
+ super
6
+ end
6
7
 
7
- end
8
+ end
9
+ end
@@ -1,10 +1,12 @@
1
- class PlatformBrowser < Entity
2
- attr_reader :versions
1
+ module LeanTesting
2
+ class PlatformBrowser < LeanTesting::Entity
3
+ attr_reader :versions
3
4
 
4
- def initialize(origin, data)
5
- super
5
+ def initialize(origin, data)
6
+ super
6
7
 
7
- @versions = PlatformBrowserVersionsHandler.new(origin, data['id'])
8
- end
8
+ @versions = PlatformBrowserVersionsHandler.new(origin, data['id'])
9
+ end
9
10
 
10
- end
11
+ end
12
+ end
@@ -1,7 +1,9 @@
1
- class PlatformBrowserVersion < Entity
1
+ module LeanTesting
2
+ class PlatformBrowserVersion < LeanTesting::Entity
2
3
 
3
- def initialize(origin, data)
4
- super
5
- end
4
+ def initialize(origin, data)
5
+ super
6
+ end
6
7
 
7
- end
8
+ end
9
+ end
@@ -1,7 +1,9 @@
1
- class PlatformDevice < Entity
1
+ module LeanTesting
2
+ class PlatformDevice < LeanTesting::Entity
2
3
 
3
- def initialize(origin, data)
4
- super
5
- end
4
+ def initialize(origin, data)
5
+ super
6
+ end
6
7
 
7
- end
8
+ end
9
+ end