示例#1
0
 def fake_open(req):
     u = req if isinstance(req, types.StringType) else req.get_full_url()
     if "http://www.ted.com/" in u:
         return fetch(u)
     if "https://api.github.com/gists" in u:
         self.assertIsNotNone(req.get_data())
         return open(conf.data_path("hello-gist.json"))
     return None
示例#2
0
 def test_parser(self):
     body = open(conf.data_path("hello-post.md")).read().decode("utf-8")
     target = gisted.Post.parse("12345", body)
     self.assertEquals(target.title, u"Commencement Address to Atlanta’s John Marshall Law School")
     self.assertEquals(target.source_url, "http://lessig.tumblr.com/post/24065401182/commencement-address-to-atlantas-john-marshall-law")
     self.assertEquals(target.source_hostname, "lessig.tumblr.com")
     self.assertEquals(target.way_url, "http://gisted.in/")
     self.assertEquals(target.way_hostname, "gisted.in")
     self.assertEquals(len(target.paragraphs), 58)
     self.assertIn("Congratulations to you", target.body)
     markdown = target.to_markdown()
     self.assertIn("----", markdown)
示例#3
0
 def test_hello(self):
     target = gisted.Downloader.make()
     resp = json.load(open(conf.data_path("hello-gist.json")))
     url = target._find_raw_url(resp)
     self.assertEquals("https://gist.github.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl", url)
示例#4
0
 def open(self, req):
     if (req.get_full_url() == "hello-post.md"):
         return open(conf.data_path("hello-post.md"))
     if ("/gists/testshow" in req.get_full_url()):
         return open(conf.data_path("hello-post.json"))
     return urllib2.urlopen(req)