← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:distribution-privacy-prepare into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:distribution-privacy-prepare into launchpad:master.

Commit message:
Prepare various tests for private distributions

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/415118

Adding privacy support to distributions will require them having a non-trivial security adapter, which means that tests using `FunctionalLayer` must be careful only to access attributes of `IDistribution` (other than a few basic ones such as `id`) within a Zope interaction.  Some tests were sloppy about that, so this commit fixes them to behave more correctly.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:distribution-privacy-prepare into launchpad:master.
diff --git a/lib/lp/bugs/browser/tests/test_bugalsoaffects.py b/lib/lp/bugs/browser/tests/test_bugalsoaffects.py
index 86aeb97..3f056a4 100644
--- a/lib/lp/bugs/browser/tests/test_bugalsoaffects.py
+++ b/lib/lp/bugs/browser/tests/test_bugalsoaffects.py
@@ -21,6 +21,8 @@ class TestBugAlsoAffectsDistribution(TestCaseWithFactory):
     def setUp(self):
         super().setUp()
         self.distribution = self.factory.makeDistribution(displayname='Distro')
+        self.distribution_name = self.distribution.name
+        self.distribution_display_name = self.distribution.display_name
         removeSecurityProxy(self.distribution).official_malone = True
 
     def openBugPage(self, bug):
@@ -41,7 +43,7 @@ class TestBugAlsoAffectsDistribution(TestCaseWithFactory):
         spn = dsp2.sourcepackagename
         browser = self.openBugPage(bug)
         browser.getLink(url='+distrotask').click()
-        browser.getControl('Distribution').value = [self.distribution.name]
+        browser.getControl('Distribution').value = [self.distribution_name]
         browser.getControl('Source Package Name').value = spn.name
         browser.getControl('Continue').click()
         self.assertEqual([], get_feedback_messages(browser.contents))
@@ -60,7 +62,7 @@ class TestBugAlsoAffectsDistribution(TestCaseWithFactory):
         with FeatureFixture({"disclosure.dsp_picker.enabled": "on"}):
             browser = self.openBugPage(bug)
             browser.getLink(url='+distrotask').click()
-            browser.getControl('Distribution').value = [self.distribution.name]
+            browser.getControl('Distribution').value = [self.distribution_name]
             browser.getControl('Source Package Name').value = dsp2.name
             browser.getControl('Continue').click()
         self.assertEqual([], get_feedback_messages(browser.contents))
@@ -77,13 +79,13 @@ class TestBugAlsoAffectsDistribution(TestCaseWithFactory):
         self.assertTrue(self.distribution.has_published_binaries)
         browser = self.openBugPage(bug)
         browser.getLink(url='+distrotask').click()
-        browser.getControl('Distribution').value = [self.distribution.name]
+        browser.getControl('Distribution').value = [self.distribution_name]
         browser.getControl('Source Package Name').value = 'does-not-exist'
         browser.getControl('Continue').click()
         expected = [
             'There is 1 error.',
             'There is no package in %s named "does-not-exist".' % (
-                self.distribution.displayname)]
+                self.distribution_display_name)]
         self.assertEqual(expected, get_feedback_messages(browser.contents))
 
     def test_bug_alsoaffects_spn_not_exists_with_no_binaries(self):
@@ -91,13 +93,13 @@ class TestBugAlsoAffectsDistribution(TestCaseWithFactory):
         bug = self.factory.makeBug()
         browser = self.openBugPage(bug)
         browser.getLink(url='+distrotask').click()
-        browser.getControl('Distribution').value = [self.distribution.name]
+        browser.getControl('Distribution').value = [self.distribution_name]
         browser.getControl('Source Package Name').value = 'does-not-exist'
         browser.getControl('Continue').click()
         expected = [
             'There is 1 error.',
             'There is no package in %s named "does-not-exist". Launchpad '
             'does not track binary package names in %s.' % (
-                self.distribution.displayname,
-                self.distribution.displayname)]
+                self.distribution_display_name,
+                self.distribution_display_name)]
         self.assertEqual(expected, get_feedback_messages(browser.contents))
