def test__create_tracking_tag_valid(self): self.t = HtmlTransformation(color="green", code="<img src=''>", link="www.google.com") result = self.t._create_tracking_tag("<img src=''>") self.assertIsNotNone(result) self.assertIn("<img", result)
class TestHtmlTransformHelpers(unittest.TestCase): def test__create_tracking_tag_empty(self): self.t = HtmlTransformation(color="green", code="", link="www.google.com") result = self.t._create_tracking_tag("") self.assertEqual(result, None) def test__create_tracking_tag_valid(self): self.t = HtmlTransformation(color="green", code="<img src=''>", link="www.google.com") result = self.t._create_tracking_tag("<img src=''>") self.assertIsNotNone(result) self.assertIn("<img", result)
def bundle_content_section(src_path, dst_path, section, config, online_link): """Bundles content. Calls copy_files method after setting necessary parameters in HtmlTransformation Args: src_path: Path to the content to be bundled dst_path: Path where the bundled content will be written section: Section to be bundled config: Dictionary containing configuration parameters online_link: URL to content online """ # Initialising a list of transformations logging.info("Start bundling files from " + section + ".") transformations = [] if online_link and not "http://" in online_link: online_link = "http://" + online_link link_color = config["link_color"] tracking_code = config["tracking_code"] html_transform = HtmlTransformation(color=link_color, code=tracking_code, link=online_link) transformations.append(html_transform) paths = (src_path, dst_path) copy_files(paths, section, transformations) click.echo("\n") logging.info("Finish bundling files from " + section + ".")
def test_copy_files(self): link_color = "blue" tracking_code = "##########" online_link = "www.xxx.com" section = "Books" html_transformation = HtmlTransformation(color=link_color, code=tracking_code, link=online_link) paths = self.src_dir, self.dst_dir copy_files(paths, section, [html_transformation]) expected = "Mary had a little lamb.\n" result = open(join(self.dst_dir, self.filename)).read() self.assertEqual(result, expected)
def setUp(self): self.t = HtmlTransformation(color="green", code="<img src=''>", link="www.google.com") self.filename = "test_file.html"
class TestHtmlTransformPublic(unittest.TestCase): def setUp(self): self.t = HtmlTransformation(color="green", code="<img src=''>", link="www.google.com") self.filename = "test_file.html" def test_transform_empty(self): result = self.t.transform("", self.filename) self.assertEquals(result, "") def test_transform_case1(self): """If there is no <body> and <a>. """ html_in = "<html><div></div></html>" html_out = "<html><div></div></html>" result = self.t.transform(html_in, self.filename) self.assertEquals(result, html_out) def test_transform_case2(self): """If there is no <body> but there is <a>. """ html_in = "<html><a href='http://'></a></html>" html_out = ("<html><a href='http://' target='_blank' " " style='color: green' ></a></html>") result = self.t.transform(html_in, self.filename) self.assertEquals(result, html_out) def test_transform_case3(self): """If there is no <body> and we have non-relative <a>. """ html_in = "<html><a href='/homepage'></a></html>" html_out = "<html><a href='/homepage'></a></html>" result = self.t.transform(html_in, self.filename) self.assertEquals(result, html_out) def test_transform_case4(self): """If there is no <body> and we have non-relative <a> and a relative <a>. """ html_in = "<html><a href='http://'></a><a href='/homepage'></a></html>" html_out = ( "<html><a href='http://' target='_blank' " " style='color: green' ></a><a href='/homepage'></a></html>") result = self.t.transform(html_in, self.filename) self.assertEquals(result, html_out) def test_transform_case5(self): """If there is <body> and no <a> . """ html_in = "<html><body></body></html>" result = self.t.transform(html_in, self.filename) self.assertIn("<img", result) def test_transform_case6(self): """If there is <body> and there is <a> . """ html_in = "<html><body><a href='http://'></a></body></html>" result = self.t.transform(html_in, self.filename) self.assertIn("<img", result) self.assertIn( "<a href='http://' target='_blank' style='color: green' >", result) def test_transform_tracking_insertion(self): result = self.t.transform("<html><body></body></html>", self.filename) self.assertNotEqual(self.t.tracking_code, result)
def test__create_tracking_tag_empty(self): self.t = HtmlTransformation(color="green", code="", link="www.google.com") result = self.t._create_tracking_tag("") self.assertEqual(result, None)
def compile_videos(division=None, div_dir=None, path_to=None): """Bundles only video content. Args: division: Division object div_dir: Division directory path_to: Path to division directory Returns: False if there is an exception """ click.echo("Processing videos .....................................") try: with open("./config.yaml") as data_file: conf_data = yaml.load(data_file) except: message = ("Oops! There is no configuration file." " Check sample and try again...") click.echo(click.style(message, fg="red")) logging.debug("Oops! There is no configuration file.") return False src_dir = conf_data["source"]["main_path"] video_src = conf_data["source"]["video_source"] or "videos" dst = conf_data["destination"]["main_path"] link_color = conf_data["absolute_link_color"] tracking_code = conf_data["tracking_code"] title = conf_data["project_title"] sub_title = conf_data["project_subtitle"] folder_name = conf_data["output_folder_name"] if not folder_name: folder_name = "goc" base_path = basename(normpath(video_src)) dst_dir = join(dst, folder_name, base_path) if not exists(join(src_dir, video_src)): message = ("\nError: Video Source Directory( " + video_src + " ) specified doesn't exist\n") click.echo(click.style(message, fg="red")) logging.error("Video Source Directory( " + video_src + " ) specified doesn't exist") return False # Initialising a list of transformations video_transformation = VideoTransformation(tracking_code, JINJA_ENVIRONMENT) transformations = list() transformations.append( HtmlTransformation(color=link_color, code=tracking_code, link=False)) transformations.append(video_transformation) # copy videos sections = get_sections(join(src_dir, video_src), join(src_dir, video_src, "metadata")) if not division: kwargs = (src_dir, dst_dir, video_src, title, sub_title, tracking_code, dst, path_to) process_video_sections(sections, folder_name, transformations, video_transformation, kwargs) else: kwargs = (src_dir, div_dir, video_src, title, sub_title, tracking_code, dst, path_to) process_video_sections(division, folder_name, transformations, video_transformation, kwargs) # copy video image(jpeg) if not isdir(join(dst, folder_name, "img")): makedirs(join(dst, folder_name, "img")) shutil.copy2("img/video_image.svg", join(dst, folder_name, "img")) # copy video image(jpeg) if not isdir(join(dst, folder_name, "img")): makedirs(join(dst, folder_name, "img")) shutil.copy2("img/back-arrow.svg", join(dst, folder_name, "img"))
class TestHtmlTransformPublic(unittest.TestCase): def setUp(self): self.t = HtmlTransformation(color="green", code="<img src=''>", link="www.google.com") self.filename = "test_file.html" def test_transform_empty(self): result = self.t.transform("", self.filename) self.assertEquals(result, "") def test_transform_case1(self): """If there is no <body> and <a>. """ html_in = "<html><div></div></html>" html_out = "<html><div></div></html>" result = self.t.transform(html_in, self.filename) self.assertEquals(result, html_out) def test_transform_case2(self): """If there is no <body> but there is <a>. """ html_in = "<html><a href='http://'></a></html>" html_out = ("<html><a href='http://' target='_blank' " " style='color: green' ></a></html>") result = self.t.transform(html_in, self.filename) self.assertEquals(result, html_out) def test_transform_case3(self): """If there is no <body> and we have non-relative <a>. """ html_in = "<html><a href='/homepage'></a></html>" html_out = "<html><a href='/homepage'></a></html>" result = self.t.transform(html_in, self.filename) self.assertEquals(result, html_out) def test_transform_case4(self): """If there is no <body> and we have non-relative <a> and a relative <a>. """ html_in = "<html><a href='http://'></a><a href='/homepage'></a></html>" html_out = ("<html><a href='http://' target='_blank' " " style='color: green' ></a><a href='/homepage'></a></html>") result = self.t.transform(html_in, self.filename) self.assertEquals(result, html_out) def test_transform_case5(self): """If there is <body> and no <a> . """ html_in = "<html><body></body></html>" result = self.t.transform(html_in, self.filename) self.assertIn("<img", result) def test_transform_case6(self): """If there is <body> and there is <a> . """ html_in = "<html><body><a href='http://'></a></body></html>" result = self.t.transform(html_in, self.filename) self.assertIn("<img", result) self.assertIn("<a href='http://' target='_blank' style='color: green' >", result) def test_transform_tracking_insertion(self): result = self.t.transform("<html><body></body></html>", self.filename) self.assertNotEqual(self.t.tracking_code, result)