Ejemplo n.º 1
0
    def test_print_posts(self):
        blog = Blog('Test', 'Test Author')
        blog_project.app.blogs = {'Test': blog}
        blog.create_new_post('Test Title', 'Test Content')
        with patch('blog_project.app.print_post') as mocked_print_post:
            blog_project.app.print_posts(blog)

            mocked_print_post.assert_called_with(blog.posts[0])
    def test_create_json_blog_no_posts(self):
        new_blog = Blog ("Ian Kowalsky", "Cookies Time")
        expected_json = {
            "author" : "Ian Kowalsky",
            "title" : "Cookies Time",
            "posts" : [ ]
        }

        self.assertDictEqual(expected_json, new_blog.create_json())
    def test_create_json_blog(self):
        new_blog = Blog ("Ian Kowalsky", "Cookies Time")
        new_blog.create_new_post("Something delicious", "We love sweets and so on")
        expected_json = {
            "author" : "Ian Kowalsky",
            "title" : "Cookies Time",
            "posts" : [{
                "title" : "Something delicious",
                "content" : "We love sweets and so on" }]
        }

        self.assertDictEqual(expected_json, new_blog.create_json())
    def test_create_blog(self):
        new_blog = Blog("Ian Kowalsky", "Cookies Time")

        self.assertEqual("Ian Kowalsky", new_blog.author)
        self.assertEqual("Cookies Time", new_blog.title)
    #   self.assertListEqual([], new_blog.posts)
        self.assertEqual(0, len(new_blog.posts))
Ejemplo n.º 5
0
    def test_ask_read_blog(self):
        blog = Blog('Test', 'Test Author')
        blog_project.app.blogs = {'Test': blog}
        with patch('builtins.input', return_value = 'Test'):
            with patch('blog_project.app.print_posts') as mocked_print_posts:
                blog_project.app.ask_read_blog()

                mocked_print_posts.assert_called_with(blog)
Ejemplo n.º 6
0
    def test_ask_create_post(self):
        blog = Blog('Test', 'Test Author')
        blog_project.app.blogs = {'Test': blog}
        with patch('builtins.input') as mocked_input:
            mocked_input.side_effect = ('Test', 'Test Title', 'Test Content')
            blog_project.app.ask_create_post()

            self.assertEqual(blog.posts[0].title, 'Test Title')
            self.assertEqual(blog.posts[0].content, 'Test Content')
def ask_create_blog():
    title = input('Please, provide blog title: ')
    author = input('Please, enter author name: ')
    blogs[title] = Blog(title, author)
    def test_create_new_post_verify_post_content(self):
        blog_with_post = Blog ("Ian Kowalsky", "Cookies Time")
        blog_with_post.create_new_post("Something delicious", "We love sweets and so on")

        self.assertEqual("We love sweets and so on", blog_with_post.posts[0].content)
    def test_repr_many_posts(self):
        many_posts_blog = Blog("Ian Kowalsky", "Cookies Time")
        many_posts_blog.posts = ["One", "Two", "Three"]

        self.assertEqual('Cookies Time by Ian Kowalsky (3 posts available)',
                         many_posts_blog.__repr__())
    def test_repr_one_post(self):
        single_post_blog = Blog("Ian Kowalsky", "Cookies Time")
        single_post_blog.posts = ["One"]

        self.assertEqual('Cookies Time by Ian Kowalsky (1 post available)',
                         single_post_blog.__repr__())
    def test_repr_none_post(self):
        none_post_blog = Blog("Ian Kowalsky", "Cookies Time")

        self.assertEqual('Cookies Time by Ian Kowalsky (0 posts available)',
                         none_post_blog.__repr__())
Ejemplo n.º 12
0
 def test_print_blogs(self):
     blog = Blog('Test Author', 'Test')
     blog_project.app.blogs = {'Test Author' : blog}
     with patch('builtins.print') as mocked_print:
         blog_project.app.print_blogs()
         mocked_print.assert_called_with('Test by Test Author (0 posts available)')