def test_license_no_uses_still_doesnt_limit(self): l = License() l.target = self.category l.max_applications = 2 l.save() self.assert_equals([], License.objects.unapplicable_for_model(Category))
def test_use_of_licensed_object_raises_the_applications_counter(self): l = License(max_applications=2) l.target = self.category l.save() text = 'some-text {%% box inline for core.category with pk %s %%}{%% endbox %%}' % self.category.pk self.publishable.description = self.field.clean(text) self.publishable.save() self.assert_equals(1, License.objects.get(pk=l.pk).applications)
def test_license_with_over_max_number_of_uses_does_limit(self): l = License() l.target = self.category l.max_applications = 2 l.applications = 20 l.save() self.assert_equals([self.category.pk], License.objects.unapplicable_for_model(Category)) qset = Category.objects.order_by('pk') self.assert_equals(list(qset.exclude(pk=self.category.pk)), list(License.objects.filter_queryset(qset)))
def test_license_with_allowed_number_of_uses_still_doesnt_limit(self): l = License() l.target = self.category l.max_applications = 2 l.applications = 1 l.save() qset = Category.objects.order_by('pk') self.assert_equals([], License.objects.unapplicable_for_model(Category)) self.assert_equals(list(qset), list(License.objects.filter_queryset(qset)))
def test_no_longer_using_licensed_object_lowers_its_applications(self): l = License(max_applications=2, applications=2) l.target = self.category l.save() dep = Dependency() dep.target = self.category dep.dependent = self.publishable dep.save() text = 'some-text, no box' self.publishable.description = self.field.clean(text) self.publishable.save() self.assert_equals(1, License.objects.get(pk=l.pk).applications)
def test_still_using_licensed_object_doesnt_change_its_applications(self): l = License(max_applications=2, applications=2) l.target = self.category l.save() dep = Dependency() dep.target = self.category dep.dependent = self.publishable dep.save() text = 'some-text {%% box inline for core.category with pk %s %%}{%% endbox %%}' % self.category.pk self.publishable.description = self.field.clean(text) self.publishable.save() self.assert_equals(2, License.objects.get(pk=l.pk).applications)
def test_two_uses_in_two_fields_on_one_object_count_as_one(self): l = License(max_applications=2, applications=1) l.target = self.category l.save() text = 'some-text {%% box inline for core.category with pk %s %%}{%% endbox %%}' % self.category.pk self.publishable.description = self.field.clean(text) field2 = fields.NewmanRichTextField( instance=self.publishable, model=self.publishable.__class__, field_name = "title", ) self.publishable.title = field2.clean(text) self.publishable.save() self.assert_equals(2, License.objects.get(pk=l.pk).applications)
def test_two_uses_in_two_fields_on_one_object_count_as_one(self): l = License(max_applications=2, applications=1) l.target = self.category l.save() text = 'some-text {%% box inline for core.category with pk %s %%}{%% endbox %%}' % self.category.pk self.publishable.description = self.field.clean(text) field2 = fields.NewmanRichTextField( instance=self.publishable, model=self.publishable.__class__, field_name="title", ) self.publishable.title = field2.clean(text) self.publishable.save() self.assert_equals(2, License.objects.get(pk=l.pk).applications)
def test_object_still_used_in_one_field_doesnt_affect_applications(self): l = License(max_applications=2, applications=1) l.target = self.category l.save() dep = Dependency() dep.target = self.category dep.dependent = self.publishable dep.save() text = 'some-text {%% box inline for core.category with pk %s %%}{%% endbox %%}' % self.category.pk self.publishable.description = self.field.clean(text) field2 = fields.NewmanRichTextField( instance=self.publishable, model=self.publishable.__class__, field_name = "title", ) self.publishable.title = field2.clean('no box here') self.publishable.save() self.assert_equals(1, License.objects.get(pk=l.pk).applications)
def test_object_still_used_in_one_field_doesnt_affect_applications(self): l = License(max_applications=2, applications=1) l.target = self.category l.save() dep = Dependency() dep.target = self.category dep.dependent = self.publishable dep.save() text = 'some-text {%% box inline for core.category with pk %s %%}{%% endbox %%}' % self.category.pk self.publishable.description = self.field.clean(text) field2 = fields.NewmanRichTextField( instance=self.publishable, model=self.publishable.__class__, field_name="title", ) self.publishable.title = field2.clean('no box here') self.publishable.save() self.assert_equals(1, License.objects.get(pk=l.pk).applications)