diff --git a/lib/lp/bugs/browser/tests/test_bugtask.py b/lib/lp/bugs/browser/tests/test_bugtask.py
index f47860e..245ba07 100644
--- a/lib/lp/bugs/browser/tests/test_bugtask.py
+++ b/lib/lp/bugs/browser/tests/test_bugtask.py
@@ -1525,6 +1525,7 @@ class TestBugTaskEditView(WithScenarios, TestCaseWithFactory):
         with admin_logged_in():
             ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
             oci_distro = self.factory.makeDistribution()
+            oci_distro_name = oci_distro.name
             oci_distro.official_malone = True
             oci_distro.default_traversal_policy = (
                 DistributionDefaultTraversalPolicy.OCI_PROJECT)
@@ -1537,7 +1538,7 @@ class TestBugTaskEditView(WithScenarios, TestCaseWithFactory):
         browser = self.getUserBrowser(url, user=bug_task.owner)
         browser.getControl(name='ubuntu.target').value = 'package'
         browser.getControl(name='ubuntu.target.distribution').value = (
-            oci_distro.name)
+            oci_distro_name)
         browser.getControl(name='ubuntu.target.package').value = (
             oci_project_name)
         browser.getControl("Save Changes").click()
@@ -1563,7 +1564,7 @@ class TestBugTaskEditView(WithScenarios, TestCaseWithFactory):
         browser = self.getUserBrowser(url, user=bug_task.owner)
         browser.getControl(name='oci-distro.target').value = 'package'
         browser.getControl(name='oci-distro.target.distribution').value = (
-            ubuntu.name)
+            'ubuntu')
         browser.getControl(name='oci-distro.target.package').value = ''
         browser.getControl("Save Changes").click()
 
@@ -1590,7 +1591,7 @@ class TestBugTaskEditView(WithScenarios, TestCaseWithFactory):
         browser = self.getUserBrowser(url, user=bug_task.owner)
         browser.getControl(name='oci-distro.target').value = 'package'
         browser.getControl(name='oci-distro.target.distribution').value = (
-            ubuntu.name)
+            'ubuntu')
         browser.getControl(name='oci-distro.target.package').value = sp.name
         browser.getControl("Save Changes").click()
 
diff --git a/lib/lp/code/stories/webservice/xx-code-import.txt b/lib/lp/code/stories/webservice/xx-code-import.txt
index 62a2056..c864fdf 100644
--- a/lib/lp/code/stories/webservice/xx-code-import.txt
+++ b/lib/lp/code/stories/webservice/xx-code-import.txt
@@ -223,9 +223,11 @@ We can create a Git-to-Git import.
 
 We can also create an import targetting a source package.
 
+    >>> login(ANONYMOUS)
     >>> source_package_url = (
     ...     '/' + distribution.name + '/' + distroseries.name + '/+source/'
     ...     + source_package.name)
