def test_deactivateCommercialFeatures_open_source(self): # When the project is open source, the product's commercial features # are deactivated and the commercial subscription is deleted. product, reviewer = self.make_notification_data(licenses=[License.MIT]) public_branch = self.factory.makeBranch( owner=product.owner, product=product) private_branch = self.factory.makeBranch( owner=product.owner, product=product, information_type=InformationType.USERDATA) with person_logged_in(product.owner): public_series = product.development_focus public_series.branch = public_branch private_series = product.newSeries( product.owner, 'special', 'testing', branch=private_branch) # Verify that branchless series do not raise an error. product.newSeries(product.owner, 'unused', 'no branch') self.expire_commercial_subscription(product) job = CommercialExpiredJob.create(product, reviewer) job._deactivateCommercialFeatures() clear_property_cache(product) self.assertTrue(product.active) self.assertEqual( BranchSharingPolicy.FORBIDDEN, product.branch_sharing_policy) self.assertEqual( BugSharingPolicy.FORBIDDEN, product.bug_sharing_policy) self.assertEqual(public_branch, public_series.branch) self.assertIs(None, private_series.branch) self.assertIs(None, product.commercial_subscription)
def setRecipe(self, builder_recipe): """Convert the BaseRecipeBranch `builder_recipe` to the db form.""" clear_property_cache(self) if builder_recipe.format > MAX_RECIPE_FORMAT: raise TooNewRecipeFormat(builder_recipe.format, MAX_RECIPE_FORMAT) branch_map = self._scanInstructions(builder_recipe) # If this object hasn't been added to a store yet, there can't be any # instructions linking to us yet. if Store.of(self) is not None: self.instructions.find().remove() branch_lookup = getUtility(IBranchLookup) base_branch = branch_lookup.getByUrl(builder_recipe.url) if base_branch is None: raise NoSuchBranch(builder_recipe.url) if base_branch.private: raise PrivateBranchRecipe(base_branch) if builder_recipe.revspec is not None: self.revspec = unicode(builder_recipe.revspec) else: self.revspec = None self._recordInstructions( builder_recipe, parent_insn=None, branch_map=branch_map) self.base_branch = base_branch if builder_recipe.deb_version is None: self.deb_version_template = None else: self.deb_version_template = unicode(builder_recipe.deb_version) self.recipe_format = unicode(builder_recipe.format)
def test_eta(self): # SnapBuild.eta returns a non-None value when it should, or None # when there's no start time. self.build.queueBuild() self.assertIsNone(self.build.eta) self.factory.makeBuilder(processors=[self.build.processor]) clear_property_cache(self.build) self.assertIsNotNone(self.build.eta)
def test_getByPath(self): branch = self.factory.makeProductBranch() self.assertEqual(branch, BranchSet().getByPath(branch.shortened_path)) product = removeSecurityProxy(branch.product) ICanHasLinkedBranch(product).setBranch(branch) clear_property_cache(branch) self.assertEqual(product.name, branch.shortened_path) self.assertEqual(branch, BranchSet().getByPath(branch.shortened_path)) self.assertIsNone(BranchSet().getByPath('nonexistent'))
def test_estimate(self): # SnapBuild.estimate returns True until the job is completed. self.build.queueBuild() self.factory.makeBuilder(processors=[self.build.processor]) self.build.updateStatus(BuildStatus.BUILDING) self.assertTrue(self.build.estimate) self.build.updateStatus(BuildStatus.FULLYBUILT) clear_property_cache(self.build) self.assertFalse(self.build.estimate)
def test_deactivateCommercialFeatures_proprietary(self): # When the project is proprietary, the product is deactivated. product, reviewer = self.make_notification_data( licenses=[License.OTHER_PROPRIETARY]) self.expire_commercial_subscription(product) job = CommercialExpiredJob.create(product, reviewer) job._deactivateCommercialFeatures() clear_property_cache(product) self.assertIs(False, product.active) self.assertIsNot(None, product.commercial_subscription)
def test_delete(self): # Inactive commercial subscriptions can be deleted. product = self.factory.makeProduct( licenses=[License.OTHER_PROPRIETARY]) cs = product.commercial_subscription date_expires = cs.date_expires - timedelta(days=31) removeSecurityProxy(cs).date_expires = date_expires self.assertIs(False, cs.is_active) cs.delete() clear_property_cache(product) self.assertIs(None, product.commercial_subscription)
def update(self, manual=False): """See `IDistroSeriesDifference`.""" # Updating is expected to be a heavy operation (not called # during requests). We clear the cache beforehand - even though # it is not currently necessary - so that in the future it # won't cause a hard-to find bug if a script ever creates a # difference, copies/publishes a new version and then calls # update() (like the tests for this method do). clear_property_cache(self) self._updateType() updated = self._updateVersionsAndStatus(manual=manual) if updated is True: self._setPackageDiffs() return updated
def setRecipe(self, builder_recipe, recipe_branch_type): """Convert the BaseRecipeBranch `builder_recipe` to the db form.""" clear_property_cache(self) if builder_recipe.format > MAX_RECIPE_FORMAT: raise TooNewRecipeFormat(builder_recipe.format, MAX_RECIPE_FORMAT) if recipe_branch_type == RecipeBranchType.BZR: base = getUtility(IBranchLookup).getByUrl(builder_recipe.url) if base is None: raise NoSuchBranch(builder_recipe.url) elif base.private: raise PrivateBranchRecipe(base) elif recipe_branch_type == RecipeBranchType.GIT: base = getUtility(IGitLookup).getByUrl(builder_recipe.url) if base is None: raise NoSuchGitRepository(builder_recipe.url) elif base.private: raise PrivateGitRepositoryRecipe(base) else: raise AssertionError('Unknown recipe_branch_type: %r' % recipe_branch_type) branch_map = self._scanInstructions(base, builder_recipe) # If this object hasn't been added to a store yet, there can't be any # instructions linking to us yet. if Store.of(self) is not None: self.instructions.find().remove() if builder_recipe.revspec is not None: self.revspec = unicode(builder_recipe.revspec) else: self.revspec = None self._recordInstructions(builder_recipe, parent_insn=None, branch_map=branch_map) self.base = base if builder_recipe.deb_version is None: self.deb_version_template = None else: self.deb_version_template = unicode(builder_recipe.deb_version) self.recipe_format = unicode(builder_recipe.format)
def test_show_spam_controls_permissions(self): # Admins, registry experts, and the author of the comment itself can # hide comments, but other people can't. author = self.factory.makePerson() comment = self.factory.makeCodeReviewComment(sender=author) display_comment = CodeReviewDisplayComment(comment) with person_logged_in(author): self.assertTrue(display_comment.show_spam_controls) clear_property_cache(display_comment) with person_logged_in(self.factory.makePerson()): self.assertFalse(display_comment.show_spam_controls) clear_property_cache(display_comment) with celebrity_logged_in('registry_experts'): self.assertTrue(display_comment.show_spam_controls) clear_property_cache(display_comment) with admin_logged_in(): self.assertTrue(display_comment.show_spam_controls)
def __storm_invalidated__(self): """Flush cached properties.""" clear_property_cache(self)
def __storm_invalidated__(self): """Flush cached properties.""" # XXX: RobertCollins 2010-08-16 bug=622648: Note this is not directly # tested, but the entire test suite blows up awesomely if it's broken. # It's entirely unclear where tests for this should be. clear_property_cache(self)