Merge ~twom/launchpad:redistribute-the-distribution-tests into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: d540efb21411f10dbe8f5df51b08239954ad1e24
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:redistribute-the-distribution-tests
Merge into: launchpad:master
Diff against target: 118 lines (+44/-39)
1 file modified
lib/lp/registry/tests/test_distribution.py (+44/-39)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+383228@code.launchpad.net

Commit message

Change distribution webservice unit tests for newer format

To post a comment you must log in.
d540efb... by Tom Wardill

Remove transaction and tidy imports

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/tests/test_distribution.py b/lib/lp/registry/tests/test_distribution.py
2index 6dfd8b5..f64e947 100644
3--- a/lib/lp/registry/tests/test_distribution.py
4+++ b/lib/lp/registry/tests/test_distribution.py
5@@ -18,7 +18,6 @@ from testtools.matchers import (
6 MatchesAny,
7 Not,
8 )
9-import transaction
10 from zope.component import getUtility
11 from zope.security.interfaces import Unauthorized
12 from zope.security.proxy import removeSecurityProxy
13@@ -56,14 +55,12 @@ from lp.soyuz.interfaces.distributionsourcepackagerelease import (
14 IDistributionSourcePackageRelease,
15 )
16 from lp.testing import (
17- admin_logged_in,
18 api_url,
19 celebrity_logged_in,
20 login_person,
21 person_logged_in,
22 TestCase,
23 TestCaseWithFactory,
24- WebServiceTestCase,
25 )
26 from lp.testing.layers import (
27 DatabaseFunctionalLayer,
28@@ -683,42 +680,6 @@ class TestDistributionTranslations(TestCaseWithFactory):
29 distro.translationpermission = TranslationPermission.CLOSED
30
31
32-class TestWebService(WebServiceTestCase):
33-
34- def test_oops_references_matching_distro(self):
35- # The distro layer provides the context restriction, so we need to
36- # check we can access context filtered references - e.g. on question.
37- oopsid = "OOPS-abcdef1234"
38- distro = self.factory.makeDistribution()
39- self.factory.makeQuestion(
40- title="Crash with %s" % oopsid, target=distro)
41- transaction.commit()
42- ws_distro = self.wsObject(distro, distro.owner)
43- now = datetime.datetime.now(tz=pytz.utc)
44- day = datetime.timedelta(days=1)
45- self.assertEqual(
46- [oopsid],
47- ws_distro.findReferencedOOPS(start_date=now - day, end_date=now))
48- self.assertEqual(
49- [],
50- ws_distro.findReferencedOOPS(
51- start_date=now + day, end_date=now + day))
52-
53- def test_oops_references_different_distro(self):
54- # The distro layer provides the context restriction, so we need to
55- # check the filter is tight enough - other contexts should not work.
56- oopsid = "OOPS-abcdef1234"
57- self.factory.makeQuestion(title="Crash with %s" % oopsid)
58- distro = self.factory.makeDistribution()
59- transaction.commit()
60- ws_distro = self.wsObject(distro, distro.owner)
61- now = datetime.datetime.now(tz=pytz.utc)
62- day = datetime.timedelta(days=1)
63- self.assertEqual(
64- [],
65- ws_distro.findReferencedOOPS(start_date=now - day, end_date=now))
66-
67-
68 class DistributionOCIProjectAdminPermission(TestCaseWithFactory):
69 layer = DatabaseFunctionalLayer
70
71@@ -803,3 +764,47 @@ class TestDistributionWebservice(TestCaseWithFactory):
72 self.webservice.getAbsoluteUrl(api_url(first_project)),
73 search_body["entries"][0]["self_link"])
74
75+ def test_oops_references_matching_distro(self):
76+ # The distro layer provides the context restriction, so we need to
77+ # check we can access context filtered references - e.g. on question.
78+ oopsid = "OOPS-abcdef1234"
79+ with person_logged_in(self.person):
80+ distro = self.factory.makeDistribution()
81+ self.factory.makeQuestion(
82+ title="Crash with %s" % oopsid, target=distro)
83+ distro_url = api_url(distro)
84+
85+ now = datetime.datetime.now(tz=pytz.utc)
86+ day = datetime.timedelta(days=1)
87+
88+ yesterday_response = self.webservice.named_get(
89+ distro_url,
90+ "findReferencedOOPS",
91+ start_date=(now - day).isoformat(),
92+ end_date=now.isoformat())
93+ self.assertEqual([oopsid], yesterday_response.jsonBody())
94+
95+ future_response = self.webservice.named_get(
96+ distro_url,
97+ "findReferencedOOPS",
98+ start_date=(now + day).isoformat(),
99+ end_date=(now + day).isoformat())
100+ self.assertEqual([], future_response.jsonBody())
101+
102+ def test_oops_references_different_distro(self):
103+ # The distro layer provides the context restriction, so we need to
104+ # check the filter is tight enough - other contexts should not work.
105+ oopsid = "OOPS-abcdef1234"
106+ with person_logged_in(self.person):
107+ self.factory.makeQuestion(title="Crash with %s" % oopsid)
108+ distro = self.factory.makeDistribution()
109+ distro_url = api_url(distro)
110+ now = datetime.datetime.now(tz=pytz.utc)
111+ day = datetime.timedelta(days=1)
112+
113+ empty_response = self.webservice.named_get(
114+ distro_url,
115+ "findReferencedOOPS",
116+ start_date=(now - day).isoformat(),
117+ end_date=now.isoformat())
118+ self.assertEqual([], empty_response.jsonBody())

Subscribers

People subscribed via source and target branches

to status/vote changes: