Beispiel #1
0
 def setup(self):
     self.dummy_post = Post(object(),
                            'Fhtagn Daaz',
                            'Grape Old Ones',
                            created_at=datetime(2015, 10, 11),
                            id=1)
     self.posts = mock.create_autospec(PostRepositoryABC)
     self.posts.find_by_id.return_value = self.dummy_post
     self.editor = PostEditor(posts=self.posts)
Beispiel #2
0
class TestPostEditor:
    def setup(self):
        self.dummy_post = Post(object(),
                               'Fhtagn Daaz',
                               'Grape Old Ones',
                               created_at=datetime(2015, 10, 11),
                               id=1)
        self.posts = mock.create_autospec(PostRepositoryABC)
        self.posts.find_by_id.return_value = self.dummy_post
        self.editor = PostEditor(posts=self.posts)

    def test_add_category_to_post(self):
        self.editor.add_category(post_id=1, category='Primal Ice Screams')

        assert self.dummy_post.categories == {'Primal Ice Screams'}

    def test_remove_category_from_post(self):
        self.dummy_post.categories = {'Primal Ice Screams'}
        self.editor.remove_category(post_id=1, category='Primal Ice Screams')

        assert self.dummy_post.categories == set()

    def test_edit_post_title(self):
        self.editor.edit(post_id=1, title='Cthocolate')

        assert self.dummy_post.title == 'Cthocolate'

    def test_edit_post_text(self):
        self.editor.edit(post_id=1, text='Grape is gross')

        assert self.dummy_post.text == 'Grape is gross'

    def test_set_post_for_scheduled(self, clock):
        self.editor.schedule_post(post_id=1, when=datetime(2015, 10, 15))

        assert self.dummy_post.status == PostStatus.scheduled
        assert self.dummy_post.published_at == datetime(2015, 10, 15)

    def test_revert_post_to_draft(self):
        self.dummy_post.publish()
        self.editor.revert_to_draft(post_id=1)

        assert self.dummy_post.status == PostStatus.draft

    def test_publish_post(self, clock):
        self.editor.publish_post(post_id=1, clock=clock)

        assert self.dummy_post.status == PostStatus.published
        assert self.dummy_post.published_at == clock.now()
Beispiel #3
0
class TestPostEditor:
    def setup(self):
        self.dummy_post = Post(object(), 'Fhtagn Daaz', 'Grape Old Ones',
                               created_at=datetime(2015, 10, 11), id=1)
        self.posts = mock.create_autospec(PostRepositoryABC)
        self.posts.find_by_id.return_value = self.dummy_post
        self.editor = PostEditor(posts=self.posts)

    def test_add_category_to_post(self):
        self.editor.add_category(post_id=1, category='Primal Ice Screams')

        assert self.dummy_post.categories == {'Primal Ice Screams'}

    def test_remove_category_from_post(self):
        self.dummy_post.categories = {'Primal Ice Screams'}
        self.editor.remove_category(post_id=1, category='Primal Ice Screams')

        assert self.dummy_post.categories == set()

    def test_edit_post_title(self):
        self.editor.edit(post_id=1, title='Cthocolate')

        assert self.dummy_post.title == 'Cthocolate'

    def test_edit_post_text(self):
        self.editor.edit(post_id=1, text='Grape is gross')

        assert self.dummy_post.text == 'Grape is gross'

    def test_set_post_for_scheduled(self, clock):
        self.editor.schedule_post(post_id=1, when=datetime(2015, 10, 15))

        assert self.dummy_post.status == PostStatus.scheduled
        assert self.dummy_post.published_at == datetime(2015, 10, 15)

    def test_revert_post_to_draft(self):
        self.dummy_post.publish()
        self.editor.revert_to_draft(post_id=1)

        assert self.dummy_post.status == PostStatus.draft

    def test_publish_post(self, clock):
        self.editor.publish_post(post_id=1, clock=clock)

        assert self.dummy_post.status == PostStatus.published
        assert self.dummy_post.published_at == clock.now()
Beispiel #4
0
 def setup(self):
     self.post = Post(title='Introducing Grape Old Ones',
                      text='Yummy grape flavor', created_at=datetime(2015, 10, 11),
                      author=None, categories=None)
Beispiel #5
0
class TestPost:
    def setup(self):
        self.post = Post(title='Introducing Grape Old Ones',
                         text='Yummy grape flavor', created_at=datetime(2015, 10, 11),
                         author=None, categories=None)

    def test_add_category_to_post(self):
        self.post.add_category('Fhtagn Daaz')

        assert self.post.categories == {'Fhtagn Daaz'}

    def test_remove_category_from_post(self):
        self.post.add_category('Fred')

        self.post.remove_category('Fred')

        assert self.post.categories == set()

    def test_remove_nonexistent_category_causes_PostError(self):
        with pytest.raises(PostError):
            self.post.remove_category('Fhtagn Daaz')

    def test_publish_post(self, clock):
        self.post.publish(clock=clock)

        assert self.post.status == PostStatus.published
        assert self.post.published_at == datetime(2015, 10, 11)

    def test_revert_post_to_draft(self):
        self.post.publish()

        self.post.revert_to_draft()

        assert self.post.status == PostStatus.draft
        assert not self.post.published_at

    def test_cant_revert_draft_post(self):
        with pytest.raises(PostError):
            self.post.revert_to_draft()

    def test_schedule_post(self, clock):
        self.post.schedule(when=datetime(2015, 10, 12), clock=clock)

        assert self.post.status == PostStatus.scheduled
        assert self.post.published_at == datetime(2015, 10, 12)

    def test_cant_retroactively_schedule_post(self, clock):
        with pytest.raises(PostError):
            self.post.schedule(when=datetime(2015, 10, 10), clock=clock)

    def test_edit_post_title(self):
        self.post.edit_title(title='Cthocolate')

        assert self.post.title == 'Cthocolate'

    def test_edit_post_text(self):
        self.post.edit_text(text='Grape is gross')

        assert self.post.text == 'Grape is gross'
Beispiel #6
0
 def setup(self):
     self.dummy_post = Post(object(), 'Fhtagn Daaz', 'Grape Old Ones',
                            created_at=datetime(2015, 10, 11), id=1)
     self.posts = mock.create_autospec(PostRepositoryABC)
     self.posts.find_by_id.return_value = self.dummy_post
     self.editor = PostEditor(posts=self.posts)