def testOne(self): with app.test_request_context(): write_post(u"Post Title", u"A generic blog post", self.auth_id, self.auth_name) expected = ('Post Title', 'A generic blog post', 'testauthor') response = self.client.get('/').data for elem in expected: assert elem in response
def testOne(self): with app.test_request_context(): write_post(u"Single Post", u"Bloggity blog post, just one this time", self.auth_id, self.auth_name) expected = ('Single Post', 'Bloggity blog post, just one this time', 'testauthor') response = self.client.get('/post/1').data for elem in expected: assert elem in response
def test_long_title(self): author = Author.query.first() with self.assertRaises(DataError): write_post( """THOU HAST WRITTEN A RIDICULOUS TITLE THAT SHALL EXCEED THE MAXIMIUM THRESHOLD ALLOWED""", "I LOVE UNIT-TESTING IN PYTHON!!!!", author)
def testWriteOne(self): expected = Post(u"First Post", u""" The text containing the first post in the blog.""", self.auth_id, self.auth_name) write_post(u"First Post", u""" The text containing the first post in the blog.""", self.auth_id, self.auth_name) actual = Post.query.filter_by(title=u'First Post').first() self.assertEqual(expected.title, actual.title) self.assertEqual(expected.body, actual.body) self.assertEqual(expected.auth_name, actual.auth_name)
def test_writePost(self): self.LOGIN(self.author, self.password) session['current_user'] = self.author write_post(self.spring, self.imaginations) post = Post.query.all()[0] self.assertEqual(len(Post.query.all()), 1) self.assertEqual(post.title, self.spring) self.assertEqual(post.body, self.imaginations) self.assertTrue(post.pub_date)
def test_read_posts_order(self): """Add a new post, then verify that calling read_posts() places it at the top of the list of posts it returns. """ microblog.write_post(self.title, self.body, self.auth_id) posts = microblog.read_posts() self.assertEqual(len(posts), 3) self.assertEqual(posts[0].title, self.title) self.assertEqual(posts[0].body, self.body) self.assertEqual(posts[0].auth_id, self.auth_id)
def test_write_post(self): """Write a post and then verify that it appeared at the top of the microblog. """ microblog.write_post(self.title, self.body, self.auth_id) posts = microblog.read_posts() self.assertEqual(len(posts), 1) self.assertEqual(posts[0].title, self.title) self.assertEqual(posts[0].body, self.body) self.assertEqual(posts[0].auth_id, self.auth_id)
def testReadOne(self): expected = Post(u"New Post", u""" The text containing the newest post in the blog.""", self.auth_id, self.auth_name) write_post(u"New Post", u""" The text containing the newest post in the blog.""", self.auth_id, self.auth_name) actual = read_posts()[0] self.assertEqual(expected.title, actual.title) self.assertEqual(expected.body, actual.body) self.assertEqual(self.auth_id, actual.author_id) self.assertEqual(self.auth_name, actual.auth_name)
def test_write_post(self): test_title = 'Testing the title.' test_body = 'This is the body of the test microblog post.' test_cat = '' test_auth = 1 microblog.write_post(test_title, test_body, test_cat, test_auth) expected_post = microblog.Post( test_title, test_body, [], test_auth) result_post = microblog.Post.query.filter_by(title=test_title).first() self.assertEqual(expected_post.title, result_post.title) self.assertEqual(expected_post.body, expected_post.body)
def test_read_post(self): test_title = 'Testing the title.' test_body = 'This is the body of the test microblog post.' test_cat = '' test_auth = 1 microblog.write_post(test_title, test_body, test_cat, test_auth) expected_post = microblog.Post( test_title, test_body, [], test_auth) result_post = microblog.read_post(1) self.assertEqual(expected_post.title, result_post.title) self.assertEqual(expected_post.body, result_post.body)
def test_write_post(self): author = Author.query.first() write_post(TITLE[0], BODY_TEXT[0], author) self.assertEquals(len(Post.query.all()), 1) post = Post.query.all()[0] #Test Attributes self.assertEquals(post.title, TITLE[0]) self.assertEquals(post.body, BODY_TEXT[0]) self.assertTrue(post.pub_date) self.assertEqual(post.author.username, self.username)
def setUp(self): microblog.db.create_all() microblog.add_user( 'admin', 'password', '*****@*****.**', confirm=False) self.user_id = \ microblog.User.query.filter_by(username='******').first().id self.posts = { "Blog 1": "A Blog Body", "Blog 2": "Another Blog Body", "Blog 3": "A Third Blog Body", } for title, body in sorted(self.posts.items(), key=lambda x: x[0]): microblog.write_post(title, body, self.user_id)
def setUp(self): microblog.db.create_all() microblog.add_user( 'admin', 'password', '*****@*****.**', confirm=False) self.auth_id = \ microblog.User.query.filter_by(username='******').first().id self.posts = { 'A Blog Title': 'A Blog Body', 'Eye-Catching Headline': 'Earth-Shattering Content', } for key, val in self.posts.items(): microblog.write_post(key, val, self.auth_id) self.title = "Another Blog Title" self.body = "Another Blog Body"
def testCategoryView(self): microblog.register_author('jack', 'markley') testpost = microblog.write_post("test title", "test body", 1) testcategory = microblog.new_category('testcategory') microblog.link_post_category(testpost, testcategory) rv = self.app.get('category/1') assert 'test title' in rv.data
def testPostView(self): microblog.register_author('jack', 'markley') microblog.register_author('jeff', 'haskins') rv = self.app.get('/post/1') assert "That post hasn't been written yet!" in rv.data microblog.write_post("test title", "test body", 1) microblog.write_post("test title2", "test body2", 2) microblog.write_post("test title3", "test body3", 1) rv = self.app.get('/post/1') assert 'test title' in rv.data assert 'test body' in rv.data assert 'jack' in rv.data assert 'jeff' not in rv.data rv = self.app.get('/post/2') assert 'test title2' in rv.data assert 'test body2' in rv.data assert 'jeff' in rv.data assert 'jack' not in rv.data rv = self.app.get('/post/3') assert 'test title3' in rv.data assert 'test body3' in rv.data assert 'jack' in rv.data rv = self.app.get('/post/78') assert "That post hasn't been written yet!" in rv.data
def testSingleGet(self): microblog.register_author('jack', 'markley') microblog.write_post("test title", "test body", 1) microblog.write_post("test title2", "test body2", 1) microblog.write_post("test title3", "test body3", 1) self.assertEqual(microblog.get_post(1).BlagPost.title, "test title") self.assertEqual(microblog.get_post(3).BlagPost.body, "test body3")
def testMany(self): with app.test_request_context(): write_post(u"Post One", u"The first blog post in a list", self.auth_id, self.auth_name) write_post(u"Post Two", u"The second blog post in a list", self.auth_id, self.auth_name) write_post(u"Post Three", u"The third blog post in a list", self.auth_id, self.auth_name) expected = ('Post Three', 'The third blog post in a list', 'testauthor') response = self.client.get('/post/3').data for elem in expected: self.assertIn(elem, response)
def testBlagGet(self): microblog.register_author('jack', 'markley') microblog.write_post("test title", "test body", 1) microblog.write_post("test title2", "test body2", 1) microblog.write_post("test title3", "test body3", 1) a = microblog.get_posts() self.assertEqual(a[2].BlagPost.title, "test title") self.assertEqual(a[0].BlagPost.body, "test body3")
def testMany(self): with app.test_request_context(): write_post(u"Post Number One", u"Some text that makes up blog post number one", self.auth_id, self.auth_name) write_post(u"Post Number Two", u"Some text that makes up blog post number two", self.auth_id, self.auth_name) write_post(u"Post Number Three", u"Some text that makes up blog post number three", self.auth_id, self.auth_name) expected = ('Post Number One', 'Post Number Two', 'Post Number Three', 'Some text', 'testauthor') response = self.client.get('/').data for elem in expected: assert elem in response
def test_read_posts(self): test_title = 'Testing the title.' test_body = 'This is the body of the test microblog post.' test_cat = '' test_auth = 1 microblog.write_post(test_title, test_body, test_cat, test_auth) expected_post1 = microblog.Post( test_title, test_body, [], test_auth) test_title = 'Testing the title a second time.' test_body = 'This is the body of the second test microblog post.' microblog.write_post(test_title, test_body, test_cat, test_auth) expected_post2 = microblog.Post( test_title, test_body, [], test_auth) results = microblog.read_posts() result_post1 = results[1] result_post2 = results[0] self.assertEqual(expected_post1.title, result_post1.title) self.assertEqual(expected_post1.body, result_post1.body) self.assertEqual(expected_post2.title, result_post2.title) self.assertEqual(expected_post2.body, result_post2.body)
def testBlagPost(self): microblog.register_author('jack', 'markley') microblog.write_post("test title", "test body", 1) microblog.write_post("test title2", "test body2", 1) microblog.write_post("test title3", "test body3", 1) blags = microblog.BlagPost.query.all() self.assertEqual(blags[0].title, "test title") self.assertEqual(blags[2].body, "test body3")
def testPostsView(self): microblog.register_author('jack', 'markley') microblog.register_author('jeff', 'haskins') microblog.register_author('ben', 'markley') rv = self.app.get('/') assert 'No posts yet' in rv.data microblog.write_post("test title", "test body", 1) microblog.write_post("test title2", "test body2", 1) microblog.write_post("test title3", "test body3", 2) rv = self.app.get('/') assert 'test title' in rv.data assert 'test title2' in rv.data assert 'test title3' in rv.data assert 'jack' in rv.data assert 'jeff' in rv.data assert 'ben' not in rv.data
def test_writePost_wordy_title(self): self.LOGIN(self.author, self.password) session['current_user'] = self.author with self.assertRaises(DataError): write_post(self.imaginations, self.spring)
def testFirst(self): write_post(u"Newer Post", u""" The text containing the newer post in the blog.""", self.auth_id, self.auth_name) self.assertIsInstance(read_post(1), Post)
def POETRY(self): for letter in 'POEM': session['current_user'] = self.author write_post(letter, self.imaginations)
def test_writePost_missing_values(self): self.LOGIN(self.author, self.password) with self.assertRaises(ValueError): write_post(None, None) write_post(self.spring, None) write_post(None, self.imaginations)
def test_empty_title(self): author = Author.query.first() with self.assertRaises(ValueError): write_post(None, "I LOVE UNIT-TESTING IN PYTHON!!!!", author)
def setup_posts(self): author = Author.query.first() for num in range(4): write_post(TITLE[num], BODY_TEXT[num], author)
def testCategories(self): microblog.register_author('jack', 'markley') testpost = microblog.write_post("test title", "test body", 1) testcategory = microblog.new_category('testcategory') microblog.link_post_category(testpost, testcategory) assert testcategory in testpost.categories