def archivedata(urim, preferences): httpcache = getURICache(urim) # TODO: only here because we need to detect NotAMemento, need a better solution memento = memento_resource_factory(urim, httpcache) archive = ArchiveResource(urim, httpcache) if preferences['datauri_favicon'].lower() == 'yes': archive_favicon = convert_imageuri_to_pngdata_uri( archive.favicon, httpcache, 16, 16 ) else: archive_favicon = archive.favicon output = {} output['urim'] = urim output['generation-time'] = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") output['archive-uri'] = archive.home_uri output['archive-name'] = archive.name output['archive-favicon'] = archive_favicon output['archive-collection-id'] = archive.collection_id output['archive-collection-name'] = archive.collection_name output['archive-collection-uri'] = archive.collection_uri response = make_response(json.dumps(output, indent=4)) response.headers['Content-Type'] = 'application/json' response.headers['Preference-Applied'] = \ "datauri_favicon={}".format(preferences['datauri_favicon']) return response, 200
def test_favicon_from_html(self): expected_favicon = "http://myarchive.org/content/favicon.ico" cachedict = { "http://myarchive.org": mock_response(headers={}, content="""<html> <head> <title>Is this a good title?</title> <link rel="icon" href="{}"> </head> <body>Is this all there is to content?</body> </html>""".format(expected_favicon), status=200, url="testing-url://notused"), expected_favicon: mock_response(headers={'content-type': 'image/x-testing'}, content="a", status=200, url="testing-url://notused") } httpcache = mock_httpcache(cachedict) urim = "http://myarchive.org/20160518000858/http://example.com/somecontent" x = ArchiveResource(urim, httpcache) self.assertEqual(x.favicon, expected_favicon)
def test_simplestuff(self): httpcache = None urim = "https://myarchive.org/somememento" x = ArchiveResource(urim, httpcache) self.assertEqual(x.scheme, "https") self.assertEqual(x.domain, "myarchive.org") self.assertEqual(x.name, "MYARCHIVE.ORG") self.assertEqual(x.uri, "https://myarchive.org")
def test_collection_data_extraction(self): urim = "http://wayback.archive-it.org/5728/20160518000858/http://blog.willamette.edu/mba/" requests_cache.install_cache(cachefile) httpcache = requests.Session() httpcache.headers.update({'User-Agent': __useragent__}) x = ArchiveResource(urim, httpcache) self.assertEqual(x.scheme, "http") self.assertEqual(x.domain, "wayback.archive-it.org") self.assertEqual(x.name, "ARCHIVE-IT.ORG") self.assertEqual(x.uri, "http://wayback.archive-it.org") self.assertEqual(x.home_uri, "https://archive-it.org") self.assertEqual(x.collection_id, "5728") self.assertEqual(x.collection_uri, "https://archive-it.org/collections/5728") self.assertEqual(x.collection_name, "Social Media")
def test_link_tag_no_rel(self): expected_favicon = None cachedict = { "http://myarchive.org": mock_response(headers={}, content="""<html> <head> <title>Is this a good title?</title> <link title="a good title" href="content/favicon.ico"> </head> <body>Is this all there is to content?</body> </html>""", status=200, url="testing-url://notused"), expected_favicon: mock_response(headers={'content-type': 'image/x-testing'}, content="a", status=200, url="testing-url://notused"), "http://myarchive.org/favicon.ico": mock_response(headers={}, content="not found", status=404, url="testing-url://notused"), "https://www.google.com/s2/favicons?domain=myarchive.org": mock_response(headers={}, content="not found", status=404, url="testing-url://notused") } httpcache = mock_httpcache(cachedict) urim = "http://myarchive.org/20160518000858/http://example.com/somecontent" x = ArchiveResource(urim, httpcache) self.assertEqual(x.favicon, expected_favicon)