예제 #1
0
 def setUp(self):
     super(TestWhenModerating, self).setUp()
     post = create_post('mypost')
     discussion_controller = Mock(
         discussion = Mock(_id=post.discussion_id),
     )
     self.controller = ModerationController(discussion_controller)
예제 #2
0
class TestWhenModerating(WithDatabase):
    patches = [patches.fake_app_patch,
               patches.fake_redirect_patch,
               patches.fake_request_patch,
               patches.disable_notifications_patch]

    def setUp(self):
        super(TestWhenModerating, self).setUp()
        create_post('mypost')
        discussion_controller = Mock()
        self.controller = ModerationController(discussion_controller)

    def test_that_it_can_approve(self):
        self.moderate_post(approve=True)
        assert self.get_post().status == 'ok'

    def test_that_it_can_mark_as_spam(self):
        self.moderate_post(spam=True)
        assert self.get_post().status == 'spam'

    def test_that_it_can_be_deleted(self):
        self.moderate_post(delete=True)
        assert self.get_post() is None

    def moderate_post(self, **kwargs):
        self.controller.save_moderation(post=[dict(checked=True, full_slug=self.get_post().full_slug)],
                                 **kwargs)
        ThreadLocalORMSession.flush_all()

    def get_post(self):
        return model.Post.query.get(slug='mypost')
예제 #3
0
class TestWhenModerating(WithDatabase):
    patches = [patches.fake_app_patch,
               patches.fake_user_patch,
               patches.fake_redirect_patch,
               patches.fake_request_patch,
               patches.disable_notifications_patch]

    def setUp(self):
        super(TestWhenModerating, self).setUp()
        post = create_post('mypost')
        discussion_controller = Mock(
            discussion=Mock(_id=post.discussion_id),
        )
        self.controller = ModerationController(discussion_controller)

    def test_that_it_can_approve(self):
        mod_date = self.get_post().mod_date

        with patch('allura.model.discuss.Thread.post_to_feed') as mock_post_to_feed:
            self.moderate_post(approve=True)
            assert mock_post_to_feed.called
            assert mock_post_to_feed.call_count == 1

        post = self.get_post()
        assert_equal(post.status, 'ok')
        assert_equal(post.thread.last_post_date.strftime("%Y-%m-%d %H:%M:%S"),
                     mod_date.strftime("%Y-%m-%d %H:%M:%S"))

    def test_that_it_can_mark_as_spam(self):
        self.moderate_post(spam=True)
        assert_equal(self.get_post().status, 'spam')

    def test_that_it_can_be_deleted(self):
        self.moderate_post(delete=True)
        assert_equal(self.get_post(), None)

    def moderate_post(self, **kwargs):
        with patch('allura.controllers.discuss.flash'):
            self.controller.save_moderation(
                post=[dict(checked=True, _id=self.get_post()._id)],
                **kwargs)
        ThreadLocalORMSession.flush_all()

    def get_post(self):
        return model.Post.query.get(slug='mypost', deleted=False)
class TestWhenModerating(WithDatabase):
    patches = [patches.fake_app_patch,
               patches.fake_user_patch,
               patches.fake_redirect_patch,
               patches.fake_request_patch,
               patches.disable_notifications_patch]

    def setUp(self):
        super(TestWhenModerating, self).setUp()
        post = create_post('mypost')
        discussion_controller = Mock(
            discussion=Mock(_id=post.discussion_id),
        )
        self.controller = ModerationController(discussion_controller)

    def test_that_it_can_approve(self):
        mod_date = self.get_post().mod_date

        with patch('allura.model.discuss.Thread.post_to_feed') as mock_post_to_feed:
            self.moderate_post(approve=True)
            assert mock_post_to_feed.called
            assert mock_post_to_feed.call_count == 1

        post = self.get_post()
        assert_equal(post.status, 'ok')
        assert_equal(post.thread.last_post_date.strftime("%Y-%m-%d %H:%M:%S"),
                     mod_date.strftime("%Y-%m-%d %H:%M:%S"))

    def test_that_it_can_mark_as_spam(self):
        self.moderate_post(spam=True)
        assert_equal(self.get_post().status, 'spam')

    def test_that_it_can_be_deleted(self):
        self.moderate_post(delete=True)
        assert_equal(self.get_post(), None)

    def moderate_post(self, **kwargs):
        with patch('allura.controllers.discuss.flash'):
            self.controller.save_moderation(
                post=[dict(checked=True, _id=self.get_post()._id)],
                **kwargs)
        ThreadLocalORMSession.flush_all()

    def get_post(self):
        return model.Post.query.get(slug='mypost', deleted=False)
예제 #5
0
def show_moderation_index(discussion, **kwargs_for_controller):
    discussion_controller = Mock()
    discussion_controller.discussion = discussion
    controller = ModerationController(discussion_controller)
    template_variables = controller.index(**kwargs_for_controller)
    return template_variables
예제 #6
0
 def setUp(self):
     super(TestWhenModerating, self).setUp()
     create_post('mypost')
     discussion_controller = Mock()
     self.controller = ModerationController(discussion_controller)