+    >>> logout()
     >>> new_remote_url = factory.getUniqueURL()
     >>> response = import_webservice.named_post(source_package_url,
     ...    'newCodeImport', branch_name='new-import', rcs_type='Git',
@@ -256,8 +258,10 @@ We can also create an import targetting a source package.
 
 We can create a Git-to-Git import targetting a distribution source package.
 
+    >>> login(ANONYMOUS)
     >>> distro_source_package_url = (
     ...     '/' + distribution.name + '/+source/' + source_package.name)
+    >>> logout()
     >>> new_remote_url = factory.getUniqueURL()
     >>> with GitHostingFixture():
     ...     response = import_webservice.named_post(
diff --git a/lib/lp/registry/browser/tests/test_distribution.py b/lib/lp/registry/browser/tests/test_distribution.py
index 3f3ac9c..b0c3b61 100644
--- a/lib/lp/registry/browser/tests/test_distribution.py
+++ b/lib/lp/registry/browser/tests/test_distribution.py
@@ -366,12 +366,12 @@ class TestDistributionPage(TestCaseWithFactory):
         # User can't see the +search-oci-project link if there are no
         # available OCI projects.
         admin = login_celebrity('admin')
-        browser = self.getUserBrowser(canonical_url(self.distro), user=admin)
+        distro_url = canonical_url(self.distro)
+        browser = self.getUserBrowser(distro_url, user=admin)
         matchers = Not(soupmatchers.HTMLContains(
             soupmatchers.Tag(
                 'link to search oci project', 'a',
-                attrs={'href': canonical_url(
-                    self.distro, view_name='+search-oci-project')},
+                attrs={'href': '%s/+search-oci-project' % distro_url},
                 text='Search for OCI project')))
         self.assertThat(browser.contents, matchers)
 
@@ -379,12 +379,12 @@ class TestDistributionPage(TestCaseWithFactory):
         # User can see the +search-oci-project link if there are OCI projects.
         self.factory.makeOCIProject(pillar=self.distro)
         admin = login_celebrity('admin')
-        browser = self.getUserBrowser(canonical_url(self.distro), user=admin)
+        distro_url = canonical_url(self.distro)
+        browser = self.getUserBrowser(distro_url, user=admin)
         matchers = soupmatchers.HTMLContains(
             soupmatchers.Tag(
                 'link to search oci project', 'a',
-                attrs={'href': canonical_url(
-                    self.distro, view_name='+search-oci-project')},
+                attrs={'href': '%s/+search-oci-project' % distro_url},
                 text='Search for OCI project'))
         self.assertThat(browser.contents, matchers)
 
@@ -393,20 +393,19 @@ class TestDistributionPage(TestCaseWithFactory):
         # is disabled.
         self.useFixture(FeatureFixture({OCI_PROJECT_ALLOW_CREATE: ''}))
         user = self.factory.makePerson()
-        browser = self.getUserBrowser(canonical_url(self.distro), user=user)
+        distro_url = canonical_url(self.distro)
+        browser = self.getUserBrowser(distro_url, user=user)
 
         self.assertThat(browser.contents, Not(soupmatchers.HTMLContains(
             soupmatchers.Tag(
                 'link to search oci project', 'a',
-                attrs={'href': canonical_url(
-                    self.distro, view_name='+search-oci-project')},
+                attrs={'href': '%s/+search-oci-project' % distro_url},
                 text='Search for OCI project'))))
 
         self.assertThat(browser.contents, Not(soupmatchers.HTMLContains(
             soupmatchers.Tag(
                 'link to create oci project', 'a',
-                attrs={'href': canonical_url(
-                    self.distro, view_name='+new-oci-project')},
+                attrs={'href': '%s/+new-oci-project' % distro_url},
                 text='Create an OCI project'))))
 
     def test_distributionpage_oci_links_for_user_no_permission(self):
@@ -414,22 +413,21 @@ class TestDistributionPage(TestCaseWithFactory):
         # doesn't have permission to create OCI projects.
         self.factory.makeOCIProject(pillar=self.distro)
         user = self.factory.makePerson()
-        browser = self.getUserBrowser(canonical_url(self.distro), user=user)
+        distro_url = canonical_url(self.distro)
+        browser = self.getUserBrowser(distro_url, user=user)
 
         # User can see search link
         self.assertThat(browser.contents, soupmatchers.HTMLContains(
             soupmatchers.Tag(
                 'link to search oci project', 'a',
-                attrs={'href': canonical_url(
-                    self.distro, view_name='+search-oci-project')},
+                attrs={'href': '%s/+search-oci-project' % distro_url},
                 text='Search for OCI project')))
 
         # User cannot see "new-oci-project" link.
         self.assertThat(browser.contents, Not(soupmatchers.HTMLContains(
             soupmatchers.Tag(
                 'link to create oci project', 'a',
-                attrs={'href': canonical_url(
-                    self.distro, view_name='+new-oci-project')},
+                attrs={'href': '%s/+new-oci-project' % distro_url},
                 text='Create an OCI project'))))
 
     def test_distributionpage_addseries_link_noadmin(self):
diff --git a/lib/lp/registry/browser/tests/test_ociproject.py b/lib/lp/registry/browser/tests/test_ociproject.py
index 05babda..4837f5b 100644
--- a/lib/lp/registry/browser/tests/test_ociproject.py
+++ b/lib/lp/registry/browser/tests/test_ociproject.py
@@ -361,22 +361,24 @@ class TestOCIProjectEditView(BrowserTestCase):
         oci_project = self.factory.makeOCIProject()
         new_distribution = self.factory.makeDistribution(
             owner=oci_project.pillar.owner)
+        new_distribution_name = new_distribution.name
+        new_distribution_display_name = new_distribution.display_name
 
         browser = self.getViewBrowser(
             oci_project, user=oci_project.pillar.owner)
         browser.getLink("Edit OCI project").click()
         browser.getControl(name="field.distribution").value = [
-            new_distribution.name]
+            new_distribution_name]
         browser.getControl(name="field.name").value = "new-name"
         browser.getControl("Update OCI project").click()
 
         content = find_main_content(browser.contents)
         self.assertEqual(
-            "OCI project new-name for %s" % new_distribution.display_name,
+            "OCI project new-name for %s" % new_distribution_display_name,
             extract_text(content.h1))
         self.assertThat(
             "Distribution:\n%s\nEdit OCI project" % (
-                new_distribution.display_name),
+                new_distribution_display_name),
             MatchesTagText(content, "pillar"))
         self.assertThat(
             "Name:\nnew-name\nEdit OCI project",
@@ -419,22 +421,24 @@ class TestOCIProjectEditView(BrowserTestCase):
             pillar=original_distribution)
         new_distribution = self.factory.makeDistribution(
             oci_project_admin=admin_team)
+        new_distribution_name = new_distribution.name
+        new_distribution_display_name = new_distribution.display_name
 
         browser = self.getViewBrowser(
             oci_project, user=admin_person)
         browser.getLink("Edit OCI project").click()
         browser.getControl(name="field.distribution").value = [
-            new_distribution.name]
+            new_distribution_name]
         browser.getControl(name="field.name").value = "new-name"
         browser.getControl("Update OCI project").click()
 
         content = find_main_content(browser.contents)
         self.assertEqual(
-            "OCI project new-name for %s" % new_distribution.display_name,
+            "OCI project new-name for %s" % new_distribution_display_name,
             extract_text(content.h1))
         self.assertThat(
             "Distribution:\n%s\nEdit OCI project" % (
-                new_distribution.display_name),
+                new_distribution_display_name),
             MatchesTagText(content, "pillar"))
         self.assertThat(
             "Name:\nnew-name\nEdit OCI project",
@@ -486,6 +490,7 @@ class TestOCIProjectAddView(BrowserTestCase):
         user = oci_project.pillar.owner
         new_distribution = self.factory.makeDistribution(
             owner=user, oci_project_admin=user)
+        new_distribution_display_name = new_distribution.display_name
         browser = self.getViewBrowser(
             new_distribution, user=user, view_name='+new-oci-project')
         browser.getControl(name="field.name").value = "new-name"
@@ -493,11 +498,11 @@ class TestOCIProjectAddView(BrowserTestCase):
 
         content = find_main_content(browser.contents)
         self.assertEqual(
-            "OCI project new-name for %s" % new_distribution.display_name,
+            "OCI project new-name for %s" % new_distribution_display_name,
             extract_text(content.h1))
         self.assertThat(
             "Distribution:\n%s\nEdit OCI project" % (
-                new_distribution.display_name),
+                new_distribution_display_name),
             MatchesTagText(content, "pillar"))
         self.assertThat(
              "Name:\nnew-name\nEdit OCI project",
@@ -528,6 +533,7 @@ class TestOCIProjectAddView(BrowserTestCase):
     def test_create_oci_project_already_exists(self):
         person = self.factory.makePerson()
         distribution = self.factory.makeDistribution(oci_project_admin=person)
+        distribution_display_name = distribution.display_name
         self.factory.makeOCIProject(ociprojectname="new-name",
                                     pillar=distribution,
                                     registrant=person)
@@ -539,7 +545,7 @@ class TestOCIProjectAddView(BrowserTestCase):
 
         expected_msg = (
             "There is already an OCI project in distribution %s with this "
-            "name." % distribution.display_name)
+            "name." % distribution_display_name)
         self.assertEqual(
             expected_msg,
             extract_text(find_tags_by_class(browser.contents, "message")[1]))
