8687.15.17
by Karl Fogel
Add the copyright header block to the rest of the files under lib/lp/. |
1 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
4486.3.1
by Jonathan Lange
Don't display abandoned branches on the product overview "latest branches" portlet. |
3 |
|
4 |
"""Tests for BranchSet."""
|
|
5 |
||
6 |
__metaclass__ = type |
|
7 |
||
12504.1.3
by Robert Collins
Reject reversion of this branch on trunk. |
8 |
from testtools.matchers import LessThan |
4486.3.1
by Jonathan Lange
Don't display abandoned branches on the product overview "latest branches" portlet. |
9 |
|
11666.3.5
by Curtis Hovey
Import layers from canonical.testing.layers. |
10 |
from canonical.testing.layers import DatabaseFunctionalLayer |
11116.5.1
by Jonathan Lange
Move bits of the branch.txt doc test into unit tests. |
11 |
from lp.code.interfaces.branch import IBranchSet |
8138.1.2
by Jonathan Lange
Run migrater over lp.code. Many tests broken and imports failing. |
12 |
from lp.code.model.branch import BranchSet |
12504.1.3
by Robert Collins
Reject reversion of this branch on trunk. |
13 |
from lp.testing import ( |
14 |
logout, |
|
15 |
TestCaseWithFactory, |
|
16 |
)
|
|
17 |
from lp.testing._webservice import QueryCollector |
|
18 |
from lp.testing.matchers import HasQueryCount |
|
14578.4.4
by William Grant
format-imports. |
19 |
from lp.testing.pages import LaunchpadWebServiceCaller |
4486.3.1
by Jonathan Lange
Don't display abandoned branches on the product overview "latest branches" portlet. |
20 |
|
21 |
||
9841.2.4
by Jonathan Lange
Move the getByUrls implementation out of IBranchLookup. It's kind of a crappy |
22 |
class TestBranchSet(TestCaseWithFactory): |
4486.3.1
by Jonathan Lange
Don't display abandoned branches on the product overview "latest branches" portlet. |
23 |
|
7349.1.1
by Jonathan Lange
Cherry pick the content class stuff into a separate branch. |
24 |
layer = DatabaseFunctionalLayer |
4486.3.1
by Jonathan Lange
Don't display abandoned branches on the product overview "latest branches" portlet. |
25 |
|
11116.5.1
by Jonathan Lange
Move bits of the branch.txt doc test into unit tests. |
26 |
def test_provides_IBranchSet(self): |
27 |
# BranchSet instances provide IBranchSet.
|
|
12504.1.3
by Robert Collins
Reject reversion of this branch on trunk. |
28 |
self.assertProvides(BranchSet(), IBranchSet) |
11116.5.1
by Jonathan Lange
Move bits of the branch.txt doc test into unit tests. |
29 |
|
9841.2.4
by Jonathan Lange
Move the getByUrls implementation out of IBranchLookup. It's kind of a crappy |
30 |
def test_getByUrls(self): |
31 |
# getByUrls returns a list of branches matching the list of URLs that
|
|
32 |
# it's given.
|
|
33 |
a = self.factory.makeAnyBranch() |
|
34 |
b = self.factory.makeAnyBranch() |
|
12504.1.3
by Robert Collins
Reject reversion of this branch on trunk. |
35 |
branches = BranchSet().getByUrls( |
9841.2.10
by Jonathan Lange
Update the tests to match the new API. |
36 |
[a.bzr_identity, b.bzr_identity]) |
37 |
self.assertEqual({a.bzr_identity: a, b.bzr_identity: b}, branches) |
|
9841.2.4
by Jonathan Lange
Move the getByUrls implementation out of IBranchLookup. It's kind of a crappy |
38 |
|
39 |
def test_getByUrls_cant_find_url(self): |
|
40 |
# If a branch cannot be found for a URL, then None appears in the list
|
|
41 |
# in place of the branch.
|
|
9841.2.10
by Jonathan Lange
Update the tests to match the new API. |
42 |
url = 'http://example.com/doesntexist' |
12504.1.3
by Robert Collins
Reject reversion of this branch on trunk. |
43 |
branches = BranchSet().getByUrls([url]) |
9841.2.10
by Jonathan Lange
Update the tests to match the new API. |
44 |
self.assertEqual({url: None}, branches) |
12475.1.5
by Robert Collins
And eager load series source package links too. |
45 |
|
12504.1.3
by Robert Collins
Reject reversion of this branch on trunk. |
46 |
def test_api_branches_query_count(self): |
47 |
webservice = LaunchpadWebServiceCaller() |
|
48 |
collector = QueryCollector() |
|
49 |
collector.register() |
|
50 |
self.addCleanup(collector.unregister) |
|
51 |
# Get 'all' of the 50 branches this collection is limited to - rather
|
|
52 |
# than the default in-test-suite pagination size of 5.
|
|
53 |
url = "/branches?ws.size=50" |
|
54 |
logout() |
|
55 |
response = webservice.get(url, |
|
56 |
headers={'User-Agent': 'AnonNeedsThis'}) |
|
57 |
self.assertEqual(response.status, 200, |
|
58 |
"Got %d for url %r with response %r" % ( |
|
59 |
response.status, url, response.body)) |
|
12641.3.12
by Ian Booth
Fix test failures due to lazr restful upgrade |
60 |
self.assertThat(collector, HasQueryCount(LessThan(17))) |