/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5050.79.2 by John Arbash Meinel
Start refactoring lp_api_lite and making it testable.
1
# Copyright (C) 2011 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""Tools for dealing with the Launchpad API without using launchpadlib.
18
"""
19
6024.3.8 by John Arbash Meinel
Move 'place' logic onto LatestPublication.
20
import doctest
5050.79.2 by John Arbash Meinel
Start refactoring lp_api_lite and making it testable.
21
import socket
22
23
from bzrlib import tests
6024.3.3 by John Arbash Meinel
Start at least testing the package_branch regex.
24
from bzrlib.plugins import launchpad
5050.79.2 by John Arbash Meinel
Start refactoring lp_api_lite and making it testable.
25
from bzrlib.plugins.launchpad import lp_api_lite
26
6024.3.8 by John Arbash Meinel
Move 'place' logic onto LatestPublication.
27
from testtools.matchers import DocTestMatches
28
29
5050.79.4 by John Arbash Meinel
Put several tests behind a Feature object.
30
class _JSONParserFeature(tests.Feature):
31
32
    def _probe(self):
33
        return lp_api_lite.json is not None
34
35
    def feature_name(self):
36
        return 'simplejson or json'
37
38
JSONParserFeature = _JSONParserFeature()
39
5050.79.2 by John Arbash Meinel
Start refactoring lp_api_lite and making it testable.
40
_example_response = r"""
41
{
42
    "total_size": 2,
43
    "start": 0,
44
    "next_collection_link": "https://api.launchpad.net/1.0/ubuntu/+archive/primary?distro_series=%2Fubuntu%2Flucid&exact_match=true&source_name=%22bzr%22&status=Published&ws.op=getPublishedSources&ws.start=1&ws.size=1",
45
    "entries": [
46
        {
47
            "package_creator_link": "https://api.launchpad.net/1.0/~maxb",
48
            "package_signer_link": "https://api.launchpad.net/1.0/~jelmer",
49
            "source_package_name": "bzr",
50
            "removal_comment": null,
51
            "display_name": "bzr 2.1.4-0ubuntu1 in lucid",
52
            "date_made_pending": null,
53
            "source_package_version": "2.1.4-0ubuntu1",
54
            "date_superseded": null,
55
            "http_etag": "\"9ba966152dec474dc0fe1629d0bbce2452efaf3b-5f4c3fbb3eaf26d502db4089777a9b6a0537ffab\"",
56
            "self_link": "https://api.launchpad.net/1.0/ubuntu/+archive/primary/+sourcepub/1750327",
57
            "distro_series_link": "https://api.launchpad.net/1.0/ubuntu/lucid",
58
            "component_name": "main",
59
            "status": "Published",
60
            "date_removed": null,
61
            "pocket": "Updates",
62
            "date_published": "2011-05-30T06:09:58.653984+00:00",
63
            "removed_by_link": null,
64
            "section_name": "devel",
65
            "resource_type_link": "https://api.launchpad.net/1.0/#source_package_publishing_history",
66
            "archive_link": "https://api.launchpad.net/1.0/ubuntu/+archive/primary",
67
            "package_maintainer_link": "https://api.launchpad.net/1.0/~ubuntu-devel-discuss-lists",
68
            "date_created": "2011-05-30T05:19:12.233621+00:00",
69
            "scheduled_deletion_date": null
70
        }
71
    ]
72
}"""
73
5050.79.3 by John Arbash Meinel
All the bits are now hooked up. The slow tests are disabled,
74
_no_versions_response = '{"total_size": 0, "start": 0, "entries": []}'
75
76
5050.79.2 by John Arbash Meinel
Start refactoring lp_api_lite and making it testable.
77
class TestLatestPublication(tests.TestCase):
78
79
    def make_latest_publication(self, archive='ubuntu', series='natty',
80
                                project='bzr'):
81
        return lp_api_lite.LatestPublication(archive, series, project)
82
6024.3.8 by John Arbash Meinel
Move 'place' logic onto LatestPublication.
83
    def assertPlace(self, place, archive, series, project):
84
        lp = lp_api_lite.LatestPublication(archive, series, project)
85
        self.assertEqual(place, lp.place())
86
5050.79.2 by John Arbash Meinel
Start refactoring lp_api_lite and making it testable.
87
    def test_init(self):
88
        latest_pub = self.make_latest_publication()
89
        self.assertEqual('ubuntu', latest_pub._archive)
90
        self.assertEqual('natty', latest_pub._series)
91
        self.assertEqual('bzr', latest_pub._project)
5050.79.8 by John Arbash Meinel
We should supply pocket=Release when none is supplied.
92
        self.assertEqual('Release', latest_pub._pocket)
5050.79.2 by John Arbash Meinel
Start refactoring lp_api_lite and making it testable.
93
94
    def test__archive_URL(self):
95
        latest_pub = self.make_latest_publication()
96
        self.assertEqual(
97
            'https://api.launchpad.net/1.0/ubuntu/+archive/primary',
98
            latest_pub._archive_URL())
99
100
    def test__publication_status_for_ubuntu(self):
101
        latest_pub = self.make_latest_publication()
102
        self.assertEqual('Published', latest_pub._publication_status())
103
104
    def test__publication_status_for_debian(self):
105
        latest_pub = self.make_latest_publication(archive='debian')
106
        self.assertEqual('Pending', latest_pub._publication_status())
107
108
    def test_pocket(self):
109
        latest_pub = self.make_latest_publication(series='natty-proposed')
110
        self.assertEqual('natty', latest_pub._series)
111
        self.assertEqual('Proposed', latest_pub._pocket)
112
113
    def test_series_None(self):
114
        latest_pub = self.make_latest_publication(series=None)
115
        self.assertEqual('ubuntu', latest_pub._archive)
116
        self.assertEqual(None, latest_pub._series)
117
        self.assertEqual('bzr', latest_pub._project)
5050.79.8 by John Arbash Meinel
We should supply pocket=Release when none is supplied.
118
        self.assertEqual('Release', latest_pub._pocket)
5050.79.2 by John Arbash Meinel
Start refactoring lp_api_lite and making it testable.
119
120
    def test__query_params(self):
121
        latest_pub = self.make_latest_publication()
122
        self.assertEqual({'ws.op': 'getPublishedSources',
123
                          'exact_match': 'true',
124
                          'source_name': '"bzr"',
125
                          'status': 'Published',
126
                          'ws.size': '1',
127
                          'distro_series': '/ubuntu/natty',
5050.79.8 by John Arbash Meinel
We should supply pocket=Release when none is supplied.
128
                          'pocket': 'Release',
5050.79.2 by John Arbash Meinel
Start refactoring lp_api_lite and making it testable.
129
                         }, latest_pub._query_params())
130
131
    def test__query_params_no_series(self):
132
        latest_pub = self.make_latest_publication(series=None)
133
        self.assertEqual({'ws.op': 'getPublishedSources',
134
                          'exact_match': 'true',
135
                          'source_name': '"bzr"',
136
                          'status': 'Published',
137
                          'ws.size': '1',
5050.79.8 by John Arbash Meinel
We should supply pocket=Release when none is supplied.
138
                          'pocket': 'Release',
5050.79.2 by John Arbash Meinel
Start refactoring lp_api_lite and making it testable.
139
                         }, latest_pub._query_params())
140
141
    def test__query_params_pocket(self):
142
        latest_pub = self.make_latest_publication(series='natty-proposed')
143
        self.assertEqual({'ws.op': 'getPublishedSources',
144
                          'exact_match': 'true',
145
                          'source_name': '"bzr"',
146
                          'status': 'Published',
147
                          'ws.size': '1',
148
                          'distro_series': '/ubuntu/natty',
149
                          'pocket': 'Proposed',
150
                         }, latest_pub._query_params())
151
152
    def test__query_URL(self):
153
        latest_pub = self.make_latest_publication()
154
        # we explicitly sort params, so we can be sure this URL matches exactly
155
        self.assertEqual(
156
            'https://api.launchpad.net/1.0/ubuntu/+archive/primary'
157
            '?distro_series=%2Fubuntu%2Fnatty&exact_match=true'
5050.79.8 by John Arbash Meinel
We should supply pocket=Release when none is supplied.
158
            '&pocket=Release&source_name=%22bzr%22&status=Published'
5050.79.2 by John Arbash Meinel
Start refactoring lp_api_lite and making it testable.
159
            '&ws.op=getPublishedSources&ws.size=1',
160
            latest_pub._query_URL())
161
162
    def DONT_test__gracefully_handle_failed_rpc_connection(self):
163
        # TODO: This test kind of sucks. We intentionally create an arbitrary
164
        #       port and don't listen to it, because we want the request to fail.
165
        #       However, it seems to take 1s for it to timeout. Is there a way
166
        #       to make it fail faster?
167
        latest_pub = self.make_latest_publication()
168
        s = socket.socket()
169
        s.bind(('127.0.0.1', 0))
170
        addr, port = s.getsockname()
171
        latest_pub.LP_API_ROOT = 'http://%s:%s/' % (addr, port)
172
        s.close()
173
        self.assertIs(None, latest_pub._get_lp_info())
174
5050.79.3 by John Arbash Meinel
All the bits are now hooked up. The slow tests are disabled,
175
    def DONT_test__query_launchpad(self):
5050.79.2 by John Arbash Meinel
Start refactoring lp_api_lite and making it testable.
176
        # TODO: This is a test that we are making a valid request against
177
        #       launchpad. This seems important, but it is slow, requires net
178
        #       access, and requires launchpad to be up and running. So for
179
        #       now, it is commented out for production tests.
180
        latest_pub = self.make_latest_publication()
181
        json_txt = latest_pub._get_lp_info()
182
        self.assertIsNot(None, json_txt)
183
        if lp_api_lite.json is None:
184
            # We don't have a way to parse the text
185
            return
186
        # The content should be a valid json result
187
        content = lp_api_lite.json.loads(json_txt)
188
        entries = content['entries'] # It should have an 'entries' field.
189
        # ws.size should mean we get 0 or 1, and there should be something
190
        self.assertEqual(1, len(entries))
191
        entry = entries[0]
192
        self.assertEqual('bzr', entry['source_package_name'])
193
        version = entry['source_package_version']
194
        self.assertIsNot(None, version)
5050.79.3 by John Arbash Meinel
All the bits are now hooked up. The slow tests are disabled,
195
196
    def test__get_lp_info_no_json(self):
197
        # If we can't parse the json, we don't make the query.
198
        self.overrideAttr(lp_api_lite, 'json', None)
199
        latest_pub = self.make_latest_publication()
200
        self.assertIs(None, latest_pub._get_lp_info())
201
202
    def test__parse_json_info_no_module(self):
203
        # If a json parsing module isn't available, we just return None here.
204
        self.overrideAttr(lp_api_lite, 'json', None)
205
        latest_pub = self.make_latest_publication()
206
        self.assertIs(None, latest_pub._parse_json_info(_example_response))
207
208
    def test__parse_json_example_response(self):
5050.79.4 by John Arbash Meinel
Put several tests behind a Feature object.
209
        self.requireFeature(JSONParserFeature)
5050.79.3 by John Arbash Meinel
All the bits are now hooked up. The slow tests are disabled,
210
        latest_pub = self.make_latest_publication()
211
        content = latest_pub._parse_json_info(_example_response)
212
        self.assertIsNot(None, content)
213
        self.assertEqual(2, content['total_size'])
214
        entries = content['entries']
215
        self.assertEqual(1, len(entries))
216
        entry = entries[0]
217
        self.assertEqual('bzr', entry['source_package_name'])
218
        self.assertEqual("2.1.4-0ubuntu1", entry["source_package_version"])
219
5050.79.4 by John Arbash Meinel
Put several tests behind a Feature object.
220
    def test__parse_json_not_json(self):
221
        self.requireFeature(JSONParserFeature)
222
        latest_pub = self.make_latest_publication()
223
        self.assertIs(None, latest_pub._parse_json_info('Not_valid_json'))
224
5050.79.3 by John Arbash Meinel
All the bits are now hooked up. The slow tests are disabled,
225
    def test_get_latest_version_no_response(self):
226
        latest_pub = self.make_latest_publication()
227
        latest_pub._get_lp_info = lambda: None
228
        self.assertEqual(None, latest_pub.get_latest_version())
229
230
    def test_get_latest_version_no_json(self):
231
        self.overrideAttr(lp_api_lite, 'json', None)
232
        latest_pub = self.make_latest_publication()
233
        self.assertEqual(None, latest_pub.get_latest_version())
234
5050.79.4 by John Arbash Meinel
Put several tests behind a Feature object.
235
    def test_get_latest_version_invalid_json(self):
236
        self.requireFeature(JSONParserFeature)
237
        latest_pub = self.make_latest_publication()
238
        latest_pub._get_lp_info = lambda: "not json"
239
        self.assertEqual(None, latest_pub.get_latest_version())
240
5050.79.3 by John Arbash Meinel
All the bits are now hooked up. The slow tests are disabled,
241
    def test_get_latest_version_no_versions(self):
5050.79.4 by John Arbash Meinel
Put several tests behind a Feature object.
242
        self.requireFeature(JSONParserFeature)
5050.79.3 by John Arbash Meinel
All the bits are now hooked up. The slow tests are disabled,
243
        latest_pub = self.make_latest_publication()
244
        latest_pub._get_lp_info = lambda: _no_versions_response
245
        self.assertEqual(None, latest_pub.get_latest_version())
246
5050.79.4 by John Arbash Meinel
Put several tests behind a Feature object.
247
    def test_get_latest_version_missing_entries(self):
248
        # Launchpad's no-entries response does have an empty entries value.
249
        # However, lets test that we handle other failures without tracebacks
250
        self.requireFeature(JSONParserFeature)
251
        latest_pub = self.make_latest_publication()
252
        latest_pub._get_lp_info = lambda: '{}'
253
        self.assertEqual(None, latest_pub.get_latest_version())
254
255
    def test_get_latest_version_invalid_entries(self):
256
        # Make sure we sanely handle a json response we don't understand
257
        self.requireFeature(JSONParserFeature)
258
        latest_pub = self.make_latest_publication()
259
        latest_pub._get_lp_info = lambda: '{"entries": {"a": 1}}'
260
        self.assertEqual(None, latest_pub.get_latest_version())
261
5050.79.3 by John Arbash Meinel
All the bits are now hooked up. The slow tests are disabled,
262
    def test_get_latest_version_example(self):
5050.79.4 by John Arbash Meinel
Put several tests behind a Feature object.
263
        self.requireFeature(JSONParserFeature)
5050.79.3 by John Arbash Meinel
All the bits are now hooked up. The slow tests are disabled,
264
        latest_pub = self.make_latest_publication()
265
        latest_pub._get_lp_info = lambda: _example_response
266
        self.assertEqual("2.1.4-0ubuntu1", latest_pub.get_latest_version())
267
268
    def DONT_test_get_latest_version_from_launchpad(self):
5050.79.4 by John Arbash Meinel
Put several tests behind a Feature object.
269
        self.requireFeature(JSONParserFeature)
5050.79.3 by John Arbash Meinel
All the bits are now hooked up. The slow tests are disabled,
270
        latest_pub = self.make_latest_publication()
271
        self.assertIsNot(None, latest_pub.get_latest_version())
6024.3.3 by John Arbash Meinel
Start at least testing the package_branch regex.
272
6024.3.8 by John Arbash Meinel
Move 'place' logic onto LatestPublication.
273
    def test_place(self):
274
        self.assertPlace('Ubuntu', 'ubuntu', None, 'bzr')
275
        self.assertPlace('Ubuntu Natty', 'ubuntu', 'natty', 'bzr')
276
        self.assertPlace('Ubuntu Natty Proposed', 'ubuntu', 'natty-proposed',
277
                         'bzr')
278
        self.assertPlace('Debian', 'debian', None, 'bzr')
279
        self.assertPlace('Debian Sid', 'debian', 'sid', 'bzr')
280
6024.3.3 by John Arbash Meinel
Start at least testing the package_branch regex.
281
282
class TestIsUpToDate(tests.TestCase):
283
284
    def assertPackageBranchRe(self, url, user, archive, series, project):
6024.3.5 by John Arbash Meinel
Pull out code into helper functions, which allows us to test it.
285
        m = launchpad._package_branch.search(url)
6024.3.3 by John Arbash Meinel
Start at least testing the package_branch regex.
286
        if m is None:
287
            self.fail('package_branch regex did not match url: %s' % (url,))
288
        self.assertEqual(
289
            (user, archive, series, project),
290
            m.group('user', 'archive', 'series', 'project'))
291
6024.3.5 by John Arbash Meinel
Pull out code into helper functions, which allows us to test it.
292
    def assertNotPackageBranch(self, url):
293
        self.assertIs(None, launchpad._get_package_branch_info(url))
294
295
    def assertBranchInfo(self, url, archive, series, project):
296
        self.assertEqual((archive, series, project),
297
            launchpad._get_package_branch_info(url))
298
6024.3.3 by John Arbash Meinel
Start at least testing the package_branch regex.
299
    def test_package_branch_regex(self):
300
        self.assertPackageBranchRe(
301
            'http://bazaar.launchpad.net/+branch/ubuntu/foo',
302
            None, 'ubuntu', None, 'foo')
6024.3.4 by John Arbash Meinel
More tests, and a small fix for the regex.
303
        self.assertPackageBranchRe(
6024.3.5 by John Arbash Meinel
Pull out code into helper functions, which allows us to test it.
304
            'bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/natty/foo',
6024.3.4 by John Arbash Meinel
More tests, and a small fix for the regex.
305
            None, 'ubuntu', 'natty/', 'foo')
306
        self.assertPackageBranchRe(
6024.3.5 by John Arbash Meinel
Pull out code into helper functions, which allows us to test it.
307
            'sftp://bazaar.launchpad.net/+branch/debian/foo',
6024.3.4 by John Arbash Meinel
More tests, and a small fix for the regex.
308
            None, 'debian', None, 'foo')
309
        self.assertPackageBranchRe(
310
            'http://bazaar.launchpad.net/+branch/debian/sid/foo',
311
            None, 'debian', 'sid/', 'foo')
312
        self.assertPackageBranchRe(
313
            'http://bazaar.launchpad.net/+branch'
314
            '/~ubuntu-branches/ubuntu/natty/foo/natty',
315
            '~ubuntu-branches/', 'ubuntu', 'natty/', 'foo')
6024.3.5 by John Arbash Meinel
Pull out code into helper functions, which allows us to test it.
316
        self.assertPackageBranchRe(
317
            'http://bazaar.launchpad.net/+branch'
318
            '/~user/ubuntu/natty/foo/test',
319
            '~user/', 'ubuntu', 'natty/', 'foo')
320
321
    def test_package_branch_doesnt_match(self):
322
        self.assertNotPackageBranch('http://example.com/ubuntu/foo')
323
        self.assertNotPackageBranch(
324
            'http://bazaar.launchpad.net/+branch/bzr')
325
        self.assertNotPackageBranch(
326
            'http://bazaar.launchpad.net/+branch/~bzr-pqm/bzr/bzr.dev')
327
        # Not a packaging branch because ~user isn't ~ubuntu-branches
328
        self.assertNotPackageBranch(
329
            'http://bazaar.launchpad.net/+branch'
330
            '/~user/ubuntu/natty/foo/natty')
331
332
    def test__get_package_branch_info(self):
333
        self.assertBranchInfo(
334
            'bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/natty/foo',
335
            'ubuntu', 'natty', 'foo')
336
        self.assertBranchInfo(
337
            'bzr+ssh://bazaar.launchpad.net/+branch'
338
            '/~ubuntu-branches/ubuntu/natty/foo/natty',
339
            'ubuntu', 'natty', 'foo')
340
        self.assertBranchInfo(
341
            'http://bazaar.launchpad.net/+branch'
342
            '/~ubuntu-branches/debian/sid/foo/sid',
343
            'debian', 'sid', 'foo')
6024.3.7 by John Arbash Meinel
Add code to determine the moste recent tag.
344
345
346
class TestGetMostRecentTag(tests.TestCaseWithMemoryTransport):
347
348
    def make_simple_builder(self):
349
        builder = self.make_branch_builder('tip')
350
        builder.build_snapshot('A', [], [
351
            ('add', ('', 'root-id', 'directory', None))])
352
        b = builder.get_branch()
353
        b.tags.set_tag('tip-1.0', 'A')
354
        return builder, b, b.tags.get_tag_dict()
355
356
    def test_get_most_recent_tag_tip(self):
357
        builder, b, tag_dict = self.make_simple_builder()
358
        self.assertEqual('tip-1.0',
359
                         lp_api_lite.get_most_recent_tag(tag_dict, b))
360
361
    def test_get_most_recent_tag_older(self):
362
        builder, b, tag_dict = self.make_simple_builder()
363
        builder.build_snapshot('B', ['A'], [])
364
        self.assertEqual('B', b.last_revision())
365
        self.assertEqual('tip-1.0',
366
                         lp_api_lite.get_most_recent_tag(tag_dict, b))
6024.3.8 by John Arbash Meinel
Move 'place' logic onto LatestPublication.
367
368
369
class StubLatestPublication(object):
370
371
    def __init__(self, latest):
372
        self.called = False
373
        self.latest = latest
374
375
    def get_latest_version(self):
376
        self.called = True
377
        return self.latest
378
379
    def place(self):
380
        return 'Ubuntu Natty'
381
382
383
class TestReportFreshness(tests.TestCaseWithMemoryTransport):
384
385
    def make_trivial_branch(self):
386
        builder = self.make_branch_builder('tip')
387
        builder.build_snapshot('A', [], [
388
            ('add', ('', 'root-id', 'directory', None))])
389
        b = builder.get_branch()
390
        return b
391
392
    def assertFreshnessReports(self, the_branch, verbosity, latest_version,
393
                               content):
394
        """Assert that lp_api_lite.report_freshness reports the given content.
