Merge lp:~james-w/pkgme-service/review-click into lp:pkgme-service

Proposed by James Westby
Status: Merged
Approved by: James Westby
Approved revision: 147
Merged at revision: 147
Proposed branch: lp:~james-w/pkgme-service/review-click
Merge into: lp:pkgme-service
Diff against target: 186 lines (+70/-23)
2 files modified
src/djpkgme/tasks.py (+29/-13)
src/djpkgme/tests/test_tasks.py (+41/-10)
To merge this branch: bzr merge lp:~james-w/pkgme-service/review-click
Reviewer Review Type Date Requested Status
Ricardo Kirkner (community) Approve
Review via email: mp+193482@code.launchpad.net

Commit message

Add an explanation when either of the click review checks fails.

Description of the change

Hi,

The commit message should explain this change.

Thanks,

James

To post a comment you must log in.
Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/djpkgme/tasks.py'
2--- src/djpkgme/tasks.py 2013-10-16 21:21:20 +0000
3+++ src/djpkgme/tasks.py 2013-10-31 19:53:16 +0000
4@@ -38,6 +38,13 @@
5 )
6
7
8+def indent(text, distance):
9+ """Indent a block of text by `distance` spaces."""
10+ output = distance * ' '
11+ output += text.replace('\n', '\n' + distance * ' ')
12+ return output
13+
14+
15 class MissingFieldsError(Exception):
16 """Raised when we're asked to do a job with missing data."""
17
18@@ -382,16 +389,20 @@
19
20 def unpack_package(self, package_file, temp_dir):
21 dest = os.path.join(temp_dir, 'unpacked')
22- passed = True
23+ result = {
24+ 'description': 'Is a valid click package',
25+ 'passed': True,
26+ }
27 try:
28- subprocess.check_call(['dpkg-deb', '-R', package_file, dest])
29- except subprocess.CalledProcessError:
30- passed = False
31+ subprocess.check_output(['dpkg-deb', '-R', package_file, dest],
32+ stderr=subprocess.STDOUT)
33+ except subprocess.CalledProcessError, e:
34+ result['passed'] = False
35+ explanation = 'Extracting the package with dpkg failed:\n\n'
36+ explanation += indent(e.output, 4)
37+ result['explanation'] = explanation
38 dest = None
39- return dest, {
40- 'description': 'Is a valid click package',
41- 'passed': passed,
42- }
43+ return dest, result
44
45 def run(self, metadata, overrides, logger):
46 working_dirs = []
47@@ -406,13 +417,18 @@
48 return results
49
50 def check_package_name_matches(self, metadata, package):
51+ result = {
52+ 'description': 'Stated package name matches the manifest',
53+ 'passed': True,
54+ }
55 with open(os.path.join(package, 'DEBIAN/manifest')) as f:
56 manifest_content = json.loads(f.read())
57- passed = manifest_content['name'] == metadata['package_fullname']
58- return {
59- 'description': 'Stated package name matches the manifest',
60- 'passed': passed,
61- }
62+ if manifest_content['name'] != metadata['package_fullname']:
63+ result['passed'] = False
64+ result['explanation'] = '''Package name in the manifest: `{}`
65+Package name in My Apps: `{}`
66+'''.format(manifest_content['name'], metadata['package_fullname'])
67+ return result
68
69
70 class CauseOopsTask(Task):
71
72=== modified file 'src/djpkgme/tests/test_tasks.py'
73--- src/djpkgme/tests/test_tasks.py 2013-10-30 21:14:05 +0000
74+++ src/djpkgme/tests/test_tasks.py 2013-10-31 19:53:16 +0000
75@@ -34,6 +34,7 @@
76 BuildPackageTask,
77 CallbackError,
78 get_url_for_file,
79+ indent,
80 PackageAppJob,
81 prepare_icons,
82 prepare_metadata,
83@@ -50,6 +51,22 @@
84 from djpkgme.tests.helpers import FakeResponse
85
86
87+class TestIndent(TestCase):
88+
89+ def test_empty_string(self):
90+ self.assertEqual(' ', indent('', 4))
91+
92+ def test_distance(self):
93+ self.assertEqual(' ', indent('', 4))
94+ self.assertEqual(' ', indent('', 5))
95+
96+ def test_multiline(self):
97+ self.assertEqual(' a\n b', indent('a\nb', 4))
98+
99+ def test_trailing_newline(self):
100+ self.assertEqual(' a\n ', indent('a\n', 4))
101+
102+
103 class TestTranslateDict(TestCase):
104
105 def test_default(self):
106@@ -470,7 +487,7 @@
107 mock_download_file.assert_called_with(metadata['package_url'],
108 temp_dir)
109
110- @patch('djpkgme.tasks.subprocess.check_call')
111+ @patch('djpkgme.tasks.subprocess.check_output')
112 def test_unpack_package(self, mock_call):
113 job = ReviewClickJob()
114 package_file = 'some/package'
115@@ -481,21 +498,29 @@
116 self.assertEqual(
117 check, dict(passed=True, description="Is a valid click package"))
118 mock_call.assert_called_with(
119- ['dpkg-deb', '-R', package_file, unpack_path])
120+ ['dpkg-deb', '-R', package_file, unpack_path],
121+ stderr=subprocess.STDOUT)
122
123- @patch('djpkgme.tasks.subprocess.check_call')
124+ @patch('djpkgme.tasks.subprocess.check_output')
125 def test_unpack_package_fails(self, mock_call):
126 job = ReviewClickJob()
127 package_file = 'some/package'
128 temp_dir = 'temp/dir'
129 unpack_path = os.path.join(temp_dir, 'unpacked')
130- mock_call.side_effect = subprocess.CalledProcessError(1, 'command')
131+ mock_call.side_effect = subprocess.CalledProcessError(1, 'command',
132+ "Command failed\nwith some problem\n")
133 returned_path, check = job.unpack_package(package_file, temp_dir)
134 self.assertEqual(None, returned_path)
135- self.assertEqual(
136- check, dict(passed=False, description="Is a valid click package"))
137+ expected_result = dict(passed=False, description="Is a valid click package")
138+ expected_result['explanation'] = """Extracting the package with dpkg failed:
139+
140+ Command failed
141+ with some problem
142+ """
143+ self.assertEqual(check, expected_result)
144 mock_call.assert_called_with(
145- ['dpkg-deb', '-R', package_file, unpack_path])
146+ ['dpkg-deb', '-R', package_file, unpack_path],
147+ stderr=subprocess.STDOUT)
148
149 def make_manifest_file(self, manifest_content, directory):
150 debian_dir = os.path.join(directory, 'DEBIAN')
151@@ -518,11 +543,16 @@
152 def test_check_package_name_doesnt_match(self):
153 job = ReviewClickJob()
154 package_name = 'some.package'
155+ other_package_name = 'some.other.package'
156 metadata = dict(package_fullname=package_name)
157 tempdir = self.useFixture(TempDir()).path
158- self.make_manifest_file(dict(name='some.other.package'), tempdir)
159+ self.make_manifest_file(dict(name=other_package_name), tempdir)
160 result = job.check_package_name_matches(metadata, tempdir)
161 self.assertEqual(False, result['passed'])
162+ explanation = '''Package name in the manifest: `{}`
163+Package name in My Apps: `{}`
164+'''.format(other_package_name, package_name)
165+ self.assertEqual(explanation, result['explanation'])
166
167 def make_tempdir_fixture_mock(self, path):
168 """Return a mock suitable for mocking the fixtures.TempDir class.
169@@ -538,7 +568,7 @@
170 tempdir_mock.__exit__ = mock.Mock(return_value=False)
171 return tempdir_mock
172
173- @patch('djpkgme.tasks.subprocess.check_call')
174+ @patch('djpkgme.tasks.subprocess.check_output')
175 @patch('djpkgme.tasks.ReviewClickJob.download_package')
176 @patch('djpkgme.tasks.TempDir')
177 def test_integration(self, mock_tempdir, mock_download_package,
178@@ -562,6 +592,7 @@
179 mock_download_package.assert_called_with(
180 metadata, tempdir.path, logger)
181 mock_call.assert_called_with(
182- ['dpkg-deb', '-R', downloaded_path, unpacked_path])
183+ ['dpkg-deb', '-R', downloaded_path, unpacked_path],
184+ stderr=subprocess.STDOUT)
185 self.assertEqual(2, len(results))
186 self.assertEqual(True, results[0]['passed'])

Subscribers

People subscribed via source and target branches