Пример #1
0
    def test_review_queue(self):
        tracker, commit1 = make_commit(self.widgy_site, vt_class=ReviewedVersionTracker)

        p = Permission.objects.get(codename='change_versioncommit')
        user = User.objects.create()
        user.user_permissions.add(p)
        user.save()

        request_factory = RequestFactory()

        tracker = refetch(tracker)
        self.assertFalse(tracker.get_published_node(request_factory.get('/')))

        commit1.approve(user)

        tracker = refetch(tracker)
        self.assertEqual(tracker.get_published_node(request_factory.get('/')),
                         commit1.root_node)

        commit2 = tracker.commit(publish_at=timezone.now())
        tracker = refetch(tracker)
        self.assertEqual(tracker.get_published_node(request_factory.get('/')),
                         commit1.root_node)

        commit2.approve(user)
        tracker = refetch(tracker)
        self.assertEqual(tracker.get_published_node(request_factory.get('/')),
                         commit2.root_node)
Пример #2
0
    def test_undo_approvals_view(self):
        tracker, commit = make_commit(self.widgy_site)
        tracker2, commit2 = make_commit(self.widgy_site)
        url = self.widgy_site.reverse(self.widgy_site.undo_approvals_view)
        commit.approve(self.user)
        commit2.approve(self.user)

        def doit():
            return self.client.post(url, {
                'actions': json.dumps([commit.pk]),
                'referer': '/referer/',
            })

        with self.as_staffuser() as user:
            resp = doit()

        self.assertEqual(resp.status_code, 403)
        self.assertTrue(refetch(commit).is_approved)
        self.assertTrue(refetch(commit2).is_approved)

        with self.as_staffuser() as user:
            with self.with_permission(user, 'change', ReviewedVersionCommit):
                resp = doit()

        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp['Location'], 'http://testserver/referer/')
        self.assertFalse(refetch(commit).is_approved)
        self.assertTrue(refetch(commit2).is_approved)
Пример #3
0
    def test_undo_approvals_view(self):
        tracker, commit = make_commit(self.widgy_site)
        tracker2, commit2 = make_commit(self.widgy_site)
        url = self.widgy_site.reverse(self.widgy_site.undo_approvals_view)
        commit.approve(self.user)
        commit2.approve(self.user)

        def doit():
            return self.client.post(url, {
                'actions': json.dumps([commit.pk]),
                'referer': '/referer/',
            })

        with self.as_staffuser() as user:
            resp = doit()

        self.assertEqual(resp.status_code, 403)
        self.assertTrue(refetch(commit).is_approved)
        self.assertTrue(refetch(commit2).is_approved)

        with self.as_staffuser() as user:
            with self.with_permission(user, 'change', ReviewedVersionCommit):
                resp = doit()

        self.assertEqual(resp.status_code, 302)
        self.assertEqual(resp['Location'], 'http://testserver/referer/')
        self.assertFalse(refetch(commit).is_approved)
        self.assertTrue(refetch(commit2).is_approved)
Пример #4
0
    def test_review_queue(self):
        tracker, commit1 = make_commit(self.widgy_site,
                                       vt_class=ReviewedVersionTracker)

        p = Permission.objects.get(codename='change_versioncommit')
        user = User.objects.create()
        user.user_permissions.add(p)
        user.save()

        request_factory = RequestFactory()

        tracker = refetch(tracker)
        self.assertFalse(tracker.get_published_node(request_factory.get('/')))

        commit1.approve(user)

        tracker = refetch(tracker)
        self.assertEqual(tracker.get_published_node(request_factory.get('/')),
                         commit1.root_node)

        commit2 = tracker.commit(publish_at=timezone.now())
        tracker = refetch(tracker)
        self.assertEqual(tracker.get_published_node(request_factory.get('/')),
                         commit1.root_node)

        commit2.approve(user)
        tracker = refetch(tracker)
        self.assertEqual(tracker.get_published_node(request_factory.get('/')),
                         commit2.root_node)
Пример #5
0
    def test_commit_view(self):
        tracker, first_commit = make_commit(self.widgy_site)
        url = self.widgy_site.reverse(self.widgy_site.commit_view,
                                      kwargs={
                                          'pk': tracker.pk,
                                      })

        with self.as_staffuser() as user:
            with self.with_permission(user, 'add', ReviewedVersionCommit):
                self.client.post(url, {
                    'approve_it': 1,
                    'publish_radio': 'now'
                })
                self.assertNotEqual(
                    refetch(tracker).head.reviewedversioncommit, first_commit)
                self.assertFalse(
                    refetch(tracker).head.reviewedversioncommit.is_approved)

        with self.as_staffuser() as user:
            with self.with_permission(user, 'change', ReviewedVersionCommit):
                with self.with_permission(user, 'add', ReviewedVersionCommit):
                    self.client.post(url, {
                        'approve_it': 1,
                        'publish_radio': 'now'
                    })
                    self.assertTrue(
                        refetch(
                            tracker).head.reviewedversioncommit.is_approved)
