def test_generate_sitemap_routes(self): sitemap_data = json.loads(read_file(os.path.join(base_path, "data", "sitemaps_r_0.json"))) expected_sitemap = read_file(os.path.join(base_path, "data", "sitemaps_r_0.xml")) # set the registry so that the routes can be generated self.request.registry = self.app.app.registry self.request.environ["HTTP_HOST"] = "example.com" sitemap = generate_sitemap(sitemap_data, ROUTE_TYPE, self.view.request, pretty_print=True) self.assertEqual(sitemap, expected_sitemap)
def test_generate_sitemap_index(self): sitemap_data = json.loads(read_file(os.path.join(base_path, "data", "sitemap_index.json"))) expected_sitemap = read_file(os.path.join(base_path, "data", "sitemap.xml")) sitemap = generate_sitemap_index( sitemap_data, "https://www.camptocamp.org/sitemaps/-DOC_TYPE-/-I-.xml", "2016-01-01T00:00:00+00:00", pretty_print=True, ) self.assertEqual(sitemap, expected_sitemap)
def test_diff_text(self): file1 = read_file(os.path.join(base_path, '1.txt')) file2 = read_file(os.path.join(base_path, '2.txt')) table = diff_text(file1, file2) # create_debug_file(table) self.assertIsNotNone(table) self.assertTrue('<span class="diff_chg">1</span>' in table) self.assertTrue('<span class="diff_chg">2</span>' in table) self.assertTrue( '<span class="diff_add">Some text here.</span>' in table)
def test_generate_sitemap_index(self): sitemap_data = json.loads( read_file(os.path.join(base_path, 'data', 'sitemap_index.json'))) expected_sitemap = read_file( os.path.join(base_path, 'data', 'sitemap.xml')) sitemap = generate_sitemap_index( sitemap_data, 'https://www.camptocamp.org/sitemaps/-DOC_TYPE-/-I-.xml', '2016-01-01T00:00:00+00:00', pretty_print=True) self.assertEqual(sitemap, expected_sitemap)
def test_generate_sitemap_waypoints(self): sitemap_data = json.loads( read_file(os.path.join(base_path, 'data', 'sitemaps_w_0.json'))) expected_sitemap = read_file( os.path.join(base_path, 'data', 'sitemaps_w_0.xml')) # set the registry so that the routes can be generated self.request.registry = self.app.app.registry self.request.environ['HTTP_HOST'] = 'example.com' sitemap = generate_sitemap(sitemap_data, WAYPOINT_TYPE, self.view.request, pretty_print=True) self.assertEqual(sitemap, expected_sitemap)
def test_all(self): def do_test(id, text, expected): result = parse_code(text) self.assertEqual(expected.rstrip(), result.rstrip(), id) test_path = os.path.join(base_path, 'test') for file in os.listdir(test_path): file_path = os.path.join(test_path, file) if os.path.isfile(file_path): if file.endswith(".md"): text = read_file(file_path) expected = read_file(file_path.replace(".md", ".html")) do_test(file, text, expected) elif file.endswith(".json"): tests = json.loads(read_file(file_path)) for test in tests: do_test(**test)
def handle_mock_request(request, file, etag): if request.headers.get('If-None-Match') == etag: return { 'status_code': 304, 'headers': { 'ETag': etag } } else: return { 'status_code': 200, 'headers': { 'Content-Type': 'application/json; charset = UTF-8', 'ETag': etag }, 'content': read_file(file) }
def create_debug_file(table): template = read_file(os.path.join(base_path, 'debug-template.html')) template = template.replace('{{table}}', table) with open('/tmp/diff-table.html', 'w') as f: f.write(template)
def test_full_conversion(self): input_txt = read_file(os.path.join(base_path, 'input.txt')) output_txt = read_file(os.path.join(base_path, 'output.txt')) txt = self.markdown_parser.convert(input_txt) txt = self.bbcode_parser.format(txt) self.assertEqual(txt, output_txt)