def __get_page_review(email_cnt, idx): ''' Review for pages. ''' recent_posts = MWiki.query_recent_edited(tools.timestamp() - TIME_LIMIT) for recent_post in recent_posts: hist_rec = MWikiHist.get_last(recent_post.uid) if hist_rec: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_chg">Edit</td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(SITE_CFG['site_url'], 'wiki', recent_post.title)) email_cnt = email_cnt + foo_str else: foo_str = ''' <tr><td>{0}</td><td>{1}</td><td class="diff_add">New </td><td>{2}</td> <td><a href="{3}">{3}</a></td></tr> '''.format( idx, recent_post.user_name, recent_post.title, os.path.join(SITE_CFG['site_url'], 'wiki', recent_post.title)) email_cnt = email_cnt + foo_str idx = idx + 1 return email_cnt, idx
def test_query_recent_edited(self): self.add_mess() aa = MWiki.query_recent_edited(111111) tf = False for i in aa: if i.uid == self.uid: tf = True break self.tearDown() assert tf
class TestMWiki(): def setup(self): print('setup 方法执行于本类中每条用例之前') self.uu = MWiki() self.title = 'tyyyitle' self.uid = '6985' def add_page(self, **kwargs): post_data = { 'title': kwargs.get('title', self.title), 'user_name': kwargs.get('user_name', 'Tome'), 'cnt_md': kwargs.get('cnt_md', '## adslkfjasdf\n lasdfkjsadf'), } self.uu.create_page(self.uid, post_data) def test_insert(self): raw_count = self.uu.get_counts() post_data = { 'title': 'tyyyitle', 'user_name': 'Tome', 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', } self.add_page(**post_data) new_count = self.uu.get_counts() tt = self.uu.get_by_uid(self.uid) assert tt.title == post_data['title'] assert tt.cnt_md == tornado.escape.xhtml_unescape(post_data['cnt_md']) assert raw_count + 1 <= new_count self.tearDown() # def test_insert_2(self): # self.tearDown() # '''Wiki insert: Test invalid title''' # post_data = { # 'title': '', # 'user_name': 'Tome', # 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', # # } # aa=self.uu.create_page(self.uid, post_data) # assert aa==False # # self.tearDown() def test_query_all(self): self.add_page() p = {'kind': '2'} aa = self.uu.query_all(**p) tf = False for i in aa: if i.uid == self.uid: tf = True self.tearDown() assert tf def test_get_by_slug(self): self.add_page() aa = self.uu.get_by_uid(self.uid) assert aa.title == self.title self.tearDown() def test_update_cnt(self): self.add_page() post_data = { 'user_name': 'name', 'cnt_md': '## adslkfjgggfdffasdf\n lasdfkjsadf', } self.uu.update_cnt(self.uid, post_data) tt = self.uu.get_by_uid(self.uid) assert tt.user_name == post_data['user_name'] assert tt.cnt_md == tornado.escape.xhtml_unescape(post_data['cnt_md']) self.tearDown() def test_update(self): self.add_page() post_data = { 'title': 'ti', 'user_name': 'Tome', 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', } aa = self.uu.update(self.uid, post_data) assert aa == None post_data2 = { 'title': 'tgrgri', 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', } self.uu.update(self.uid, post_data2) aa = self.uu.get_by_uid(self.uid) assert aa.title == post_data2['title'] self.tearDown() def test_query_recent_edited(self): timstamp = tools.timestamp() time.sleep(1) self.add_page() aa = self.uu.query_recent_edited(timstamp, kind='2') tf = False for i in aa: if i.uid == self.uid: tf = True self.tearDown() assert tf def tearDown(self): print("function teardown") self.uu.delete(self.uid)
class TestMWiki(): def setup(self): print('setup 方法执行于本类中每条用例之前') self.uu = MWiki() self.raw_count = self.uu.get_counts() self.page_slug = 'aaa' self.uid = tools.get_uuid() def test_insert(self): raw_count = self.uu.get_counts() post_data = { 'title': 'title', 'slug': 'sadfsadf', 'id_user': '******', 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', 'view_count': 1, } self.uu.create_page('sadfsadf', post_data) new_count = self.uu.get_counts() tt = self.uu.get_by_uid(self.page_slug) # assert tt.title == post_data['title'][0] # assert tt.cnt_md == tornado.escape.xhtml_unescape(post_data['cnt_md'][0]) # assert raw_count + 1 == new_count def test_insert_2(self): '''Wiki insert: Test invalid title''' post_data = { 'title': '', 'id_user': '******', 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', 'view_count': 1, } uu = self.uu.create_page('abcd', post_data) assert uu == False post_data = { 'title': '1', 'id_user': '******', 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', 'view_count': 1, } uu = self.uu.create_page('bdef', post_data) assert uu == False post_data = { 'title': '天', 'id_user': '******', 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', 'view_count': 1, } uu = self.uu.create_page('aaaa', post_data) assert uu == False def test_query_all(self): self.uu.query_all() assert True def test_get_by_slug(self): self.uu.get_by_uid('aa') assert True def test_update_cnt(self): post_data = { 'user_name': 'name', 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', } self.uu.update_cnt(self.uid, post_data) assert True def test_update(self): post_data = { 'title': 'title', 'user_name': 'Tome', 'cnt_md': '## adslkfjasdf\n lasdfkjsadf', } self.uu.update(self.uid, post_data) assert True def test_query_recent_edited(self): timstamp = tools.timestamp() self.uu.query_recent_edited(timstamp) assert True def tearDown(self): print("function teardown") tt = self.uu.get_by_uid(self.page_slug) if tt: self.uu.delete(tt.uid)