def match_does_not_verify(self):

        class BadlyImplementedClass:
            implements(ITestInterface)

        obj = BadlyImplementedClass()
        matcher = Provides(ITestInterface)
        return obj, matcher.match(obj)
Example #2
0
    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))
Example #5
0
 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])
Example #6
0
 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)
Example #7
0
 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))),
         ]))
Example #8
0
 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))),
         ]))
Example #9
0
 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))
Example #12
0
 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))
Example #15
0
 def test_makeDistroSeries_returns_IDistroSeries(self):
     distroseries = self.factory.makeDistroSeries()
     self.assertThat(removeSecurityProxy(distroseries),
                     Provides(IDistroSeries))
Example #16
0
 def test_makeDistribution_returns_IDistribution(self):
     distribution = self.factory.makeDistribution()
     self.assertThat(removeSecurityProxy(distribution),
                     Provides(IDistribution))
Example #17
0
 def test_provides_interface(self):
     self.assertThat(self.factory.makeAccessPolicyGrant(),
                     Provides(IAccessPolicyGrant))
Example #18
0
 def test_makeSourcePackagePublishingHistory_returns_ISPPH(self):
     spph = self.factory.makeSourcePackagePublishingHistory()
     self.assertThat(removeSecurityProxy(spph),
                     Provides(ISourcePackagePublishingHistory))
Example #19
0
 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)
Example #20
0
 def test_provides_interface(self):
     self.assertThat(self.factory.makeAccessArtifact(),
                     Provides(IAccessArtifact))
Example #21
0
 def match_does_not_provide(self):
     obj = object()
     matcher = Provides(ITestInterface)
     return obj, matcher.match(obj)
Example #22
0
 def test_matches(self):
     matcher = Provides(ITestInterface)
     self.assertEqual(None, matcher.match(Implementor()))
Example #23
0
 def test_str(self):
     matcher = Provides(ITestInterface)
     self.assertEqual("provides %r." % ITestInterface, str(matcher))
Example #24
0
 def test_makeBinaryPackageBuild_returns_IBinaryPackageBuild(self):
     bpb = self.factory.makeBinaryPackageBuild()
     self.assertThat(removeSecurityProxy(bpb),
                     Provides(IBinaryPackageBuild))
Example #25
0
 def test_storm_creation_event_adapter(self):
     event = ILongPollEvent(FakeStormClass)
     self.assertThat(event, Provides(ILongPollEvent))
     self.assertEqual("longpoll.event.faketable", event.event_key)
Example #26
0
 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))
Example #28
0
 def test_matches(self):
     matcher = Provides(ITestInterface)
     self.assertEqual(None, matcher.match(Implementor()))
Example #29
0
 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))
Example #30
0
 def test_makeBinaryPackagePublishingHistory_returns_IBPPH(self):
     bpph = self.factory.makeBinaryPackagePublishingHistory()
     self.assertThat(removeSecurityProxy(bpph),
                     Provides(IBinaryPackagePublishingHistory))
Example #31
0
 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])
Example #32
0
 def match_does_not_provide(self):
     obj = object()
     matcher = Provides(ITestInterface)
     return obj, matcher.match(obj)
Example #33
0
 def test_implements(self):
     pillar = self.factory.makeProduct()
     person = self.factory.makePerson()
     pillar_person = PillarPerson(pillar, person)
     self.assertThat(pillar_person, Provides(IPillarPerson))