python类ContextDecorator()的实例源码

test_render.py 文件源码 项目:taktyk 作者: kosior 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_create(self, mock_get_all_entries, mock_count_tags, mock_db, test_strftime):
        test_strftime.return_value = self.date
        tags = [('testtag1', 123), ('testtag2', 1), ('testtag3', 25)]
        mock_count_tags.return_value = tags
        entry_args = ('444', 'testauthor', 'testdate', '', 'testbody_html', 'testurl', '+1000',
                      'testmedia_url', 'testtags', '')
        sample_entry = Entry(*entry_args)
        mock_get_all_entries.return_value = [sample_entry]

        class MockConnect(ContextDecorator):
            def __enter__(self):
                pass

            def __exit__(self, exc_type, exc_val, exc_tb):
                pass

        DB.Connect = MockConnect
        htmlfile = HtmlFile()
        htmlfile.user_files_path = os.path.join(settings.SAVE_PATH, 'tests')
        htmlfile.create()

        self.assertTrue(os.path.isfile(self.html_path))

        with open(self.html_path, 'r') as file:
            content = file.read()

        for tag, _ in tags:
            self.assertTrue(tag in content)
        for arg in entry_args:
            self.assertTrue(arg in content)


问题


面经


文章

微信
公众号

扫码关注公众号