def match_does_not_verify(self): class BadlyImplementedClass: implements(ITestInterface) obj = BadlyImplementedClass() matcher = Provides(ITestInterface) return obj, matcher.match(obj)
def match_does_not_verify(self): @implementer(ITestInterface) class BadlyImplementedClass: pass obj = BadlyImplementedClass() matcher = Provides(ITestInterface) return obj, matcher.match(obj)
def test_product_series(self): target = self.factory.makeProductSeries(owner=self.person) helper = IStructuralSubscriptionTargetHelper(target) self.assertThat(helper, Provides(IStructuralSubscriptionTargetHelper)) self.assertEqual("project series", helper.target_type_display) self.assertEqual(target, helper.target) self.assertEqual(target.product, helper.target_parent) self.assertThat(helper.target_parent, Provides(IStructuralSubscriptionTarget)) self.assertEqual(target.product, helper.pillar) self.assertEqual({"productseries": target}, helper.target_arguments) self.assertEqual(u"StructuralSubscription.productseries = ?", compile_storm(helper.join))
def test_milestone(self): target = self.factory.makeMilestone() helper = IStructuralSubscriptionTargetHelper(target) self.assertThat(helper, Provides(IStructuralSubscriptionTargetHelper)) self.assertEqual("milestone", helper.target_type_display) self.assertEqual(target, helper.target) self.assertEqual(target.target, helper.target_parent) self.assertThat(helper.target_parent, Provides(IStructuralSubscriptionTarget)) self.assertEqual(target.target, helper.pillar) self.assertEqual({"milestone": target}, helper.target_arguments) self.assertEqual(u"StructuralSubscription.milestone = ?", compile_storm(helper.join))
def test_create(self): wanted = [ (self.factory.makeProduct(), InformationType.PROPRIETARY), (self.factory.makeDistribution(), InformationType.PUBLICSECURITY), ] policies = getUtility(IAccessPolicySource).create(wanted) self.assertThat(policies, AllMatch(Provides(IAccessPolicy))) self.assertContentEqual(wanted, [(policy.pillar, policy.type) for policy in policies])
def test_getTerm(self): # A term can be obtained from a given value. difference = self.factory.makeDistroSeriesDifference() vocabulary = DistroSeriesDifferencesVocabulary( difference.derived_series) term = vocabulary.getTerm(difference) self.assertThat(term, Provides(ITokenizedTerm)) self.assertEqual(difference, term.value) self.assertEqual(str(difference.id), term.token)
def test_different_user(self): obj = Thing(0) user = self.factory.makePerson() with EventRecorder() as recorder: with notify_modified(obj, ["attr"], user=user): obj.attr = 1 self.assertThat( recorder.events, MatchesListwise([ MatchesAll( Provides(IObjectModifiedEvent), MatchesStructure(object=MatchesStructure(attr=Equals(1)), object_before_modification=MatchesAll( Provides(IThing), MatchesStructure(attr=Equals(0))), edited_fields=Equals(["attr"]), user=Equals(user))), ]))
def test_generates_notification(self): obj = Thing(0) with EventRecorder() as recorder: with notify_modified(obj, ["attr"]): obj.attr = 1 self.assertThat( recorder.events, MatchesListwise([ MatchesAll( Provides(IObjectModifiedEvent), MatchesStructure( object=MatchesStructure(attr=Equals(1)), object_before_modification=MatchesAll( Provides(IThing), MatchesStructure(attr=Equals(0))), edited_fields=Equals(["attr"]), user=Provides(IUnauthenticatedPrincipal))), ]))
def assertCollectionContents( self, collection, personal=0, as_team_member=0, as_team_admin=0): # Make sure that the collection has the values we expect. self.assertEqual(collection.count, personal + as_team_member + as_team_admin) for name, expected in (('personal', personal), ('as_team_member', as_team_member), ('as_team_admin', as_team_admin)): actual = getattr(collection, name) self.assertEqual(expected, len(actual)) if IVirtualSubscriptionInfoCollection.providedBy(collection): expected_interface = IVirtualSubscriptionInfo else: self.assertThat(collection, Provides(IRealSubscriptionInfoCollection)) expected_interface = IRealSubscriptionInfo for info in actual: self.assertThat(info, Provides(expected_interface))
def test_distribution_source_package(self): target = self.factory.makeDistributionSourcePackage() helper = IStructuralSubscriptionTargetHelper(target) self.assertThat(helper, Provides(IStructuralSubscriptionTargetHelper)) self.assertEqual("package", helper.target_type_display) self.assertEqual(target, helper.target) self.assertEqual(target.distribution, helper.target_parent) self.assertThat(helper.target_parent, Provides(IStructuralSubscriptionTarget)) self.assertEqual(target.distribution, helper.pillar) self.assertEqual( { "distribution": target.distribution, "sourcepackagename": target.sourcepackagename }, helper.target_arguments) self.assertEqual( u"StructuralSubscription.distribution = ? AND " u"StructuralSubscription.sourcepackagename = ?", compile_storm(helper.join))
def test_distribution_series(self): target = self.factory.makeDistroSeries() helper = IStructuralSubscriptionTargetHelper(target) self.assertThat(helper, Provides(IStructuralSubscriptionTargetHelper)) self.assertEqual("distribution series", helper.target_type_display) self.assertEqual(target, helper.target) self.assertEqual(target.distribution, helper.target_parent) self.assertEqual({"distroseries": target}, helper.target_arguments) self.assertEqual(target.distribution, helper.pillar) self.assertEqual(u"StructuralSubscription.distroseries = ?", compile_storm(helper.join))
def test_mutate_edited_fields_within_block(self): obj = Thing(0) with EventRecorder() as recorder: edited_fields = set() with notify_modified(obj, edited_fields): obj.attr = 1 edited_fields.add("attr") self.assertThat( recorder.events, MatchesListwise([ MatchesAll( Provides(IObjectModifiedEvent), MatchesStructure( object=MatchesStructure(attr=Equals(1)), object_before_modification=MatchesAll( Provides(IThing), MatchesStructure(attr=Equals(0))), edited_fields=Equals(["attr"]), user=Provides(IUnauthenticatedPrincipal))), ]))
def test_product_in_group(self): project = self.factory.makeProject(owner=self.person) target = self.factory.makeProduct(project=project) helper = IStructuralSubscriptionTargetHelper(target) self.assertThat(helper, Provides(IStructuralSubscriptionTargetHelper)) self.assertEqual("project", helper.target_type_display) self.assertEqual(target, helper.target) self.assertEqual(project, helper.target_parent) self.assertEqual(target, helper.pillar) self.assertEqual({"product": target}, helper.target_arguments) self.assertEqual( u"StructuralSubscription.product = ? OR " "StructuralSubscription.project = ?", compile_storm(helper.join))
def test_distribution(self): target = self.factory.makeDistribution(owner=self.person) helper = IStructuralSubscriptionTargetHelper(target) self.assertThat(helper, Provides(IStructuralSubscriptionTargetHelper)) self.assertEqual(target, helper.target) self.assertEqual("distribution", helper.target_type_display) self.assertEqual(None, helper.target_parent) self.assertEqual(target, helper.pillar) self.assertEqual({ "distribution": target, "sourcepackagename": None }, helper.target_arguments) self.assertEqual( u"StructuralSubscription.distribution = ? AND " u"StructuralSubscription.sourcepackagename IS NULL", compile_storm(helper.join))
def test_makeDistroSeries_returns_IDistroSeries(self): distroseries = self.factory.makeDistroSeries() self.assertThat(removeSecurityProxy(distroseries), Provides(IDistroSeries))
def test_makeDistribution_returns_IDistribution(self): distribution = self.factory.makeDistribution() self.assertThat(removeSecurityProxy(distribution), Provides(IDistribution))
def test_provides_interface(self): self.assertThat(self.factory.makeAccessPolicyGrant(), Provides(IAccessPolicyGrant))
def test_makeSourcePackagePublishingHistory_returns_ISPPH(self): spph = self.factory.makeSourcePackagePublishingHistory() self.assertThat(removeSecurityProxy(spph), Provides(ISourcePackagePublishingHistory))
def test_storm_event_adapter(self): storm_object = FakeStormClass() storm_object.id = 1234 event = ILongPollEvent(storm_object) self.assertThat(event, Provides(ILongPollEvent)) self.assertEqual("longpoll.event.faketable.1234", event.event_key)
def test_provides_interface(self): self.assertThat(self.factory.makeAccessArtifact(), Provides(IAccessArtifact))
def match_does_not_provide(self): obj = object() matcher = Provides(ITestInterface) return obj, matcher.match(obj)
def test_matches(self): matcher = Provides(ITestInterface) self.assertEqual(None, matcher.match(Implementor()))
def test_str(self): matcher = Provides(ITestInterface) self.assertEqual("provides %r." % ITestInterface, str(matcher))
def test_makeBinaryPackageBuild_returns_IBinaryPackageBuild(self): bpb = self.factory.makeBinaryPackageBuild() self.assertThat(removeSecurityProxy(bpb), Provides(IBinaryPackageBuild))
def test_storm_creation_event_adapter(self): event = ILongPollEvent(FakeStormClass) self.assertThat(event, Provides(ILongPollEvent)) self.assertEqual("longpoll.event.faketable", event.event_key)
def testInterface(self): """Check whether the object follows the interface.""" self.assertThat(TranslationImporter(), Provides(ITranslationImporter))
def test_implements_interface(self): self.assertThat( getUtility(IDistributionSet), Provides(IDistributionSet))
def test_makeSPPHForBPPH_returns_ISPPH(self): bpph = self.factory.makeBinaryPackagePublishingHistory() spph = self.factory.makeSPPHForBPPH(bpph) self.assertThat(spph, IsProxied()) self.assertThat(removeSecurityProxy(spph), Provides(ISourcePackagePublishingHistory))
def test_makeBinaryPackagePublishingHistory_returns_IBPPH(self): bpph = self.factory.makeBinaryPackagePublishingHistory() self.assertThat(removeSecurityProxy(bpph), Provides(IBinaryPackagePublishingHistory))
def test_createForTeams(self): # Test createForTeams. teams = [self.factory.makeTeam()] policies = getUtility(IAccessPolicySource).createForTeams(teams) self.assertThat(policies, AllMatch(Provides(IAccessPolicy))) self.assertContentEqual(teams, [policy.person for policy in policies])
def test_implements(self): pillar = self.factory.makeProduct() person = self.factory.makePerson() pillar_person = PillarPerson(pillar, person) self.assertThat(pillar_person, Provides(IPillarPerson))