Пример #6
0
    def test_commit_view(self):
        tracker, first_commit = make_commit(self.widgy_site)
        url = self.widgy_site.reverse(self.widgy_site.commit_view, kwargs={
            'pk': tracker.pk,
        })

        with self.as_staffuser() as user:
            with self.with_permission(user, 'add', ReviewedVersionCommit):
                self.client.post(url, {'approve_it': 1, 'publish_radio': 'now'})
                self.assertNotEqual(refetch(tracker).head.reviewedversioncommit, first_commit)
                self.assertFalse(refetch(tracker).head.reviewedversioncommit.is_approved)

        with self.as_staffuser() as user:
            with self.with_permission(user, 'change', ReviewedVersionCommit):
                with self.with_permission(user, 'add', ReviewedVersionCommit):
                    self.client.post(url, {'approve_it': 1, 'publish_radio': 'now'})
                    self.assertTrue(refetch(tracker).head.reviewedversioncommit.is_approved)
Пример #7
0
    def test_commit_view(self):
        tracker, first_commit = make_commit(self.widgy_site)

        url = self.widgy_site.reverse(self.widgy_site.commit_view, kwargs={
            'pk': tracker.pk,
        })

        with self.as_staffuser() as user:
            r = self.client.post(url, {'publish_radio': 'now'})
            self.assertEqual(r.status_code, 403)
            self.assertEquals(len(refetch(tracker).get_history_list()), 1)
            self.assertEqual(refetch(tracker).head, first_commit)

        with self.as_staffuser() as user:
            with self.with_permission(user, 'add', VersionCommit):
                r = self.client.post(url, {'publish_radio': 'now'})
                self.assertEqual(r.status_code, 200)
                self.assertEquals(len(refetch(tracker).get_history_list()), 2)
Пример #8
0
    def test_approve_view(self):
        tracker, commit = make_commit(self.widgy_site)
        url = self.widgy_site.reverse(self.widgy_site.approve_view, kwargs={
            'pk': tracker.pk,
            'commit_pk': commit.pk,
        })

        with self.as_staffuser() as user:
            resp = self.client.post(url)

        self.assertEqual(resp.status_code, 403)
        self.assertFalse(refetch(commit).is_approved)

        with self.as_staffuser() as user:
            with self.with_permission(user, 'change', ReviewedVersionCommit):
                resp = self.client.post(url)

        self.assertEqual(resp.status_code, 302)
        self.assertTrue(refetch(commit).is_approved)
Пример #9
0
    def test_commit_view(self):
        tracker, first_commit = make_commit(self.widgy_site)

        url = self.widgy_site.reverse(self.widgy_site.commit_view,
                                      kwargs={
                                          'pk': tracker.pk,
                                      })

        with self.as_staffuser() as user:
            r = self.client.post(url, {'publish_radio': 'now'})
            self.assertEqual(r.status_code, 403)
            self.assertEquals(len(refetch(tracker).get_history_list()), 1)
            self.assertEqual(refetch(tracker).head, first_commit)

        with self.as_staffuser() as user:
            with self.with_permission(user, 'add', VersionCommit):
                r = self.client.post(url, {'publish_radio': 'now'})
                self.assertEqual(r.status_code, 200)
                self.assertEquals(len(refetch(tracker).get_history_list()), 2)
Пример #10
0
    def test_unapprove_view(self):
        tracker, commit = make_commit(self.widgy_site)
        url = self.widgy_site.reverse(self.widgy_site.unapprove_view,
                                      kwargs={
                                          'pk': tracker.pk,
                                          'commit_pk': commit.pk,
                                      })
        commit.approve(self.user)

        with self.as_staffuser() as user:
            resp = self.client.post(url)

        self.assertEqual(resp.status_code, 403)
        self.assertTrue(refetch(commit).is_approved)

        with self.as_staffuser() as user:
            with self.with_permission(user, 'change', ReviewedVersionCommit):
                resp = self.client.post(url)

        self.assertEqual(resp.status_code, 302)
        self.assertFalse(refetch(commit).is_approved)
Пример #11
0
    def test_reset_view(self):
        tracker, commit = make_commit(self.widgy_site)

        url = self.widgy_site.reverse(self.widgy_site.reset_view, kwargs={
            'pk': tracker.pk,
        })


        root = tracker.working_copy.content
        root.text = 'changed'
        root.save()

        with self.as_staffuser() as user:
            r = self.client.post(url)
            self.assertEqual(r.status_code, 403)
            self.assertEqual(refetch(root).text, 'changed')

        with self.as_staffuser() as user:
            with self.with_permission(user, 'add', VersionCommit):
                r = self.client.post(url)
                self.assertEqual(r.status_code, 200)
                with self.assertRaises(RawTextWidget.DoesNotExist):
                    refetch(root)
Пример #12
0
    def test_reset_view(self):
        tracker, commit = make_commit(self.widgy_site)

        url = self.widgy_site.reverse(self.widgy_site.reset_view,
                                      kwargs={
                                          'pk': tracker.pk,
                                      })

        root = tracker.working_copy.content
        root.text = 'changed'
        root.save()

        with self.as_staffuser() as user:
            r = self.client.post(url)
            self.assertEqual(r.status_code, 403)
            self.assertEqual(refetch(root).text, 'changed')

        with self.as_staffuser() as user:
            with self.with_permission(user, 'add', VersionCommit):
                r = self.client.post(url)
                self.assertEqual(r.status_code, 200)
                with self.assertRaises(RawTextWidget.DoesNotExist):
                    refetch(root)