Example #1
0
    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()
        tools.assert_equals(1, License.objects.get(pk=l.pk).applications)
Example #2
0
    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()

        tools.assert_equals(2, License.objects.get(pk=l.pk).applications)
Example #3
0
    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()

        tools.assert_equals(1, License.objects.get(pk=l.pk).applications)
Example #4
0
    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()

        tools.assert_equals(2, License.objects.get(pk=l.pk).applications)
Example #5
0
    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()

        tools.assert_equals(1, License.objects.get(pk=l.pk).applications)
Example #6
0
    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()
        tools.assert_equals([self.category.pk], License.objects.unapplicable_for_model(Category))

        qset = Category.objects.order_by('pk')
        tools.assert_equals(list(qset.exclude(pk=self.category.pk)), list(License.objects.filter_queryset(qset)))
Example #7
0
    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')
        tools.assert_equals([], License.objects.unapplicable_for_model(Category))
        tools.assert_equals(list(qset), list(License.objects.filter_queryset(qset)))
Example #8
0
 def test_license_no_uses_still_doesnt_limit(self):
     l = License()
     l.target = self.category
     l.max_applications = 2
     l.save()
     tools.assert_equals([], License.objects.unapplicable_for_model(Category))