395
396
        :param the_branch: The branch we are inspecting
397
        :param verbosity: The reporting level
398
        :param latest_version: The version reported by StubLatestPublication
399
        :param content: The expected content. This should be in DocTest form.
400
        """
401
        orig_log_len = len(self.get_log())
402
        lp_api_lite.report_freshness(the_branch, verbosity,
403
            StubLatestPublication(latest_version))
404
        new_content = self.get_log()[orig_log_len:]
405
        # Strip out lines that have LatestPublication.get_* because those are
406
        # timing related lines. While interesting to log for now, they aren't
407
        # something we want to be testing
408
        new_content = new_content.split('\n')
409
        for i in range(2):
410
            if (len(new_content) > 0
411
                and 'LatestPublication.get_' in new_content[0]):
412
                new_content = new_content[1:]
413
        new_content = '\n'.join(new_content)
414
        self.assertThat(new_content,
415
            DocTestMatches(content,
416
                doctest.ELLIPSIS | doctest.REPORT_UDIFF))
417
418
    def test_verbosity_off_skips_check(self):
419
        b = self.make_trivial_branch()
420
        # We force _get_package_branch_info so that we know it would otherwise
421
        # try to connect to launcphad
422
        self.overrideAttr(launchpad, '_get_package_branch_info',
423
            lambda x: ('ubuntu', 'natty', 'bzr'))
424
        self.overrideAttr(lp_api_lite, 'LatestPublication',
425
            lambda *args: self.fail('Tried to query launchpad'))
426
        c = b.get_config()
427
        c.set_user_option('bzr.plugins.launchpad.packaging_verbosity', 'off')
428
        orig_log_len = len(self.get_log())
429
        launchpad._check_is_up_to_date(b)
430
        new_content = self.get_log()[orig_log_len:]
431
        self.assertContainsRe(new_content,
432
            'not checking memory.*/tip/ because verbosity is turned off')
433
434
    def test_verbosity_off(self):
435
        b = self.make_trivial_branch()
436
        latest_pub = StubLatestPublication('1.0-1ubuntu2')
437
        lp_api_lite.report_freshness(b, 'off', latest_pub)
438
        self.assertFalse(latest_pub.called)
439
440
    def test_verbosity_minimal_no_tags(self):
441
        b = self.make_trivial_branch()
442
        self.assertFreshnessReports(b, 'minimal', '1.0-1ubuntu2',
443
            ' WARNING  Branch is OUT-OF-DATE, Ubuntu Natty has 1.0-1ubuntu2\n')
444
445
    def test_verbosity_minimal_out_of_date(self):
446
        b = self.make_trivial_branch()
447
        b.tags.set_tag('1.0-1ubuntu1', 'A')
448
        self.assertFreshnessReports(b, 'minimal', '1.0-1ubuntu2',
449
            ' WARNING  1.0-1ubuntu1 is OUT-OF-DATE,'
450
             ' Ubuntu Natty has 1.0-1ubuntu2\n')
451
452
    def test_verbosity_minimal_up_to_date(self):
453
        b = self.make_trivial_branch()
454
        b.tags.set_tag('1.0-1ubuntu2', 'A')
455
        self.assertFreshnessReports(b, 'minimal', '1.0-1ubuntu2',
456
             '')
457
458
    def test_verbosity_minimal_missing(self):
459
        b = self.make_trivial_branch()
460
        b.tags.set_tag('1.0-1ubuntu2', 'A')
461
        self.assertFreshnessReports(b, 'minimal', None,
462
             '')
463
464
    def test_verbosity_short_out_of_date(self):
465
        b = self.make_trivial_branch()
466
        b.tags.set_tag('1.0-1ubuntu1', 'A')
467
        self.assertFreshnessReports(b, 'short', '1.0-1ubuntu2',
468
            ' WARNING  1.0-1ubuntu1 is OUT-OF-DATE,'
469
             ' Ubuntu Natty has 1.0-1ubuntu2\n')
470
471
    def test_verbosity_short_up_to_date(self):
472
        b = self.make_trivial_branch()
473
        b.tags.set_tag('1.0-1ubuntu2', 'A')
474
        self.assertFreshnessReports(b, 'short', '1.0-1ubuntu2',
475
             '    INFO  1.0-1ubuntu2 is CURRENT in Ubuntu Natty')
476
477
    def test_verbosity_short_missing(self):
478
        b = self.make_trivial_branch()
479
        b.tags.set_tag('1.0-1ubuntu2', 'A')
480
        self.assertFreshnessReports(b, 'short', None,
481
             '    INFO  Ubuntu Natty is MISSING a version')
482
483
    def test_verbosity_all_no_tags(self):
484
        b = self.make_trivial_branch()
485
        self.assertFreshnessReports(b, 'all', '1.0-1ubuntu2',
486
             ' WARNING  Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
487
             'Packaging branch version: None\n'
488
             'Packaging branch status: OUT-OF-DATE\n')
489
490
    def test_verbosity_all_out_of_date(self):
491
        b = self.make_trivial_branch()
492
        b.tags.set_tag('1.0-1ubuntu1', 'A')
493
        self.assertFreshnessReports(b, 'all', '1.0-1ubuntu2',
494
             ' WARNING  Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
495
             'Packaging branch version: 1.0-1ubuntu1\n'
496
             'Packaging branch status: OUT-OF-DATE\n')
497
498
    def test_verbosity_all_up_to_date(self):
499
        b = self.make_trivial_branch()
500
        b.tags.set_tag('1.0-1ubuntu2', 'A')
501
        self.assertFreshnessReports(b, 'all', '1.0-1ubuntu2',
502
             '    INFO  Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
503
             'Packaging branch status: CURRENT\n')
504
505
    def test_verbosity_all_missing(self):
506
        b = self.make_trivial_branch()
507
        b.tags.set_tag('1.0-1ubuntu2', 'A')
508
        self.assertFreshnessReports(b, 'all', None,
509
             '    INFO  Most recent Ubuntu Natty version: MISSING\n')
510
511
    def test_verbosity_None_is_all(self):
512
        b = self.make_trivial_branch()
513
        b.tags.set_tag('1.0-1ubuntu2', 'A')
514
        self.assertFreshnessReports(b, None, '1.0-1ubuntu2',
515
             '    INFO  Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
516
             'Packaging branch status: CURRENT\n')