예제 #1
0
class BlogTestCase(TestCase):
    """Rewrite of Ben Potter's test"""
    def setUp(self) -> None:
        """Generate a blog post from a call to a Lorem Ipsum API"""
        self.blog_post = {
            "author":
            "Marcus Tullius Cicero",
            "title":
            "Lorem Ipsum",
            "text":
            urllib.request.urlopen(
                url="https://loripsum.net/api/3/medium/plaintext").read().
            decode("UTF-8"),
        }
        self.test_post = Post(**self.blog_post)
        self.test_post.save()

    def test_blog(self) -> None:
        """Verify that the contents of the blog post match what was generated"""
        for key, val in self.blog_post.items():
            self.assertEqual(val, self.test_post.__getattribute__(key))