Merge lp:~mfisch/ubuntu-accomplishments-daemon/ubuntu-accomplishments-daemon-more-unittests into lp:ubuntu-accomplishments-daemon
- ubuntu-accomplishments-daemon-more-unittests
- Merge into accomplishments-daemon
Proposed by
Matt Fischer
Status: | Merged |
---|---|
Merged at revision: | 103 |
Proposed branch: | lp:~mfisch/ubuntu-accomplishments-daemon/ubuntu-accomplishments-daemon-more-unittests |
Merge into: | lp:ubuntu-accomplishments-daemon |
Diff against target: |
518 lines (+232/-104) 9 files modified
accomplishments/daemon/api.py (+1/-1) accomplishments/daemon/tests/accomps/first.accomplishment (+2/-1) accomplishments/daemon/tests/accomps/second.accomplishment (+1/-0) accomplishments/daemon/tests/accomps/third.accomplishment (+1/-0) accomplishments/daemon/tests/extrainformation/info (+9/-0) accomplishments/daemon/tests/extrainformation/info2 (+23/-0) accomplishments/daemon/tests/tests.py (+188/-101) debian/control (+1/-0) debian/rules (+6/-1) |
To merge this branch: | bzr merge lp:~mfisch/ubuntu-accomplishments-daemon/ubuntu-accomplishments-daemon-more-unittests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Rafał Cieślak | Pending | ||
Review via email: mp+114960@code.launchpad.net |
Commit message
Description of the change
This has more unit tests, some clean-up of how I was testing exceptions and fixes a bug in the API that cielak found:
Basically if the value is not set (is ''), when you call get_extra_
<cielak> which causes that if - in get_extra_info - value is '', then label will be empty too
<cielak> api.py, line 837
<mfisch> whats the fix?
<cielak> api.py, line 837 is now:
<cielak> final = [{item : "", "label" : ""}]
<cielak> should be:
<cielak> final = [{item : "", "label" : label}]
To post a comment you must log in.
- 104. By Matt Fischer
-
run tests during build
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'accomplishments/daemon/api.py' | |||
2 | --- accomplishments/daemon/api.py 2012-07-13 20:01:07 +0000 | |||
3 | +++ accomplishments/daemon/api.py 2012-07-14 02:21:18 +0000 | |||
4 | @@ -834,7 +834,7 @@ | |||
5 | 834 | final = [{item : data, "label" : label}] | 834 | final = [{item : data, "label" : label}] |
6 | 835 | except IOError as e: | 835 | except IOError as e: |
7 | 836 | #print "No data." | 836 | #print "No data." |
9 | 837 | final = [{item : "", "label" : ""}] | 837 | final = [{item : "", "label" : label}] |
10 | 838 | return final | 838 | return final |
11 | 839 | 839 | ||
12 | 840 | # ================================================================= | 840 | # ================================================================= |
13 | 841 | 841 | ||
14 | === modified file 'accomplishments/daemon/tests/accomps/first.accomplishment' | |||
15 | --- accomplishments/daemon/tests/accomps/first.accomplishment 2012-07-12 21:10:53 +0000 | |||
16 | +++ accomplishments/daemon/tests/accomps/first.accomplishment 2012-07-14 02:21:18 +0000 | |||
17 | @@ -2,5 +2,6 @@ | |||
18 | 2 | title=My First Accomplishment | 2 | title=My First Accomplishment |
19 | 3 | icon=first.jpg | 3 | icon=first.jpg |
20 | 4 | description=An example accomplishment for the test suite | 4 | description=An example accomplishment for the test suite |
22 | 5 | needs-information=info,more info | 5 | needs-information=info,info2 |
23 | 6 | collection = testaccomp | 6 | collection = testaccomp |
24 | 7 | author = Tester <tester@tester> | ||
25 | 7 | 8 | ||
26 | === modified file 'accomplishments/daemon/tests/accomps/second.accomplishment' | |||
27 | --- accomplishments/daemon/tests/accomps/second.accomplishment 2012-07-12 21:10:53 +0000 | |||
28 | +++ accomplishments/daemon/tests/accomps/second.accomplishment 2012-07-14 02:21:18 +0000 | |||
29 | @@ -5,3 +5,4 @@ | |||
30 | 5 | depends=testaccomp/first | 5 | depends=testaccomp/first |
31 | 6 | needs-signing=True | 6 | needs-signing=True |
32 | 7 | collection=testaccomp | 7 | collection=testaccomp |
33 | 8 | author = Tester <tester@tester> | ||
34 | 8 | 9 | ||
35 | === modified file 'accomplishments/daemon/tests/accomps/third.accomplishment' | |||
36 | --- accomplishments/daemon/tests/accomps/third.accomplishment 2012-07-12 21:10:53 +0000 | |||
37 | +++ accomplishments/daemon/tests/accomps/third.accomplishment 2012-07-14 02:21:18 +0000 | |||
38 | @@ -7,3 +7,4 @@ | |||
39 | 7 | category=testing, unit test | 7 | category=testing, unit test |
40 | 8 | # comment should be ignored | 8 | # comment should be ignored |
41 | 9 | # comment | 9 | # comment |
42 | 10 | author = Someone | ||
43 | 10 | 11 | ||
44 | === added directory 'accomplishments/daemon/tests/extrainformation' | |||
45 | === added file 'accomplishments/daemon/tests/extrainformation/info' | |||
46 | --- accomplishments/daemon/tests/extrainformation/info 1970-01-01 00:00:00 +0000 | |||
47 | +++ accomplishments/daemon/tests/extrainformation/info 2012-07-14 02:21:18 +0000 | |||
48 | @@ -0,0 +1,9 @@ | |||
49 | 1 | [label] | ||
50 | 2 | en = Some info | ||
51 | 3 | |||
52 | 4 | [description] | ||
53 | 5 | en = Some description | ||
54 | 6 | # a comment | ||
55 | 7 | |||
56 | 8 | [example] | ||
57 | 9 | en = Some example | ||
58 | 0 | 10 | ||
59 | === added file 'accomplishments/daemon/tests/extrainformation/info2' | |||
60 | --- accomplishments/daemon/tests/extrainformation/info2 1970-01-01 00:00:00 +0000 | |||
61 | +++ accomplishments/daemon/tests/extrainformation/info2 2012-07-14 02:21:18 +0000 | |||
62 | @@ -0,0 +1,23 @@ | |||
63 | 1 | # a comment | ||
64 | 2 | |||
65 | 3 | |||
66 | 4 | |||
67 | 5 | |||
68 | 6 | |||
69 | 7 | |||
70 | 8 | |||
71 | 9 | |||
72 | 10 | |||
73 | 11 | [label] | ||
74 | 12 | en = More info | ||
75 | 13 | |||
76 | 14 | [description] | ||
77 | 15 | en = More description | ||
78 | 16 | |||
79 | 17 | #### | ||
80 | 18 | |||
81 | 19 | # | ||
82 | 20 | ## | ||
83 | 21 | |||
84 | 22 | [example] | ||
85 | 23 | en = More example | ||
86 | 0 | 24 | ||
87 | === modified file 'accomplishments/daemon/tests/tests.py' | |||
88 | --- accomplishments/daemon/tests/tests.py 2012-07-13 19:36:06 +0000 | |||
89 | +++ accomplishments/daemon/tests/tests.py 2012-07-14 02:21:18 +0000 | |||
90 | @@ -11,40 +11,41 @@ | |||
91 | 11 | sys.path.insert(0, os.path.join(os.path.split(__file__)[0], "../../..")) | 11 | sys.path.insert(0, os.path.join(os.path.split(__file__)[0], "../../..")) |
92 | 12 | from accomplishments.daemon import app, api | 12 | from accomplishments.daemon import app, api |
93 | 13 | 13 | ||
95 | 14 | # future tests | 14 | # future tests: |
96 | 15 | # create extra information files - marked for removal in the code | ||
97 | 15 | # get_acc_date_completed - needs accomplish() to work to be useful | 16 | # get_acc_date_completed - needs accomplish() to work to be useful |
98 | 16 | # get all extra information | ||
99 | 17 | # get all extra information required | ||
100 | 18 | # create extra information files | ||
101 | 19 | # invalidate extra information | ||
102 | 20 | # get extra information | ||
103 | 21 | # get trophy path | ||
104 | 22 | # get trophy data | 17 | # get trophy data |
105 | 23 | # get collection name | ||
106 | 24 | # get collection exists | ||
107 | 25 | # get collection authors | ||
108 | 26 | # get collection categories | ||
109 | 27 | # get collection data | ||
110 | 28 | # list trophies | 18 | # list trophies |
111 | 29 | # list opportunities | 19 | # list opportunities |
112 | 30 | # list depending on | 20 | # list depending on |
113 | 31 | # list unlocked | 21 | # list unlocked |
114 | 32 | # list unlocked not completed | 22 | # list unlocked not completed |
115 | 33 | # list collections | ||
116 | 34 | # run scripts/runscript | 23 | # run scripts/runscript |
117 | 35 | # build viewer database | ||
118 | 36 | # get published status | 24 | # get published status |
119 | 25 | # invalidate extra information | ||
120 | 37 | 26 | ||
121 | 38 | # These tests will modify the user's envrionment, outside of the test | 27 | # These tests will modify the user's envrionment, outside of the test |
122 | 39 | # dir and so are not written/skipped: | 28 | # dir and so are not written/skipped: |
123 | 40 | # - set daemon session start | 29 | # - set daemon session start |
124 | 41 | # - set block u1 notification bubbles | 30 | # - set block u1 notification bubbles |
125 | 42 | 31 | ||
126 | 32 | # Debugging: | ||
127 | 33 | # To debug tests, the following changes are recommended: | ||
128 | 34 | # 1) comment out the shutil.rmtree in tearDown() | ||
129 | 35 | # 2) in setUp, set self.td to a known place, like /tmp/foo (you will need | ||
130 | 36 | # to create this directory as well) | ||
131 | 37 | |||
132 | 43 | class TestDaemon(unittest.TestCase): | 38 | class TestDaemon(unittest.TestCase): |
133 | 44 | 39 | ||
134 | 45 | ACCOMP_SET = "testaccomp" | 40 | ACCOMP_SET = "testaccomp" |
135 | 46 | LANG = "en" | 41 | LANG = "en" |
136 | 47 | 42 | ||
137 | 43 | def util_copy_extrainfo(self, extrainfo_dir, extrainfo_name): | ||
138 | 44 | testdir = os.path.dirname(__file__) | ||
139 | 45 | src = os.path.join(testdir, "extrainformation", extrainfo_name) | ||
140 | 46 | dest = os.path.join(extrainfo_dir, extrainfo_name) | ||
141 | 47 | shutil.copyfile(src, dest) | ||
142 | 48 | |||
143 | 48 | def util_copy_accomp(self, accomp_dir, accomp_name): | 49 | def util_copy_accomp(self, accomp_dir, accomp_name): |
144 | 49 | testdir = os.path.dirname(__file__) | 50 | testdir = os.path.dirname(__file__) |
145 | 50 | src = os.path.join(testdir, "accomps", | 51 | src = os.path.join(testdir, "accomps", |
146 | @@ -52,6 +53,10 @@ | |||
147 | 52 | dest = os.path.join(accomp_dir, "%s.accomplishment" % accomp_name) | 53 | dest = os.path.join(accomp_dir, "%s.accomplishment" % accomp_name) |
148 | 53 | shutil.copyfile(src, dest) | 54 | shutil.copyfile(src, dest) |
149 | 54 | 55 | ||
150 | 56 | # This function is not really needed because when tearDown runs it | ||
151 | 57 | # removes the entire tree, but when debugging tests it's useful to comment | ||
152 | 58 | # out the rmtree in tearDown, so then this is critical to make the tests | ||
153 | 59 | # work. | ||
154 | 55 | def util_remove_all_accomps(self, accomp_dir): | 60 | def util_remove_all_accomps(self, accomp_dir): |
155 | 56 | for f in os.listdir(accomp_dir): | 61 | for f in os.listdir(accomp_dir): |
156 | 57 | os.remove(os.path.join(self.accomp_dir, f)) | 62 | os.remove(os.path.join(self.accomp_dir, f)) |
157 | @@ -119,9 +124,9 @@ | |||
158 | 119 | if not os.path.exists(self.script_root): | 124 | if not os.path.exists(self.script_root): |
159 | 120 | os.makedirs(self.script_root) | 125 | os.makedirs(self.script_root) |
160 | 121 | 126 | ||
164 | 122 | # XXX - not sure this is correct or needed | 127 | # /tmp/foo/accomplishments/.local/share/accomplishments/trophies |
165 | 123 | # /tmp/foo/accomplishments/accomplishments/testaccomp/trophies | 128 | self.trophy_dir = os.path.join(self.td, "accomplishments", ".local", |
166 | 124 | self.trophy_dir = os.path.join(self.td, "trophies") | 129 | "share", "accomplishments", "trophies") |
167 | 125 | if not os.path.exists(self.trophy_dir): | 130 | if not os.path.exists(self.trophy_dir): |
168 | 126 | os.makedirs(self.trophy_dir) | 131 | os.makedirs(self.trophy_dir) |
169 | 127 | 132 | ||
170 | @@ -171,14 +176,7 @@ | |||
171 | 171 | "My Second Accomplishment") | 176 | "My Second Accomplishment") |
172 | 172 | self.assertEquals(a.get_acc_title("%s/third" % self.ACCOMP_SET), | 177 | self.assertEquals(a.get_acc_title("%s/third" % self.ACCOMP_SET), |
173 | 173 | "My Third Accomplishment") | 178 | "My Third Accomplishment") |
182 | 174 | 179 | self.assertRaises(KeyError, a.get_acc_title, "wrong") | |
175 | 175 | # XXX - assertRaises isn't working here the way I think it | ||
176 | 176 | # should, this is a substitute | ||
177 | 177 | try: | ||
178 | 178 | a.get_acc_title("wrong") | ||
179 | 179 | self.assertTrue(False) | ||
180 | 180 | except KeyError: | ||
181 | 181 | self.assertTrue(True) | ||
183 | 182 | 180 | ||
184 | 183 | # get_acc_description | 181 | # get_acc_description |
185 | 184 | self.assertTrue("example" in a.get_acc_description("%s/first" % | 182 | self.assertTrue("example" in a.get_acc_description("%s/first" % |
186 | @@ -187,27 +185,13 @@ | |||
187 | 187 | self.ACCOMP_SET)) | 185 | self.ACCOMP_SET)) |
188 | 188 | self.assertTrue("example" in a.get_acc_description("%s/third" % | 186 | self.assertTrue("example" in a.get_acc_description("%s/third" % |
189 | 189 | self.ACCOMP_SET)) | 187 | self.ACCOMP_SET)) |
198 | 190 | 188 | self.assertRaises(KeyError, a.get_acc_description, "wrong") | |
191 | 191 | # XXX - assertRaises isn't working here the way I think it | ||
192 | 192 | # should, this is a substitute | ||
193 | 193 | try: | ||
194 | 194 | a.get_acc_description("wrong") | ||
195 | 195 | self.assertTrue(False) | ||
196 | 196 | except KeyError: | ||
197 | 197 | self.assertTrue(True) | ||
199 | 198 | 189 | ||
200 | 199 | # get_acc_needs_signing | 190 | # get_acc_needs_signing |
201 | 200 | self.assertFalse(a.get_acc_needs_signing("%s/first" % self.ACCOMP_SET)) | 191 | self.assertFalse(a.get_acc_needs_signing("%s/first" % self.ACCOMP_SET)) |
202 | 201 | self.assertTrue(a.get_acc_needs_signing("%s/second" % self.ACCOMP_SET)) | 192 | self.assertTrue(a.get_acc_needs_signing("%s/second" % self.ACCOMP_SET)) |
203 | 202 | self.assertFalse(a.get_acc_needs_signing("%s/first" % self.ACCOMP_SET)) | 193 | self.assertFalse(a.get_acc_needs_signing("%s/first" % self.ACCOMP_SET)) |
212 | 203 | 194 | self.assertRaises(KeyError, a.get_acc_needs_signing, "wrong") | |
205 | 204 | # XXX - assertRaises isn't working here the way I think it | ||
206 | 205 | # should, this is a substitute | ||
207 | 206 | try: | ||
208 | 207 | a.get_acc_needs_signing("wrong") | ||
209 | 208 | self.assertTrue(False) | ||
210 | 209 | except KeyError: | ||
211 | 210 | self.assertTrue(True) | ||
213 | 211 | 195 | ||
214 | 212 | # get_acc_depends | 196 | # get_acc_depends |
215 | 213 | self.assertTrue(a.get_acc_depends("%s/first" % self.ACCOMP_SET) == []) | 197 | self.assertTrue(a.get_acc_depends("%s/first" % self.ACCOMP_SET) == []) |
216 | @@ -215,27 +199,13 @@ | |||
217 | 215 | self.assertEquals(len(deps), 1) | 199 | self.assertEquals(len(deps), 1) |
218 | 216 | self.assertTrue(deps[0] == "%s/first" % self.ACCOMP_SET) | 200 | self.assertTrue(deps[0] == "%s/first" % self.ACCOMP_SET) |
219 | 217 | self.assertTrue(a.get_acc_depends("%s/third" % self.ACCOMP_SET) == []) | 201 | self.assertTrue(a.get_acc_depends("%s/third" % self.ACCOMP_SET) == []) |
228 | 218 | 202 | self.assertRaises(KeyError, a.get_acc_depends, "wrong") | |
221 | 219 | # XXX - assertRaises isn't working here the way I think it | ||
222 | 220 | # should, this is a substitute | ||
223 | 221 | try: | ||
224 | 222 | a.get_acc_depends("wrong") | ||
225 | 223 | self.assertTrue(False) | ||
226 | 224 | except KeyError: | ||
227 | 225 | self.assertTrue(True) | ||
229 | 226 | 203 | ||
230 | 227 | # get_acc_is_unlocked | 204 | # get_acc_is_unlocked |
231 | 228 | self.assertTrue(a.get_acc_is_unlocked("%s/first" % self.ACCOMP_SET)) | 205 | self.assertTrue(a.get_acc_is_unlocked("%s/first" % self.ACCOMP_SET)) |
232 | 229 | self.assertFalse(a.get_acc_is_unlocked("%s/second" % self.ACCOMP_SET)) | 206 | self.assertFalse(a.get_acc_is_unlocked("%s/second" % self.ACCOMP_SET)) |
233 | 230 | self.assertTrue(a.get_acc_is_unlocked("%s/third" % self.ACCOMP_SET)) | 207 | self.assertTrue(a.get_acc_is_unlocked("%s/third" % self.ACCOMP_SET)) |
242 | 231 | 208 | self.assertRaises(KeyError, a.get_acc_is_unlocked, "wrong") | |
235 | 232 | # XXX - assertRaises isn't working here the way I think it | ||
236 | 233 | # should, this is a substitute | ||
237 | 234 | try: | ||
238 | 235 | a.get_acc_is_unlocked("wrong") | ||
239 | 236 | self.assertTrue(False) | ||
240 | 237 | except KeyError: | ||
241 | 238 | self.assertTrue(True) | ||
243 | 239 | 209 | ||
244 | 240 | # get_acc_is_completed | 210 | # get_acc_is_completed |
245 | 241 | # XXX - when we get the accomplish() code working, make some of these | 211 | # XXX - when we get the accomplish() code working, make some of these |
246 | @@ -243,14 +213,7 @@ | |||
247 | 243 | self.assertFalse(a.get_acc_is_completed("%s/first" % self.ACCOMP_SET)) | 213 | self.assertFalse(a.get_acc_is_completed("%s/first" % self.ACCOMP_SET)) |
248 | 244 | self.assertFalse(a.get_acc_is_completed("%s/second" % self.ACCOMP_SET)) | 214 | self.assertFalse(a.get_acc_is_completed("%s/second" % self.ACCOMP_SET)) |
249 | 245 | self.assertFalse(a.get_acc_is_completed("%s/third" % self.ACCOMP_SET)) | 215 | self.assertFalse(a.get_acc_is_completed("%s/third" % self.ACCOMP_SET)) |
258 | 246 | 216 | self.assertRaises(KeyError, a.get_acc_is_completed, "wrong") | |
251 | 247 | # XXX - assertRaises isn't working here the way I think it | ||
252 | 248 | # should, this is a substitute | ||
253 | 249 | try: | ||
254 | 250 | a.get_acc_is_completed("wrong") | ||
255 | 251 | self.assertTrue(False) | ||
256 | 252 | except KeyError: | ||
257 | 253 | self.assertTrue(True) | ||
259 | 254 | 217 | ||
260 | 255 | # get_acc_script_path | 218 | # get_acc_script_path |
261 | 256 | self.assertEqual(a.get_acc_script_path("%s/first" % self.ACCOMP_SET), | 219 | self.assertEqual(a.get_acc_script_path("%s/first" % self.ACCOMP_SET), |
262 | @@ -260,30 +223,18 @@ | |||
263 | 260 | self.util_write_file(self.script_root, "third.py", "print 'hello'") | 223 | self.util_write_file(self.script_root, "third.py", "print 'hello'") |
264 | 261 | sp = a.get_acc_script_path("%s/third" % self.ACCOMP_SET) | 224 | sp = a.get_acc_script_path("%s/third" % self.ACCOMP_SET) |
265 | 262 | self.assertTrue(sp.endswith("third.py")) | 225 | self.assertTrue(sp.endswith("third.py")) |
272 | 263 | 226 | self.assertRaises(KeyError, a.get_acc_script_path, "wrong") | |
267 | 264 | try: | ||
268 | 265 | a.get_acc_script_path("wrong") | ||
269 | 266 | self.assertTrue(False) | ||
270 | 267 | except KeyError: | ||
271 | 268 | self.assertTrue(True) | ||
273 | 269 | 227 | ||
274 | 270 | # get_acc_needs_info | 228 | # get_acc_needs_info |
275 | 271 | info = a.get_acc_needs_info("%s/first" % self.ACCOMP_SET) | 229 | info = a.get_acc_needs_info("%s/first" % self.ACCOMP_SET) |
276 | 272 | self.assertEqual(len(info),2) | 230 | self.assertEqual(len(info),2) |
279 | 273 | self.assertEqual(info[0], "info") | 231 | for i in info: |
280 | 274 | self.assertEqual(info[1], "more info") | 232 | self.assertTrue(i in ["info", "info2"]) |
281 | 275 | self.assertEqual(a.get_acc_needs_info("%s/second" % self.ACCOMP_SET), | 233 | self.assertEqual(a.get_acc_needs_info("%s/second" % self.ACCOMP_SET), |
282 | 276 | []) | 234 | []) |
283 | 277 | self.assertEqual(a.get_acc_needs_info("%s/third" % self.ACCOMP_SET), | 235 | self.assertEqual(a.get_acc_needs_info("%s/third" % self.ACCOMP_SET), |
284 | 278 | []) | 236 | []) |
293 | 279 | 237 | self.assertRaises(KeyError, a.get_acc_needs_info, "wrong") | |
286 | 280 | # XXX - assertRaises isn't working here the way I think it | ||
287 | 281 | # should, this is a substitute | ||
288 | 282 | try: | ||
289 | 283 | a.get_acc_needs_info("wrong") | ||
290 | 284 | self.assertTrue(False) | ||
291 | 285 | except KeyError: | ||
292 | 286 | self.assertTrue(True) | ||
294 | 287 | 238 | ||
295 | 288 | # get_acc_collection | 239 | # get_acc_collection |
296 | 289 | self.assertEqual(a.get_acc_collection("%s/first" % self.ACCOMP_SET), | 240 | self.assertEqual(a.get_acc_collection("%s/first" % self.ACCOMP_SET), |
297 | @@ -292,32 +243,17 @@ | |||
298 | 292 | self.ACCOMP_SET) | 243 | self.ACCOMP_SET) |
299 | 293 | self.assertEqual(a.get_acc_collection("%s/third" % self.ACCOMP_SET), | 244 | self.assertEqual(a.get_acc_collection("%s/third" % self.ACCOMP_SET), |
300 | 294 | self.ACCOMP_SET) | 245 | self.ACCOMP_SET) |
309 | 295 | 246 | self.assertRaises(KeyError, a.get_acc_collection, "wrong") | |
302 | 296 | # XXX - assertRaises isn't working here the way I think it | ||
303 | 297 | # should, this is a substitute | ||
304 | 298 | try: | ||
305 | 299 | a.get_acc_collection("wrong") | ||
306 | 300 | self.assertTrue(False) | ||
307 | 301 | except KeyError: | ||
308 | 302 | self.assertTrue(True) | ||
310 | 303 | 247 | ||
311 | 304 | # get_acc_categories | 248 | # get_acc_categories |
312 | 305 | self.assertEqual(a.get_acc_categories("%s/first" % self.ACCOMP_SET), []) | 249 | self.assertEqual(a.get_acc_categories("%s/first" % self.ACCOMP_SET), []) |
313 | 306 | self.assertEqual(a.get_acc_categories("%s/second" % self.ACCOMP_SET), | 250 | self.assertEqual(a.get_acc_categories("%s/second" % self.ACCOMP_SET), |
314 | 307 | []) | 251 | []) |
316 | 308 | info = a.get_acc_categories("%s/third" % self.ACCOMP_SET) | 252 | categories = a.get_acc_categories("%s/third" % self.ACCOMP_SET) |
317 | 309 | self.assertEqual(len(info),2) | 253 | self.assertEqual(len(info),2) |
329 | 310 | self.assertEqual(info[0], "testing") | 254 | for category in categories: |
330 | 311 | self.assertEqual(info[1], "unit test") | 255 | self.assertTrue(category in ["testing", "unit test"]) |
331 | 312 | 256 | self.assertRaises(KeyError, a.get_acc_categories, "wrong") | |
321 | 313 | # XXX - assertRaises isn't working here the way I think it | ||
322 | 314 | # should, this is a substitute | ||
323 | 315 | try: | ||
324 | 316 | a.get_acc_categories("wrong") | ||
325 | 317 | self.assertTrue(False) | ||
326 | 318 | except KeyError: | ||
327 | 319 | self.assertTrue(True) | ||
328 | 320 | |||
332 | 321 | 257 | ||
333 | 322 | def test_get_block_ubuntuone_notification_bubbles(self): | 258 | def test_get_block_ubuntuone_notification_bubbles(self): |
334 | 323 | a = api.Accomplishments(None) | 259 | a = api.Accomplishments(None) |
335 | @@ -489,5 +425,156 @@ | |||
336 | 489 | self.util_write_config_file(self.config_dir) | 425 | self.util_write_config_file(self.config_dir) |
337 | 490 | return | 426 | return |
338 | 491 | 427 | ||
339 | 428 | # this tests the get_collection_* functions and list_collections(): | ||
340 | 429 | def test_get_collection_all_funcs(self): | ||
341 | 430 | self.util_remove_all_accomps(self.accomp_dir) | ||
342 | 431 | self.util_copy_accomp(self.accomp_dir, "first") | ||
343 | 432 | self.util_copy_accomp(self.accomp_dir, "second") | ||
344 | 433 | self.util_copy_accomp(self.accomp_dir, "third") | ||
345 | 434 | a = api.Accomplishments(None) | ||
346 | 435 | |||
347 | 436 | # list_collections | ||
348 | 437 | collections = a.list_collections() | ||
349 | 438 | self.assertEqual(len(collections), 1) | ||
350 | 439 | self.assertEqual(collections[0], self.ACCOMP_SET) | ||
351 | 440 | |||
352 | 441 | # get_collection_name | ||
353 | 442 | self.assertEqual(a.get_collection_name(collections[0]), | ||
354 | 443 | "Test Collection") | ||
355 | 444 | self.assertRaises(KeyError, a.get_collection_name, "wrong") | ||
356 | 445 | |||
357 | 446 | # get_collection_exists | ||
358 | 447 | self.assertTrue(a.get_collection_exists(collections[0])) | ||
359 | 448 | self.assertFalse(a.get_collection_exists("wrong")) | ||
360 | 449 | self.assertFalse(a.get_collection_exists("")) | ||
361 | 450 | self.assertFalse(a.get_collection_exists(None)) | ||
362 | 451 | |||
363 | 452 | # get_collection_authors | ||
364 | 453 | authors = a.get_collection_authors(collections[0]) | ||
365 | 454 | # we have only 2 authors because dupes are removed | ||
366 | 455 | self.assertEqual(len(authors), 2) | ||
367 | 456 | for author in authors: | ||
368 | 457 | self.assertTrue(author in ["Someone", "Tester <tester@tester>"]) | ||
369 | 458 | self.assertRaises(KeyError, a.get_collection_authors, "wrong") | ||
370 | 459 | |||
371 | 460 | # get_collection_categories | ||
372 | 461 | categories = a.get_collection_categories(collections[0]) | ||
373 | 462 | self.assertEqual(len(categories), 2) | ||
374 | 463 | for category in categories: | ||
375 | 464 | self.assertTrue(category in ["testing", "unit test"]) | ||
376 | 465 | self.assertRaises(KeyError, a.get_collection_categories, "wrong") | ||
377 | 466 | |||
378 | 467 | # get_collection_data | ||
379 | 468 | data = a.get_collection_data(collections[0]) | ||
380 | 469 | self.assertTrue(isinstance(data, dict)) | ||
381 | 470 | self.assertNotEquals(data['authors'], None) | ||
382 | 471 | self.assertNotEquals(data['name'], None) | ||
383 | 472 | self.assertNotEquals(data['categories'], None) | ||
384 | 473 | self.assertRaises(KeyError, a.get_collection_data, "wrong") | ||
385 | 474 | |||
386 | 475 | # get trophy path | ||
387 | 476 | def test_get_trophy_path(self): | ||
388 | 477 | self.util_remove_all_accomps(self.accomp_dir) | ||
389 | 478 | self.util_copy_accomp(self.accomp_dir, "first") | ||
390 | 479 | self.util_copy_accomp(self.accomp_dir, "second") | ||
391 | 480 | self.util_copy_accomp(self.accomp_dir, "third") | ||
392 | 481 | a = api.Accomplishments(None) | ||
393 | 482 | |||
394 | 483 | self.assertTrue(a.get_trophy_path("%s/first" % | ||
395 | 484 | self.ACCOMP_SET).endswith("first.trophy")) | ||
396 | 485 | self.assertTrue(a.get_trophy_path("%s/second" % | ||
397 | 486 | self.ACCOMP_SET).endswith("second.trophy")) | ||
398 | 487 | self.assertTrue(a.get_trophy_path("%s/third" % | ||
399 | 488 | self.ACCOMP_SET).endswith("third.trophy")) | ||
400 | 489 | |||
401 | 490 | def test_write_extra_information_file(self): | ||
402 | 491 | a = api.Accomplishments(None) | ||
403 | 492 | |||
404 | 493 | # write extra information will make the directory for us if needed, | ||
405 | 494 | # so lets remove it (if present and force it to) | ||
406 | 495 | extrainfo_path = os.path.join(a.trophies_path, ".extrainformation") | ||
407 | 496 | if os.path.exists(extrainfo_path): | ||
408 | 497 | shutil.rmtree(extrainfo_path) | ||
409 | 498 | |||
410 | 499 | a.write_extra_information_file("whatever", "abcdefg") | ||
411 | 500 | path = os.path.join(extrainfo_path, "whatever") | ||
412 | 501 | self.assertTrue(os.path.exists(path)) | ||
413 | 502 | |||
414 | 503 | # write extra info will remove a file if you don't pass in data | ||
415 | 504 | a.write_extra_information_file("whatever", None) | ||
416 | 505 | self.assertFalse(os.path.exists(path)) | ||
417 | 506 | |||
418 | 507 | # tests: | ||
419 | 508 | # get_extra_information() | ||
420 | 509 | # get_all_extra_information() | ||
421 | 510 | # get_all_extra_information_required() | ||
422 | 511 | def test_get_extra_information_all_funcs(self): | ||
423 | 512 | a = api.Accomplishments(None) | ||
424 | 513 | self.util_copy_extrainfo(self.extrainfo_dir, "info") | ||
425 | 514 | self.util_copy_extrainfo(self.extrainfo_dir, "info2") | ||
426 | 515 | self.util_copy_accomp(self.accomp_dir, "first") | ||
427 | 516 | |||
428 | 517 | # get extra information | ||
429 | 518 | # these won't show up until we reload | ||
430 | 519 | self.assertRaises(KeyError, a.get_extra_information, self.ACCOMP_SET, | ||
431 | 520 | "info") | ||
432 | 521 | |||
433 | 522 | # should return None when the collection doesn't exist | ||
434 | 523 | self.assertEqual(a.get_extra_information("wrong", "info"), None) | ||
435 | 524 | |||
436 | 525 | # reloading should make them show up | ||
437 | 526 | a.reload_accom_database() | ||
438 | 527 | |||
439 | 528 | # will throw a KeyError if collection is right, but extrainfo is | ||
440 | 529 | # wrong | ||
441 | 530 | self.assertRaises(KeyError, a.get_extra_information, self.ACCOMP_SET, | ||
442 | 531 | "wrong") | ||
443 | 532 | |||
444 | 533 | ei = a.get_extra_information(self.ACCOMP_SET, "info") | ||
445 | 534 | self.assertTrue(isinstance(ei, list)) | ||
446 | 535 | self.assertTrue(len(ei) == 1) | ||
447 | 536 | self.assertEqual(ei[0]['info'], '') | ||
448 | 537 | self.assertEqual(ei[0]['label'], 'Some info') | ||
449 | 538 | ei = a.get_extra_information(self.ACCOMP_SET, "info2") | ||
450 | 539 | self.assertTrue(isinstance(ei, list)) | ||
451 | 540 | self.assertTrue(len(ei) == 1) | ||
452 | 541 | self.assertEqual(ei[0]['info2'], '') | ||
453 | 542 | self.assertEqual(ei[0]['label'], 'More info') | ||
454 | 543 | |||
455 | 544 | # write some data out and reload the DB | ||
456 | 545 | a.write_extra_information_file("info", "whatever") | ||
457 | 546 | ei = a.get_extra_information(self.ACCOMP_SET, "info") | ||
458 | 547 | self.assertEqual(ei[0]['info'], 'whatever') | ||
459 | 548 | a.write_extra_information_file("info2", "whatever2") | ||
460 | 549 | ei = a.get_extra_information(self.ACCOMP_SET, "info2") | ||
461 | 550 | self.assertEqual(ei[0]['info2'], 'whatever2') | ||
462 | 551 | |||
463 | 552 | # get all extra information | ||
464 | 553 | all_extra_info = a.get_all_extra_information() | ||
465 | 554 | self.assertTrue(isinstance(all_extra_info, list)) | ||
466 | 555 | self.assertTrue(len(all_extra_info) == 2) | ||
467 | 556 | for ei in all_extra_info: | ||
468 | 557 | self.assertTrue(isinstance(ei, dict)) | ||
469 | 558 | self.assertEquals(ei['collection'], self.ACCOMP_SET) | ||
470 | 559 | self.assertTrue(ei['description'] is not None) | ||
471 | 560 | self.assertTrue(ei['example'] is not None) | ||
472 | 561 | self.assertTrue(ei['needs-information'] is not None) | ||
473 | 562 | self.assertTrue(ei['regex'] is '') | ||
474 | 563 | |||
475 | 564 | # get all extra information required | ||
476 | 565 | # clear out the extra info files, so everything is required | ||
477 | 566 | a.write_extra_information_file("info", None) | ||
478 | 567 | a.write_extra_information_file("info2", None) | ||
479 | 568 | all_extra_info_required = a.get_all_extra_information_required() | ||
480 | 569 | self.assertTrue(isinstance(all_extra_info, list)) | ||
481 | 570 | self.assertTrue(len(all_extra_info) == 2) | ||
482 | 571 | |||
483 | 572 | # now mark fill them in with info | ||
484 | 573 | a.write_extra_information_file("info", "whatever") | ||
485 | 574 | a.write_extra_information_file("info2", "whatever2") | ||
486 | 575 | all_extra_info_required = a.get_all_extra_information_required() | ||
487 | 576 | self.assertTrue(isinstance(all_extra_info_required, list)) | ||
488 | 577 | self.assertTrue(len(all_extra_info_required) == 0) | ||
489 | 578 | |||
490 | 492 | if __name__ == "__main__": | 579 | if __name__ == "__main__": |
491 | 493 | unittest.main() | 580 | unittest.main() |
492 | 494 | 581 | ||
493 | === modified file 'debian/control' | |||
494 | --- debian/control 2012-05-29 18:37:07 +0000 | |||
495 | +++ debian/control 2012-07-14 02:21:18 +0000 | |||
496 | @@ -4,6 +4,7 @@ | |||
497 | 4 | Build-Depends: cdbs (>= 0.4.43), | 4 | Build-Depends: cdbs (>= 0.4.43), |
498 | 5 | debhelper (>= 6), | 5 | debhelper (>= 6), |
499 | 6 | python (>= 2.6.6-3~), | 6 | python (>= 2.6.6-3~), |
500 | 7 | python-nose, | ||
501 | 7 | python-distutils-extra (>= 2.10) | 8 | python-distutils-extra (>= 2.10) |
502 | 8 | Maintainer: Jono Bacon <jono@ubuntu.com> | 9 | Maintainer: Jono Bacon <jono@ubuntu.com> |
503 | 9 | Standards-Version: 3.9.3 | 10 | Standards-Version: 3.9.3 |
504 | 10 | 11 | ||
505 | === modified file 'debian/rules' | |||
506 | --- debian/rules 2012-04-12 00:23:38 +0000 | |||
507 | +++ debian/rules 2012-07-14 02:21:18 +0000 | |||
508 | @@ -6,4 +6,9 @@ | |||
509 | 6 | dh $@ --with python2 | 6 | dh $@ --with python2 |
510 | 7 | endif | 7 | endif |
511 | 8 | 8 | ||
513 | 9 | 9 | override_dh_auto_test: | |
514 | 10 | ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),) | ||
515 | 11 | set -ex; for python in $(shell pyversions -r) ; do \ | ||
516 | 12 | $$python /usr/bin/nosetests -v ; \ | ||
517 | 13 | done | ||
518 | 14 | endif |