Beispiel #1
0
    def test_old_version_of_filter_moderated_objects_method(self):
        m1 = ModelWithSlugField(slug='test')
        m1.save()

        m2 = ModelWithSlugField(slug='test')
        self.assertRaises(IntegrityError, m2.save)

        self.assertEqual(ModeratedObject.objects.all().count(), 1)
Beispiel #2
0
    def test_old_version_of_filter_moderated_objects_method(self):
        m1 = ModelWithSlugField(slug='test')
        m1.save()

        m2 = ModelWithSlugField(slug='test')
        self.assertRaises(IntegrityError, m2.save)

        self.assertEqual(ModeratedObject.objects.all().count(), 1)
Beispiel #3
0
    def test_raise_integrity_error_model_registered_with_moderation(self):
        m1 = ModelWithSlugField(slug='test')
        m1.save()

        self.assertRaises(ObjectDoesNotExist, ModelWithSlugField.objects.get,
                          slug='test')

        m2 = ModelWithSlugField(slug='test')
        self.assertRaises(IntegrityError, m2.save)

        self.assertEqual(ModeratedObject.objects.all().count(), 1)
Beispiel #4
0
    def test_old_version_of_filter_moderated_objects_method(self):
        m1 = ModelWithSlugField(slug='test')
        m1.save()

        m2 = ModelWithSlugField(slug='test')
        if hasattr(transaction, 'atomic'):
            with transaction.atomic():
                self.assertRaises(IntegrityError, m2.save)
        else:
            self.assertRaises(IntegrityError, m2.save)

        self.assertEqual(ModeratedObject.objects.all().count(), 1)
Beispiel #5
0
    def test_raise_integrity_error_model_registered_with_moderation(self):
        m1 = ModelWithSlugField(slug='test')
        m1.save()

        self.assertRaises(ObjectDoesNotExist,
                          ModelWithSlugField.objects.get,
                          slug='test')

        m2 = ModelWithSlugField(slug='test')
        self.assertRaises(IntegrityError, m2.save)

        self.assertEqual(ModeratedObject.objects.all().count(), 1)
Beispiel #6
0
    def test_raise_integrity_error_model_registered_with_moderation(self):
        m1 = ModelWithSlugField(slug='test')
        m1.save()

        self.assertRaises(ObjectDoesNotExist, ModelWithSlugField.objects.get,
                          slug='test')

        m2 = ModelWithSlugField(slug='test')

        if hasattr(transaction, 'atomic'):
            with transaction.atomic():
                self.assertRaises(IntegrityError, m2.save)
        else:
            self.assertRaises(IntegrityError, m2.save)

        self.assertEqual(ModeratedObject.objects.all().count(), 1)
        def setUp(self):
            from tests.utils import setup_moderation

            rf = RequestFactory()
            rf.login(username='******', password='******')
            self.request = rf.get('/admin/moderation/')
            self.request.user = User.objects.get(username='******')
            self.admin = ModerationAdmin(UserProfile, site)

            models = [ModelWithSlugField2, ModelWithSlugField]
            self.moderation = setup_moderation(models)

            self.m1 = ModelWithSlugField(slug='test')
            self.m1.save()

            self.m2 = ModelWithSlugField2(slug='test')
            self.m2.save()
    class ContentTypeFilterSpecTextCase(TestCase):

        fixtures = ['test_users.json', 'test_moderation.json']

        def setUp(self):
            from tests.utils import setup_moderation

            rf = RequestFactory()
            rf.login(username='******', password='******')
            self.request = rf.get('/admin/moderation/')
            self.request.user = User.objects.get(username='******')
            self.admin = ModerationAdmin(UserProfile, site)

            models = [ModelWithSlugField2, ModelWithSlugField]
            self.moderation = setup_moderation(models)

            self.m1 = ModelWithSlugField(slug='test')
            self.m1.save()

            self.m2 = ModelWithSlugField2(slug='test')
            self.m2.save()

        def tearDown(self):
            teardown_moderation()

        def test_content_types_and_its_order(self):
            f = ModeratedObject._meta.get_field('content_type')
            filter_spec = ContentTypeFilterSpec(f, self.request, {},
                                                ModeratedObject, self.admin)

            self.assertEqual(
                [x[1] for x in filter_spec.lookup_choices],
                ['Model with slug field',
                 'Model with slug field2'])

            self.assertEqual(str(filter_spec.content_types),
                             "[<ContentType: model with slug field>, "
                             "<ContentType: model with slug field2>]")
    class ContentTypeFilterSpecTextCase(TestCase):

        fixtures = ['test_users.json', 'test_moderation.json']

        def setUp(self):
            from tests.utils import setup_moderation

            rf = RequestFactory()
            rf.login(username='******', password='******')
            self.request = rf.get('/admin/moderation/')
            self.request.user = User.objects.get(username='******')
            self.admin = ModerationAdmin(UserProfile, site)

            models = [ModelWithSlugField2, ModelWithSlugField]
            self.moderation = setup_moderation(models)

            self.m1 = ModelWithSlugField(slug='test')
            self.m1.save()

            self.m2 = ModelWithSlugField2(slug='test')
            self.m2.save()

        def tearDown(self):
            teardown_moderation()

        def test_content_types_and_its_order(self):
            f = ModeratedObject._meta.get_field('content_type')
            filter_spec = ContentTypeFilterSpec(f, self.request, {},
                                                ModeratedObject, self.admin)

            self.assertEqual(
                [x[1] for x in filter_spec.lookup_choices],
                ['Model with slug field',
                 'Model with slug field2'])

            self.assertEqual(str(filter_spec.content_types),
                             "[<ContentType: model with slug field>, "
                             "<ContentType: model with slug field2>]")
        def setUp(self):
            from tests.utils import setup_moderation

            rf = RequestFactory()
            rf.login(username='******', password='******')
            self.request = rf.get('/admin/moderation/')
            self.request.user = User.objects.get(username='******')
            self.admin = ModerationAdmin(UserProfile, site)

            models = [ModelWithSlugField2, ModelWithSlugField]
            self.moderation = setup_moderation(models)

            self.m1 = ModelWithSlugField(slug='test')
            self.m1.save()

            self.m2 = ModelWithSlugField2(slug='test')
            self.m2.save()