def get(self): text = self.request.get('text', None) if not text: self.response.out.write('') # no input detected. else: tp = TextParser(text) self.response.out.write(json.dumps(tp.fetch_urls())) self.response.headers.add_header("Content-type", "application/json")
def test_simple_links(self): # make sure the shuffled sequence does not lose any elements tp = TextParser(self.text) tp.extract_urls() self.assertEqual( tp.urls, [ "http://www.youtube.com/watch?v=zGXAVw3vF9A", "http://www.slideshare.net/startuplessonslearned/2012-05-15-" "eric-ries-the-lean-startup-pwc-canada", "http://www.nytimes.com/2010/04/25/business/25unboxed.html", ], )
def test_shortened_links(self): text = ( "" "Check out this video of Eric Ries " "http://bit.ly/aVlV11 from " "Stanford University. It's a good start to understand Lean Startup. " "Here is a presentation " "you need to see as well " "http://slidesha.re/M2z64S ." "NYTIme recently covered him too " "http://nyti.ms/aICucz" "Steve" ) tp = TextParser(text) self.assertEqual(tp.fetch_urls(), self.default_response)
def test_complex_urls(self): # make sure the shuffled sequence does not lose any elements text = """ Check out this video of Eric Ries http://bit.ly/abc from Stanford University. It's a good start to understand Lean Startup. Here is a presentation you need to see as well bit.ly/xyz NYTIme recently covered him too www.a.long.and.weird.url.com/yep Steve """ tp = TextParser(text) tp.extract_urls() self.assertEqual(tp.urls, ["http://bit.ly/abc", "http://bit.ly/xyz", "http://www.a.long.and.weird.url.com/yep"])
def test_embed_codes(self): tp = TextParser(self.text) self.assertEqual(tp.fetch_urls(), self.default_response)