Merge lp:~marcoceppi/charm-tools/require-series into lp:charm-tools/1.3

Proposed by Marco Ceppi
Status: Merged
Merged at revision: 327
Proposed branch: lp:~marcoceppi/charm-tools/require-series
Merge into: lp:charm-tools/1.3
Diff against target: 129 lines (+70/-24)
2 files modified
charmtools/promulgate.py (+19/-24)
tests/test_charm_promulgate.py (+51/-0)
To merge this branch: bzr merge lp:~marcoceppi/charm-tools/require-series
Reviewer Review Type Date Requested Status
Tim Van Steenburgh (community) Approve
Review via email: mp+223620@code.launchpad.net

Description of the change

Makes series flag required for charm promulgate

To post a comment you must log in.
Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

Syntax error (see inline diff comment). Also it would be nice to add a unit test for get_lp_charm_series().

review: Needs Fixing
328. By Marco Ceppi

Added unit tests, fixed missing ,

329. By Marco Ceppi

I am a giddy goat

Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

+1 LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmtools/promulgate.py'
2--- charmtools/promulgate.py 2013-12-02 20:25:28 +0000
3+++ charmtools/promulgate.py 2014-06-18 19:48:09 +0000
4@@ -19,22 +19,18 @@
5 # along with this program. If not, see <http://www.gnu.org/licenses/>.
6 #
7
8-from launchpadlib.launchpad import Launchpad
9-from lazr.restfulclient.errors import BadRequest, NotFound
10-
11 import os
12 import sys
13-
14-from optparse import OptionParser
15-
16-from bzrlib import bzrdir
17-
18 import yaml
19-
20 import logging
21-
22 import subprocess
23
24+from optparse import OptionParser
25+from bzrlib import bzrdir
26+
27+from launchpadlib.launchpad import Launchpad
28+from lazr.restfulclient.errors import BadRequest, NotFound
29+
30 DISTRIBUTION = 'charms'
31 REVIEW_TEAM_NAME = 'charmers'
32 OFFICIAL_BRANCH_POCKET = 'Release'
33@@ -50,7 +46,7 @@
34 'from the bzr configuration if omitted.')
35
36 parser.add_option(
37- '-s', '--series', dest='series', default=None,
38+ '-s', '--series', dest='series', default=None, required=True,
39 help='The distribution series on which to set the official branch. '
40 'Defaults to setting it in the current development series.')
41
42@@ -151,19 +147,18 @@
43 def get_lp_charm_series(lp, series):
44 charm_distro = lp.distributions[DISTRIBUTION]
45 if series is None:
46- charm_series = charm_distro.current_series
47- else:
48- try:
49- charm_series = charm_distro.getSeries(
50- name_or_version=series)
51- except (BadRequest, NotFound), e:
52- # XXX flacoste 2011-06-15 bug=797917
53- # Should only be NotFound.
54- if e.content.startswith('No such distribution series:'):
55- logging.error("can't find series '%s'", series)
56- raise
57- else:
58- raise
59+ raise ValueError("Series can not be None")
60+ try:
61+ charm_series = charm_distro.getSeries(
62+ name_or_version=series)
63+ except (BadRequest, NotFound), e:
64+ # XXX flacoste 2011-06-15 bug=797917
65+ # Should only be NotFound.
66+ if e.content.startswith('No such distribution series:'):
67+ logging.error("can't find series '%s'", series)
68+ raise
69+ else:
70+ raise
71 return charm_series
72
73
74
75=== added file 'tests/test_charm_promulgate.py'
76--- tests/test_charm_promulgate.py 1970-01-01 00:00:00 +0000
77+++ tests/test_charm_promulgate.py 2014-06-18 19:48:09 +0000
78@@ -0,0 +1,51 @@
79+#!/usr/bin/python
80+
81+# Copyright (C) 2013 Canonical Ltd.
82+#
83+# This program is free software: you can redistribute it and/or modify
84+# it under the terms of the GNU General Public License as published by
85+# the Free Software Foundation, either version 3 of the License, or
86+# (at your option) any later version.
87+#
88+# This program is distributed in the hope that it will be useful,
89+# but WITHOUT ANY WARRANTY; without even the implied warranty of
90+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
91+# GNU General Public License for more details.
92+#
93+# You should have received a copy of the GNU General Public License
94+# along with this program. If not, see <http://www.gnu.org/licenses/>.
95+
96+import sys
97+import unittest
98+
99+from mock import Mock
100+from charmtools.promulgate import get_lp_charm_series
101+
102+
103+class NotFound(Exception):
104+ content = None
105+ def __init__(self, content):
106+ self.content = content
107+
108+
109+class TestCharmProof(unittest.TestCase):
110+ def test_get_lp_charm_series(self):
111+ lp = Mock()
112+ charms = Mock()
113+ charms.getSeries.return_value = "trusty"
114+ lp.distributions = {'charms': charms}
115+ self.assertEqual('trusty', get_lp_charm_series(lp, 'trusty'))
116+
117+ def test_get_lp_charm_series_none(self):
118+ lp = Mock()
119+ charms = Mock()
120+ charms.getSeries.return_value = "trusty"
121+ lp.distributions = {'charms': charms}
122+ self.assertRaises(ValueError, get_lp_charm_series, lp, None)
123+
124+ def test_get_lp_charm_series_404(self):
125+ lp = Mock()
126+ charms = Mock()
127+ charms.getSeries.side_effect = NotFound('No such distribution series:')
128+ lp.distributions = {'charms': charms}
129+ self.assertRaises(NotFound, get_lp_charm_series, lp, 'not-series')

Subscribers

People subscribed via source and target branches

to all changes: