def test_create_post_in_blog(self): b = Blog('Test', 'Test Author') b.create_post('Test Post', 'Test Content') self.assertEqual(len(b.posts), 1) self.assertEqual(b.posts[0].title, 'Test Post') self.assertEqual(b.posts[0].content, 'Test Content')
def test_json_no_posts(self): b = Blog('Test', 'Test author') self.assertDictEqual(b.json(), { 'title': b.title, 'author': b.author, 'posts': [], })
def test_json_with_posts(self): b = Blog('Test', 'Test author') b.create_post('Test Post', 'Test Content') self.assertDictEqual( b.json(), { 'title': b.title, 'author': b.author, 'posts': [{ 'title': 'Test Post', 'content': 'Test Content' }], })
def test_json(self): b = Blog('Test', 'Test Author') b.create_post('Test Post', 'Test Content') expected = { 'title': 'Test', 'author': 'Test Author', 'posts': [{ 'title': 'Test Post', 'content': 'Test Content' }] } self.assertDictEqual(b.json(), expected)
def test_json(self): b = Blog('Test', 'Test Author') b.create_post('Test Post', 'Test Content') expected = { 'title': 'Test', 'author': 'Test Author', 'posts': [ {'title': 'Test Post', 'content': 'Test Content'} ] }
def test_repr_multiple_posts(self): b = Blog('Title', 'Author') b.posts = ['post1'] b2 = Blog('My Day', 'Bob') b2.posts = ['Test Blog', 'another'] self.assertEqual(b.__repr__(), 'Title by Author (1 post)') self.assertEqual(b2.__repr__(), 'My Day by Bob (2 posts)')
def test_create_blog(self): b = Blog('Test', 'Test author') self.assertEqual('Test', b.title) self.assertEqual('Test author', b.author) self.assertEqual(0, len(b.posts)) self.assertListEqual([], b.posts)
def test_blog_repr(self): b = Blog('Test', 'Test author') self.assertEqual(str(b), 'Test by Test author (0 posts)')
def setUp(self): blog = Blog('Test', 'Test Author') appp.blogs = {'Test': blog}
def test_repr_multiple_posts(self): b = Blog('Test', 'Test Author') b.posts = ['test'] self.assertEqual((b.__repr__()), 'Test by Test Author (1 post)')
def test_repr(self): b = Blog('Test', 'Test Author') self.assertEqual((b.__repr__()), 'Test by Test Author (0 posts)')
(r"/(MP_verify_.*)", tornado.web.StaticFileHandler, { "path": os.path.join(os.path.dirname(__file__), "static") }), ] ui_modules = [] from blog.blog import Blog from t9x import t9x from wx.wx import WX #from geek import geek #from wifigod import wifigod #from movies import movies #from club import club #from blog import blog #from mysky import mysky blog = Blog() webhandlers.extend(Blog().handlers()) webhandlers.extend(t9x.T9x().handlers()) #webhandlers.extend(club.Club().handlers()) #webhandlers.extend(wifigod.WifiGod().handlers()) #webhandlers.extend(movies.Movies().handlers()) # webhandlers.extend(geek.Geek().handlers()) #webhandlers.extend(mysky.MySky().handlers()) webhandlers.extend(WX().handlers()) webhandlers.append((r"/.*", Error)) # always the last! ui_modules.extend(WX().uimodules()) ui_modules.extend(Blog().uimodules()) for handler in webhandlers: print(handler[0], handler[1])
def test_print_blogs(self): blog = Blog('Test', 'Test Author') app.blogs = {'Test': blog} with patch('builtins.print') as mocked_print: app.print_blogs() mocked_print.assert_called_with('Test by Test Author (0 posts)')
import atexit # 导入http server from wgsi_server.wgsi_server import MhttpServer from kanado import Kanado, render_template from blog.blog import Blog if __name__ == '__main__': app = Kanado(__name__) blogs = [] b1 = Blog(1, 'hello1', 'zhangsan') b2 = Blog(2, 'hello2', 'lisi') blogs.append(b1) blogs.append(b2) @app.route('/') def home(): return render_template('index.html') @app.route('/blogs') def list_notes(): return render_template('list_blogs.html', blogs=blogs) @app.route('/blog/<id>') def query_note(id): blog = None # 到数据库查询博文详情 for blg in blogs: if blg.id == int(id): blog = blg # 渲染博文详情页面
def test_repr(self): b = Blog('Title', 'Author') c = Blog('My Day', 'Bob') self.assertEqual(b.__repr__(), 'Title by Author (0 posts)') self.assertEqual(c.__repr__(), 'My Day by Bob (0 posts)')
def ask_create_blog(): title = input("Enter your blog title: ") author = input("Enter your name: ") blogs[title] = Blog(title, author)