diff --git a/lib/lp/registry/stories/webservice/xx-derivedistroseries.txt b/lib/lp/registry/stories/webservice/xx-derivedistroseries.txt
index af88a08..c794fa9 100644
--- a/lib/lp/registry/stories/webservice/xx-derivedistroseries.txt
+++ b/lib/lp/registry/stories/webservice/xx-derivedistroseries.txt
@@ -54,7 +54,9 @@ Calling
     >>> def ws_object(webservice, obj):
     ...     api_request = WebServiceTestRequest(
     ...         SERVER_URL=webservice.getAbsoluteUrl(""))
+    ...     login(ANONYMOUS)
     ...     obj_url = canonical_url(obj, request=api_request)
+    ...     logout()
     ...     return webservice.get(obj_url).jsonBody()
 
 We can't call .initDerivedDistroSeries() on a distroseries that already
diff --git a/lib/lp/registry/stories/webservice/xx-source-package.txt b/lib/lp/registry/stories/webservice/xx-source-package.txt
index b920169..4fc1562 100644
--- a/lib/lp/registry/stories/webservice/xx-source-package.txt
+++ b/lib/lp/registry/stories/webservice/xx-source-package.txt
@@ -7,6 +7,7 @@ Prelude
 
     >>> login(ANONYMOUS)
     >>> a_distro = factory.makeDistribution(name='my-distro')
