def test_single_decorate(self): html_mock_1 = "<html><head><script src='/teste_html.js'></head></html>" html_mock_2 = "<html><head><script src='teste_2html.js'></script><script src=\"teste.js\"></head></html>" html_mock_3 = "<html><head><script src=\"images/teste_2html.js\"></script><script src=\"teste.js\"></head></html>" domain_mock = "www.watinha.com" html_result_mock_1 = "<html><head><script src='http://www.watinha.com/teste_html.js'></head></html>" html_result_mock_2 = "<html><head><script src='http://www.watinha.com/teste_2html.js'></script><script src=\"http://www.watinha.com/teste.js\"></head></html>" html_result_mock_3 = "<html><head><script src=\"http://www.watinha.com/images/teste_2html.js\"></script><script src=\"http://www.watinha.com/teste.js\"></head></html>" decorator = JsReplaceDecorator(domain_mock) self.assertEquals(decorator.decorate(""), "") self.assertEquals(decorator.decorate(html_mock_1), html_result_mock_1) self.assertEquals(decorator.decorate(html_mock_2), html_result_mock_2) self.assertEquals(decorator.decorate(html_mock_3), html_result_mock_3)
def get(self): """ Receives the GET request with a URI parameter """ parameter = self.request.get('url') domain = parse_url(parameter)[0] # Including the base javascript for replacing the relative URLs response = html_extractor (parameter) # Adding the decorators functions text_decorator = JsReplaceDecorator(domain, CSSReplaceDecorator(domain)) #script_text = "<script type='text/javascript' src='/javascripts/replacing_urls.js'></script>" #response = response[0:response.find("</head>")] + script_text + response[response.find("</head>"):] self.response.headers['Content-Type'] = 'text/html; charset=UTF-8' self.response.out.write(text_decorator.decorate_text(response))
def get(self): """ Receives the GET request with a URI parameter """ parameter = self.request.get('url') domain = parse_url(parameter)[0] # Including the base javascript for replacing the relative URLs response = html_extractor(parameter) # Adding the decorators functions text_decorator = JsReplaceDecorator(domain, CSSReplaceDecorator(domain)) #script_text = "<script type='text/javascript' src='/javascripts/replacing_urls.js'></script>" #response = response[0:response.find("</head>")] + script_text + response[response.find("</head>"):] self.response.headers['Content-Type'] = 'text/html; charset=UTF-8' self.response.out.write(text_decorator.decorate_text(response))