Exemplo n.º 1
0
class ModeratedObjectAdminTestCase(TestCase):
    fixtures = ["test_users.json"]
    urls = "moderation.tests.urls.default"

    def setUp(self):
        rf = RequestFactory()
        rf.login(username="******", password="******")
        self.request = rf.get("/admin/moderation/")
        self.request.user = User.objects.get(username="******")
        self.admin = ModeratedObjectAdmin(ModeratedObject, site)

        for user in User.objects.all():
            ModeratedObject(content_object=user).save()

    def test_get_actions_should_not_return_delete_selected(self):
        actions = self.admin.get_actions(self.request)
        self.failIfEqual("delete_selected" in actions, True)

    def test_content_object_returns_deserialized_object(self):
        user = User.objects.get(username="******")
        moderated_object = ModeratedObject(content_object=user)
        moderated_object.save()
        content_object = self.admin.content_object(moderated_object)
        self.assertEqual(content_object, "admin")

    def test_get_moderated_object_form(self):
        form = self.admin.get_moderated_object_form(UserProfile)
        self.assertEqual(repr(form), "<class 'moderation.admin.ModeratedObjectForm'>")
Exemplo n.º 2
0
class ModeratedObjectAdminTestCase(TestCase):
    fixtures = ['test_users.json']

    def setUp(self):
        rf = RequestFactory()
        rf.login(username='******', password='******')
        self.request = rf.get('/admin/moderation/')
        self.request.user = User.objects.get(username='******')
        self.admin = ModeratedObjectAdmin(ModeratedObject, site)

        for user in User.objects.all():
            ModeratedObject(content_object=user).save()

    def test_get_actions_should_not_return_delete_selected(self):
        actions = self.admin.get_actions(self.request)
        self.failIfEqual('delete_selected' in actions, True)

    def test_content_object_returns_deserialized_object(self):
        user = User.objects.get(username='******')
        moderated_object = ModeratedObject(content_object=user)
        moderated_object.save()
        content_object = self.admin.content_object(moderated_object)
        self.assertEqual(content_object, "admin")

    def test_get_moderated_object_form(self):
        form = self.admin.get_moderated_object_form(UserProfile)
        self.assertIn('ModeratedObjectForm', repr(form))
class ModeratedObjectAdminTestCase(TestCase):
    fixtures = ['test_users.json']

    def setUp(self):
        rf = RequestFactory()
        rf.login(username='******', password='******')
        self.request = rf.get('/admin/moderation/')
        self.request.user = User.objects.get(username='******')
        self.admin = ModeratedObjectAdmin(ModeratedObject, site)

        for user in User.objects.all():
            ModeratedObject(content_object=user).save()

    def test_get_actions_should_not_return_delete_selected(self):
        actions = self.admin.get_actions(self.request)
        self.failIfEqual('delete_selected' in actions, True)

    def test_content_object_returns_deserialized_object(self):
        user = User.objects.get(username='******')
        moderated_object = ModeratedObject(content_object=user)
        moderated_object.save()
        content_object = self.admin.content_object(moderated_object)
        self.assertEqual(content_object, "admin")

    def test_get_moderated_object_form(self):
        form = self.admin.get_moderated_object_form(UserProfile)
        self.assertIn('ModeratedObjectForm', repr(form))
Exemplo n.º 4
0
    def setUp(self):
        rf = RequestFactory()
        rf.login(username='******', password='******')
        self.request = rf.get('/admin/moderation/')
        self.request.user = User.objects.get(username='******')
        self.admin = ModeratedObjectAdmin(ModeratedObject, site)

        for user in User.objects.all():
            ModeratedObject(content_object=user).save()
Exemplo n.º 5
0
    def setUp(self):
        rf = RequestFactory()
        rf.login(username="******", password="******")
        self.request = rf.get("/admin/moderation/")
        self.request.user = User.objects.get(username="******")
        self.admin = ModeratedObjectAdmin(ModeratedObject, site)

        for user in User.objects.all():
            ModeratedObject(content_object=user).save()
Exemplo n.º 6
0
 def setUp(self):
     rf = RequestFactory()
     rf.login(username='******', password='******')
     self.request = rf.get('/admin/moderation/')
     self.request.user = User.objects.get(username='******')
     self.admin = ModeratedObjectAdmin(ModeratedObject, site)
     
     for user in User.objects.all():
         ModeratedObject(content_object=user).save()
         
     self.moderated_objects = ModeratedObject.objects.all()
Exemplo n.º 7
0
class AdminActionsTestCase(TestCase):
    fixtures = ['test_users.json']
    urls = 'moderation.tests.test_urls'

    def setUp(self):
        rf = RequestFactory()
        rf.login(username='******', password='******')
        self.request = rf.get('/admin/moderation/')
        self.request.user = User.objects.get(username='******')
        self.admin = ModeratedObjectAdmin(ModeratedObject, site)

        self.moderation = setup_moderation([User])

        for user in User.objects.all():
            ModeratedObject(content_object=user).save()

        self.moderated_objects = ModeratedObject.objects.all()

    def tearDown(self):
        teardown_moderation()

    def test_queryset_should_return_only_moderation_ready_objects(self):
        qs = self.admin.queryset(self.request)
        qs = qs.filter(moderation_state=MODERATION_DRAFT_STATE)
        self.assertEqual(list(qs), [])

    def test_approve_objects(self):
        approve_objects(self.admin, self.request, self.moderated_objects)

        for obj in ModeratedObject.objects.all():
            self.assertEqual(obj.moderation_status,
                             MODERATION_STATUS_APPROVED)

    def test_reject_objects(self):
        qs = ModeratedObject.objects.all()

        reject_objects(self.admin, self.request, qs)

        for obj in ModeratedObject.objects.all():
            self.assertEqual(obj.moderation_status,
                             MODERATION_STATUS_REJECTED)

    def test_set_objects_as_pending(self):
        for obj in self.moderated_objects:
            obj.approve(moderated_by=self.request.user)

        set_objects_as_pending(self.admin, self.request,
                               self.moderated_objects)

        for obj in ModeratedObject.objects.all():
            self.assertEqual(obj.moderation_status,
                             MODERATION_STATUS_PENDING)