+    >>> a_distro_owner = a_distro.owner
     >>> a_series = factory.makeDistroSeries(
     ...     name='my-series', distribution=a_distro)
     >>> evolution_package = factory.makeSourcePackage(
@@ -73,8 +74,7 @@ Then we set the branch on the evolution package:
     >>> from lp.testing.pages import webservice_for_person
     >>> from lp.services.webapp.interfaces import OAuthPermission
     >>> webservice = webservice_for_person(
-    ...     evolution_package.distribution.owner,
-    ...     permission=OAuthPermission.WRITE_PRIVATE)
+    ...     a_distro_owner, permission=OAuthPermission.WRITE_PRIVATE)
     >>> branch = webservice.get(branch_url).jsonBody()
     >>> response = webservice.named_post(
     ...     evolution['self_link'], 'setBranch', pocket='Release',
diff --git a/lib/lp/registry/tests/test_distroseries.py b/lib/lp/registry/tests/test_distroseries.py
index d214f99..f076ecd 100644
--- a/lib/lp/registry/tests/test_distroseries.py
+++ b/lib/lp/registry/tests/test_distroseries.py
@@ -634,6 +634,7 @@ class TestDistroSeriesWebservice(TestCaseWithFactory):
         # Somebody with only launchpad.TranslationsAdmin cannot request full
         # language pack exports.
         distroseries = self.factory.makeDistroSeries()
+        distroseries_url = api_url(distroseries)
         self.assertFalse(distroseries.language_pack_full_export_requested)
         group = self.factory.makeTranslationGroup()
         with admin_logged_in():
@@ -641,7 +642,7 @@ class TestDistroSeriesWebservice(TestCaseWithFactory):
         webservice = webservice_for_person(
             group.owner, permission=OAuthPermission.WRITE_PRIVATE)
         response = webservice.patch(
-            api_url(distroseries), "application/json",
+            distroseries_url, "application/json",
             json.dumps({"language_pack_full_export_requested": True}))
         self.assertEqual(401, response.status)
         self.assertFalse(distroseries.language_pack_full_export_requested)
@@ -650,13 +651,14 @@ class TestDistroSeriesWebservice(TestCaseWithFactory):
         # Somebody with launchpad.LanguagePacksAdmin can request full
         # language pack exports.
         distroseries = self.factory.makeDistroSeries()
+        distroseries_url = api_url(distroseries)
         self.assertFalse(distroseries.language_pack_full_export_requested)
         person = self.factory.makePerson(
             member_of=[getUtility(ILaunchpadCelebrities).rosetta_experts])
         webservice = webservice_for_person(
             person, permission=OAuthPermission.WRITE_PRIVATE)
         response = webservice.patch(
-            api_url(distroseries), "application/json",
+            distroseries_url, "application/json",
             json.dumps({"language_pack_full_export_requested": True}))
         self.assertEqual(209, response.status)
         self.assertTrue(distroseries.language_pack_full_export_requested)
diff --git a/lib/lp/registry/tests/test_ociproject.py b/lib/lp/registry/tests/test_ociproject.py
index 14ec569..b495419 100644
--- a/lib/lp/registry/tests/test_ociproject.py
+++ b/lib/lp/registry/tests/test_ociproject.py
@@ -253,7 +253,8 @@ class TestOCIProjectWebservice(TestCaseWithFactory):
         return response.jsonBody()
 
     def assertCanCreateOCIProject(self, distro, registrant):
-        url = api_url(distro)
+        with person_logged_in(self.person):
+            url = api_url(distro)
         obj = {"name": "someprojectname", "description": "My OCI project"}
         resp = self.webservice.named_post(url, "newOCIProject", **obj)
         self.assertEqual(201, resp.status, resp.body)
diff --git a/lib/lp/snappy/tests/test_snap.py b/lib/lp/snappy/tests/test_snap.py
index 709dd1f..e3b9143 100644
--- a/lib/lp/snappy/tests/test_snap.py
+++ b/lib/lp/snappy/tests/test_snap.py
@@ -4061,10 +4061,12 @@ class TestSnapWebservice(TestCaseWithFactory):
         # requestAutoBuilds can be performed over the webservice.
         distroseries = self.factory.makeDistroSeries()
         dases = []
+        das_urls = []
         for _ in range(3):
             processor = self.factory.makeProcessor(supports_virtualized=True)
             dases.append(self.makeBuildableDistroArchSeries(
                 distroseries=distroseries, processor=processor))
+            das_urls.append(api_url(dases[-1]))
         archive = self.factory.makeArchive()
         snap = self.makeSnap(
             distroseries=distroseries,
@@ -4076,7 +4078,8 @@ class TestSnapWebservice(TestCaseWithFactory):
         self.assertEqual(200, response.status)
         builds = response.jsonBody()
         self.assertContentEqual(
-            [self.getURL(das) for das in dases[:2]],
+            [self.webservice.getAbsoluteUrl(das_url)
+             for das_url in das_urls[:2]],
             [build["distro_arch_series_link"] for build in builds])
 
     def test_requestAutoBuilds_requires_auto_build_archive(self):
@@ -4151,7 +4154,7 @@ class TestSnapWebservice(TestCaseWithFactory):
         self.assertEqual(200, response.status)
         builds = response.jsonBody()
         self.assertContentEqual(
-            [self.getURL(dases[1])],
+            [self.webservice.getAbsoluteUrl(das_urls[1])],
             [build["distro_arch_series_link"] for build in builds])
 
     def test_getBuilds(self):
diff --git a/lib/lp/soyuz/stories/soyuz/xx-packagepublishinghistory.txt b/lib/lp/soyuz/stories/soyuz/xx-packagepublishinghistory.txt
index c12fa2d..5000b4f 100644
--- a/lib/lp/soyuz/stories/soyuz/xx-packagepublishinghistory.txt
+++ b/lib/lp/soyuz/stories/soyuz/xx-packagepublishinghistory.txt
@@ -47,8 +47,8 @@ intermediate archive information.
     >>> logout()
 
     >>> anon_browser.open(
-    ...     'http://launchpad.test/%s/+source/test-history/'
-    ...     '+publishinghistory' % new_distro.name)
+    ...     'http://launchpad.test/foo-distro/+source/test-history/'
+    ...     '+publishinghistory')
 
     >>> table = find_tag_by_id(anon_browser.contents, 'publishing-summary')
     >>> print(extract_text(table))  # noqa
@@ -76,8 +76,8 @@ original distribution was Ubuntutest breezy-autotest.
     >>> logout()
 
     >>> anon_browser.open(
-    ...     'http://launchpad.test/%s/+source/test-history/'
-    ...     '+publishinghistory' % new_distro.name)
+    ...     'http://launchpad.test/another-distro/+source/test-history/'
+    ...     '+publishinghistory')
     >>> table = find_tag_by_id(anon_browser.contents, 'publishing-summary')
     >>> print(extract_text(table))  # noqa
     Date    Status    Target          Pocket   Component Section Version
