Merge lp:~ricardokirkner/ols-store-tests/cpi-tests-new-style-errors into lp:~ubuntuone-pqm-team/ols-store-tests/store-acceptance-tests

Proposed by Ricardo Kirkner
Status: Merged
Merged at revision: 30
Proposed branch: lp:~ricardokirkner/ols-store-tests/cpi-tests-new-style-errors
Merge into: lp:~ubuntuone-pqm-team/ols-store-tests/store-acceptance-tests
Prerequisite: lp:~ricardokirkner/ols-store-tests/include-store-revnos
Diff against target: 99 lines (+33/-12)
3 files modified
tests/api/cpi/helpers.py (+20/-7)
tests/api/cpi/test_metadata.py (+6/-2)
tests/api/cpi/test_snaps.py (+7/-3)
To merge this branch: bzr merge lp:~ricardokirkner/ols-store-tests/cpi-tests-new-style-errors
Reviewer Review Type Date Requested Status
Ubuntu One PQM Team Pending
Review via email: mp+305742@code.launchpad.net

Commit message

fixed cpi tests after service started returning new-style error responses

To post a comment you must log in.
32. By Ricardo Kirkner

support both old and new-style error responses

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/api/cpi/helpers.py'
2--- tests/api/cpi/helpers.py 2016-07-07 19:12:03 +0000
3+++ tests/api/cpi/helpers.py 2016-09-14 20:05:56 +0000
4@@ -69,25 +69,38 @@
5 self.assertEqual(response.headers['Content-Type'],
6 content_type)
7
8- def assert_not_found(self, response, message=None):
9+ def assert_not_found(self, response, message=None, new_style_error=False):
10 self.assertEqual(response.status_code, 404)
11 self.assertEqual(response.headers['Content-Type'],
12 'application/hal+json')
13- self.assertEqual(response.json(), {
14+ expected = {
15 'result': 'error',
16 'errors': [message or 'Not found'],
17- })
18+ }
19+ if new_style_error:
20+ expected['error_list'] = [
21+ {'code': 'resource-not-found', 'message': message},
22+ ]
23+ self.assertEqual(response.json(), expected)
24
25- def assert_bad_request(self, response, message):
26+ def assert_bad_request(self, response, message, code='',
27+ new_style_error=False):
28 self.assertEqual(response.status_code, 400)
29 self.assertEqual(response.headers['Content-Type'],
30 'application/hal+json')
31- self.assertEqual(response.json(), {
32+ expected = {
33 'result': 'error',
34 'errors': [message],
35- })
36+ }
37+ if new_style_error:
38+ expected['error_list'] = [
39+ {'code': code, 'message': message},
40+ ]
41+
42+ self.assertEqual(response.json(), expected)
43
44 def assert_unauthorized(self, response):
45 self.assertEqual(response.status_code, 401)
46- self.assertEqual(response.headers['Content-Type'], 'text/plain')
47+ self.assertEqual(response.headers['Content-Type'],
48+ 'application/hal+json')
49 self.assertIn('WWW-Authenticate', response.headers)
50
51=== modified file 'tests/api/cpi/test_metadata.py'
52--- tests/api/cpi/test_metadata.py 2016-07-07 19:49:49 +0000
53+++ tests/api/cpi/test_metadata.py 2016-09-14 20:05:56 +0000
54@@ -154,12 +154,16 @@
55 response = self.get_metadata()
56 self.assert_bad_request(
57 response,
58- message='Packages must be specified in parameter "snaps".')
59+ code='missing-field',
60+ message='Packages must be specified in parameter "snaps".',
61+ new_style_error=True)
62
63 def test_get_metadata_missing_snap_id(self):
64 response = self.get_metadata(snaps=[{}])
65 self.assert_bad_request(
66- response, message='Missing snap_id for snap.')
67+ response, code='missing-field',
68+ message='Missing snap_id for snap.',
69+ new_style_error=True)
70
71 def test_get_metadata_filter_fields(self):
72 fields = ['channel', 'revision', 'snap_id']
73
74=== modified file 'tests/api/cpi/test_snaps.py'
75--- tests/api/cpi/test_snaps.py 2016-07-07 19:49:49 +0000
76+++ tests/api/cpi/test_snaps.py 2016-09-14 20:05:56 +0000
77@@ -101,15 +101,19 @@
78 def test_get_snap_detail_without_series(self):
79 response = get_snap_detail(SNAP_PACKAGE_NAME, series=None)
80 self.assert_bad_request(
81- response, message='X-Ubuntu-Series header is required.')
82+ response, code='missing-header',
83+ message='X-Ubuntu-Series header is required.',
84+ new_style_error=True)
85
86 def test_get_snap_detail_unauthorized(self):
87 response = get_snap_detail(PRIVATE_SNAP_PACKAGE_NAME, auth=False)
88- self.assert_not_found(response, message='No such package')
89+ self.assert_not_found(response, message='No such package',
90+ new_style_error=True)
91
92 def test_get_snap_detail_not_found(self):
93 response = get_snap_detail('missing')
94- self.assert_not_found(response, message='No such package')
95+ self.assert_not_found(response, message='No such package',
96+ new_style_error=True)
97
98
99 class SnapMetadataTestCase(MetadataTestCase):

Subscribers

People subscribed via source and target branches

to all changes: