Merge lp:~cjohnston/ubuntu-ci-services-itself/reject-bad-lists into lp:ubuntu-ci-services-itself

Proposed by Chris Johnston
Status: Merged
Approved by: Chris Johnston
Approved revision: 299
Merged at revision: 302
Proposed branch: lp:~cjohnston/ubuntu-ci-services-itself/reject-bad-lists
Merge into: lp:ubuntu-ci-services-itself
Diff against target: 152 lines (+73/-3)
4 files modified
cli/ci_libs/utils.py (+10/-0)
cli/tests/test_cli.py (+45/-2)
cli/tests/test_utils.py (+14/-1)
cli/ubuntu-ci (+4/-0)
To merge this branch: bzr merge lp:~cjohnston/ubuntu-ci-services-itself/reject-bad-lists
Reviewer Review Type Date Requested Status
Chris Johnston (community) Approve
Andy Doan (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+208519@code.launchpad.net

Commit message

Make the CLI check the formatting of -a and -r to ensure that there are no spaces

To post a comment you must log in.
Revision history for this message
Andy Doan (doanac) wrote :

don't want to sound like bike-shedding, but this confused me as I read. you have a function name:

21 +def is_valid_package_list(package_list_str):

but it returns true if it passes, and throws an exception if it fails. I think you want something like:

 def assert_valid_package_list(package_list_str)

the function returns nothing, but throws an exception if the list isn't correct.

My last comment is super shedding, so i'd just say ignore me. However, WRT "utils.InputError", I think just using Python's built-in exception "ValueError" might make more sense.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:297
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/276/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/276/rebuild

review: Approve (continuous-integration)
298. By Chris Johnston

Rename function to assert_valid_package_list, return nothing or raise error

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:298
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/279/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/279/rebuild

review: Approve (continuous-integration)
299. By Chris Johnston

Add a new unit test for checking an invalid entry

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:299
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/280/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/280/rebuild

review: Approve (continuous-integration)
Revision history for this message
Andy Doan (doanac) :
review: Approve
Revision history for this message
Chris Johnston (cjohnston) wrote :

 merge approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cli/ci_libs/utils.py'
2--- cli/ci_libs/utils.py 2014-02-17 10:13:29 +0000
3+++ cli/ci_libs/utils.py 2014-03-03 22:45:18 +0000
4@@ -36,6 +36,10 @@
5 AUTH_CONFIG = None
6
7
8+class InputError(Exception):
9+ """Exception raised for errors in the input."""
10+
11+
12 def load_config(config_file):
13 global CI_URL
14 global AUTH_CONFIG
15@@ -102,3 +106,9 @@
16 # Package not found.
17 log.info("Source package not found: %s" % sourcepackage)
18 return ''
19+
20+
21+def assert_valid_package_list(package_list_str):
22+ if package_list_str and " " in package_list_str:
23+ raise InputError("Added and removed packages have to be "
24+ "comma-separated lists with no spaces.")
25
26=== modified file 'cli/tests/test_cli.py'
27--- cli/tests/test_cli.py 2014-02-28 20:09:45 +0000
28+++ cli/tests/test_cli.py 2014-03-03 22:45:18 +0000
29@@ -154,7 +154,7 @@
30 'data/foobar_0.1-1_source.changes')
31 args = ['create_ticket', '-t', 'New feature', '-b', '1234', '-o',
32 'someone@example.com', '-d', 'This is a cool new feature',
33- '-a', 'foo', '-r', 'baz', '-s', changes]
34+ '-a', 'foo', '-r', 'bar,baz', '-s', changes]
35
36 args = self.cli.parse_arguments(args)
37 new_ticket_ = new_ticket(args)
38@@ -177,7 +177,7 @@
39
40 args = ['create_ticket', '-t', '"New feature"', '-b', '4321', '-o',
41 'someone@example.com', '-d', '"This is a cool new feature"',
42- '-a', 'foo', '-r', 'baz', '-s', changes_1, '-s', changes_2]
43+ '-a', 'foo,bar', '-r', 'baz', '-s', changes_1, '-s', changes_2]
44
45 args = self.cli.parse_arguments(args)
46 new_ticket_ = new_ticket(args)
47@@ -295,3 +295,46 @@
48 lc.records[0].msg,
49 "Problem validating .changes file: Invalid 'Distribution' in "
50 ".changes: UNRELEASED")
51+
52+ @mock.patch('ci_libs.ticket.SubTicket._process')
53+ @mock.patch('ci_libs.utils.post',
54+ return_value='http://www.example.com/api/v1/ticket/39/')
55+ def test_is_valid_package_list_add_space(self, mock_patch, mock_post):
56+ """
57+ Test a ticket adding two test binaries and not removing any binaries
58+ fails
59+ """
60+ changes = os.path.join(os.path.dirname(__file__),
61+ 'data/foobar_0.1-1_source.changes')
62+ args = ['create_ticket', '-t', '"New feature"', '-d',
63+ '"This is a cool new feature"', '-o', 'someone@example.com',
64+ '-a', 'foo, bar', '-s', changes]
65+ with LogCapture() as lc:
66+ logger = logging.getLogger()
67+ self.cli.main(args, log=logger)
68+ self.assertIsNotNone(lc)
69+ self.assertEquals(
70+ lc.records[0].msg[0],
71+ "Added and removed packages have to be comma-separated lists "
72+ "with no spaces.")
73+
74+ @mock.patch('ci_libs.ticket.SubTicket._process')
75+ @mock.patch('ci_libs.utils.post',
76+ return_value='http://www.example.com/api/v1/ticket/39/')
77+ def test_is_valid_package_list_remove_space(self, mock_patch, mock_post):
78+ """
79+ Test a ticket removing two test binaries fails
80+ """
81+ changes = os.path.join(os.path.dirname(__file__),
82+ 'data/foobar_0.1-1_source.changes')
83+ args = ['create_ticket', '-t', '"New feature"', '-d',
84+ '"This is a cool new feature"', '-o', 'someone@example.com',
85+ '-a', 'foo', '-r', 'bar, baz', '-s', changes]
86+ with LogCapture() as lc:
87+ logger = logging.getLogger()
88+ self.cli.main(args, log=logger)
89+ self.assertIsNotNone(lc)
90+ self.assertEquals(
91+ lc.records[0].msg[0],
92+ "Added and removed packages have to be comma-separated lists "
93+ "with no spaces.")
94
95=== modified file 'cli/tests/test_utils.py'
96--- cli/tests/test_utils.py 2014-02-17 10:13:29 +0000
97+++ cli/tests/test_utils.py 2014-03-03 22:45:18 +0000
98@@ -18,6 +18,7 @@
99 import json
100 import mock
101 import tempfile
102+import logging
103
104 from tests import CLITestCase
105 from ci_libs import utils
106@@ -68,7 +69,6 @@
107
108 def test_load_config(self):
109 with tempfile.NamedTemporaryFile() as config_file:
110- import logging
111 logging.warn("config_file: %s", config_file)
112 logging.warn("config_file.name: %s", config_file.name)
113 with open(config_file.name, 'w') as fp:
114@@ -77,3 +77,16 @@
115 utils.load_config(config_file.name)
116
117 self.assertEqual('http://example.com/ci', utils.CI_URL)
118+
119+ def test_assert_valid_package_list_single(self):
120+ utils.assert_valid_package_list('foo')
121+
122+ def test_assert_valid_package_list_three(self):
123+ utils.assert_valid_package_list('foo,bar,baz')
124+
125+ def test_assert_valid_package_list_empty(self):
126+ utils.assert_valid_package_list(package_list_str=None)
127+
128+ def test_assert_valid_package_list_with_space(self):
129+ with self.assertRaises(utils.InputError):
130+ utils.assert_valid_package_list('bar, baz')
131
132=== modified file 'cli/ubuntu-ci'
133--- cli/ubuntu-ci 2014-02-28 20:09:45 +0000
134+++ cli/ubuntu-ci 2014-03-03 22:45:18 +0000
135@@ -103,6 +103,8 @@
136 raise ChangesFileNotFound(source)
137 if not source.endswith(".changes"):
138 raise NotAChangesFileError(source)
139+ utils.assert_valid_package_list(args.add)
140+ utils.assert_valid_package_list(args.remove)
141
142 except AttributeError:
143 # We're not in create_ticket context, moving on.
144@@ -111,6 +113,8 @@
145 utils.load_config(DEF_CFG)
146 args.func(args)
147 return 0
148+ except utils.InputError as exc:
149+ log.error(exc)
150 except ChangesFileNotFound as exc:
151 log.error("Changes file not found: {}".format(exc))
152 except NotAChangesFileError as exc:

Subscribers

People subscribed via source and target branches