@@ -98,8 +98,8 @@ messages.
     ...     new_component='universe', creator=person)
     >>> logout()
     >>> anon_browser.open(
-    ...     'http://launchpad.test/%s/+source/test-history/'
-    ...     '+publishinghistory' % new_distro.name)
+    ...     'http://launchpad.test/another-distro/+source/test-history/'
+    ...     '+publishinghistory')
     >>> table = find_tag_by_id(anon_browser.contents, 'publishing-summary')
     >>> print(extract_text(table))  # noqa
     Date    Status    Target          Pocket   Component Section Version
diff --git a/lib/lp/translations/browser/tests/test_distribution_views.py b/lib/lp/translations/browser/tests/test_distribution_views.py
index 36d5e17..a92d5eb 100644
--- a/lib/lp/translations/browser/tests/test_distribution_views.py
+++ b/lib/lp/translations/browser/tests/test_distribution_views.py
@@ -40,9 +40,9 @@ class TestDistributionSettingsView(TestCaseWithFactory):
         self.useFixture(FakeLogger())
         unprivileged = self.factory.makePerson()
         distribution = self.factory.makeDistribution()
-        browser = self.getUserBrowser(user=unprivileged)
         url = canonical_url(distribution, view_name='+configure-translations',
                             rootsite='translations')
+        browser = self.getUserBrowser(user=unprivileged)
         self.assertRaises(Unauthorized, browser.open, url)
 
     def test_translation_group_owner(self):
@@ -53,9 +53,9 @@ class TestDistributionSettingsView(TestCaseWithFactory):
         distribution = self.factory.makeDistribution()
         with person_logged_in(distribution.owner):
             distribution.translationgroup = group
-        browser = self.getUserBrowser(user=group.owner)
         url = canonical_url(distribution, view_name='+configure-translations',
                             rootsite='translations')
+        browser = self.getUserBrowser(user=group.owner)
         # No "Unauthorized" exception is thrown.
         browser.open(url)
 
@@ -64,8 +64,8 @@ class TestDistributionSettingsView(TestCaseWithFactory):
         # launchpad.TranslationsAdmin privileges on it, meaning they
         # can access Distribution:+configure-translations page.
         distribution = self.factory.makeDistribution()
-        browser = self.getUserBrowser(user=distribution.owner)
         url = canonical_url(distribution, view_name='+configure-translations',
                             rootsite='translations')
+        browser = self.getUserBrowser(user=distribution.owner)
         # No "Unauthorized" exception is thrown.
         browser.open(url)
diff --git a/lib/lp/translations/stories/standalone/xx-sourcepackage-export.txt b/lib/lp/translations/stories/standalone/xx-sourcepackage-export.txt
index 3b662b7..ab6b119 100644
--- a/lib/lp/translations/stories/standalone/xx-sourcepackage-export.txt
+++ b/lib/lp/translations/stories/standalone/xx-sourcepackage-export.txt
@@ -192,10 +192,12 @@ their native file format.
     >>> from lp.translations.model.potemplate import POTemplateSubset
     >>> from lp.translations.interfaces.translationfileformat import (
     ...     TranslationFileFormat)
+    >>> login(ANONYMOUS)
     >>> hoary = ubuntu.getSeries('hoary')
     >>> hoary_subset = POTemplateSubset(distroseries=hoary)
     >>> an_evolution_template = hoary_subset.getPOTemplateByPath(
     ...     'po/evolution-2.2.pot')
+    >>> logout()
 
 If the file format for one of these templates were different from the
 other's, a warning would appear on the export request form that wasn't