def test_should_update_the_resource_when_it_attempts_a_redirect(self): web = TestWeb() url = "http://localhost:5000/redirect" web.head = self.redirect resource = Resource('Page', 'http://localhost:5000', web) resource.isAPage() web.head = lambda x: FakeResponse('Content', 'application/pdf') self.assertEqual(resource.name, "redirect.pdf") self.assertEqual(resource.url, "http://localhost:5000/redirect.pdf")
def resources(self): files = [] anchors = self.find_links_in_content(self.markup) for anchor in anchors: resource = Resource(anchor.getText(), anchor.get('href'), self.web, "http://elearning.uni-heidelberg.de/mod/resource/") if resource.url == '' or resource.isOnExternalWebsite(): continue try: if resource.isAPage(): content = resource.load() f = Page(content, self.web).resources() files.append(f) else: files.append(resource) except urllib2.HTTPError as e: debug("Could not retrieve %s." % resource.url) continue return deflate(files)
def test_should_indicate_that_the_resource_is_a_page(self): web = TestWeb() web.response = FakeResponse("Content", "text/html") resource = Resource("any", "any", web) self.assertTrue(resource.isAPage())