def test_getCache_anonymous_obfuscated(self): request = LaunchpadTestRequest() branch = self.factory.makeBranch(name='user@domain') login_as(None) view = LaunchpadView(branch, request) self.assertIs(None, view.user) self.assertNotIn('user@domain', view.getCacheJSON())
def test_team_scope_in_team(self): request = LaunchpadTestRequest() scopes = webapp.ScopesFromRequest(request) member = self.factory.makePerson() team = self.factory.makeTeam(members=[member]) login_as(member, request) self.assertTrue(scopes.lookup('team:%s' % team.name))
def test_login_as_team(self): # login_as() logs in as a member of a team if it's given a team. team = self.factory.makeTeam() logout() login_as(team) person = self.getLoggedInPerson() self.assertTrue(person.inTeam(team))
def test_celebrity_logged_in_restores_person(self): # Once outside of the celebrity_logged_in context, the originally # logged-in person is re-logged in. person = self.factory.makePerson() login_as(person) with celebrity_logged_in('vcs_imports'): pass self.assertLoggedIn(person)
def test_person_logged_in_restores_person(self): # Once outside of the person_logged_in context, the originally # logged-in person is re-logged in. a = self.factory.makePerson() login_as(a) b = self.factory.makePerson() with person_logged_in(b): self.assertLoggedIn(b) self.assertLoggedIn(a)
def test_with_person_logged_in(self): person = self.factory.makePerson() @with_person_logged_in(person) def f(): return self.getLoggedInPerson() login_as(None) logged_in = f() self.assertEqual(person, logged_in)
def test_person_logged_in_restores_participation(self): # Once outside of the person_logged_in context, the original # participation (e.g., request) is used. This can be important for # yuixhr test fixtures, in particular. a = self.factory.makePerson() login_as(a) participation = getInteraction().participations[0] b = self.factory.makePerson() with person_logged_in(b): self.assertLoggedIn(b) self.assertIs(participation, getInteraction().participations[0])
def test_person_logged_in_restores_person_even_when_raises(self): # Once outside of the person_logged_in context, the originially # logged-in person is re-logged in. a = self.factory.makePerson() login_as(a) b = self.factory.makePerson() try: with person_logged_in(b): 1 / 0 except ZeroDivisionError: pass self.assertLoggedIn(a)
def test_with_celebrity_logged_in(self): # with_celebrity_logged_in decorates a function so that it runs with # the given person logged in. vcs_imports = getUtility(ILaunchpadCelebrities).vcs_imports @with_celebrity_logged_in('vcs_imports') def f(): return self.getLoggedInPerson() login_as(None) person = f() self.assertTrue(person.inTeam, vcs_imports)
def test_setChrootFromBuild_image_type(self): self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: "on"})) das = self.factory.makeDistroArchSeries() build = self.factory.makeLiveFSBuild() build_url = api_url(build) login_as(build.livefs.owner) lfa = self.factory.makeLibraryFileAlias( filename="livecd.ubuntu-base.lxd.tar.gz") build.addFile(lfa) user = das.distroseries.distribution.main_archive.owner webservice = launchpadlib_for("testing", user) ws_das = ws_object(webservice, das) ws_das.setChrootFromBuild(livefsbuild=build_url, filename="livecd.ubuntu-base.lxd.tar.gz", image_type="LXD image") self.assertIsNone(das.getChroot(image_type=BuildBaseImageType.CHROOT)) self.assertEqual(lfa, das.getChroot(image_type=BuildBaseImageType.LXD))
def test_setChrootFromBuild_random_user(self): # Random users are not allowed to set chroots from a livefs build. self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: "on"})) das = self.factory.makeDistroArchSeries() build = self.factory.makeLiveFSBuild() build_url = api_url(build) login_as(build.livefs.owner) build.addFile( self.factory.makeLibraryFileAlias( filename="livecd.ubuntu-base.rootfs.tar.gz")) user = self.factory.makePerson() webservice = launchpadlib_for("testing", user, version='devel') ws_das = ws_object(webservice, das) self.assertRaises(Unauthorized, ws_das.setChrootFromBuild, livefsbuild=build_url, filename="livecd.ubuntu-base.rootfs.tar.gz")
def test_no_email_sent_to_uncontactable_owner(self): # If the owner has no contact address, only the mirror admins are # notified. mirror = self.cdimage_mirror login_as(mirror.owner) # Deactivate the mirror owner to remove the contact address. mirror.owner.deactivate(comment="I hate mirror spam.") login_as(mirror.distribution.mirror_admin) # Clear out notifications about the new team member. transaction.commit() stub.test_emails = [] # Disabling the mirror results in a single notification to the # mirror admins. self.factory.makeMirrorProbeRecord(mirror) mirror.disable(notify_owner=True, log="It broke.") transaction.commit() self.failUnlessEqual(len(stub.test_emails), 1)
def test_no_email_sent_to_uncontactable_owner(self): # If the owner has no contact address, only the mirror admins are # notified. mirror = self.cdimage_mirror login_as(mirror.owner) # Deactivate the mirror owner to remove the contact address. mirror.owner.deactivate(comment="I hate mirror spam.") login_as(mirror.distribution.mirror_admin) # Clear out notifications about the new team member. transaction.commit() stub.test_emails = [] # Disabling the mirror results in a single notification to the # mirror admins. self.factory.makeMirrorProbeRecord(mirror) mirror.disable(notify_owner=True, log="It broke.") transaction.commit() self.assertEqual(len(stub.test_emails), 1)
def test_setChrootFromBuild(self): self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: "on"})) das = self.factory.makeDistroArchSeries() build = self.factory.makeLiveFSBuild() build_url = api_url(build) login_as(build.livefs.owner) lfas = [] for filename in ("livecd.ubuntu-base.rootfs.tar.gz", "livecd.ubuntu-base.manifest"): lfa = self.factory.makeLibraryFileAlias(filename=filename) lfas.append(lfa) build.addFile(lfa) user = das.distroseries.distribution.main_archive.owner webservice = launchpadlib_for("testing", user) ws_das = ws_object(webservice, das) ws_das.setChrootFromBuild(livefsbuild=build_url, filename="livecd.ubuntu-base.rootfs.tar.gz") self.assertEqual(lfas[0], das.getChroot())
def test_setChrootFromBuild_pocket(self): self.useFixture(FeatureFixture({LIVEFS_FEATURE_FLAG: "on"})) das = self.factory.makeDistroArchSeries() build = self.factory.makeLiveFSBuild() build_url = api_url(build) login_as(build.livefs.owner) lfa = self.factory.makeLibraryFileAlias( filename="livecd.ubuntu-base.rootfs.tar.gz") build.addFile(lfa) user = das.distroseries.distribution.main_archive.owner webservice = launchpadlib_for("testing", user) ws_das = ws_object(webservice, das) ws_das.setChrootFromBuild(livefsbuild=build_url, filename="livecd.ubuntu-base.rootfs.tar.gz", pocket="Updates") self.assertIsNone( das.getChroot(pocket=PackagePublishingPocket.RELEASE)) self.assertEqual(lfa, das.getChroot(pocket=PackagePublishingPocket.UPDATES))
def test_login_as_person(self): # login_as() logs in as a person if it's given a person. person = self.factory.makePerson() logout() login_as(person) self.assertLoggedIn(person)
def test_login_as_None(self): # login_as(None) logs in as the anonymous user. logout() login_as(None) self.assertLoggedIn(ANONYMOUS)