Repository: oduwsdl/MementoEmbed

Issue:
Test with URI-Ms from Perma.cc
To start, try:
* http://perma-archives.org/warc/20180501135244/https://www.flexispy.com/

Discussion:

Patch:
diff --git a/mementoembed/favicon.py b/mementoembed/favicon.py
index 2fff1f1..f1e76b8 100644
--- a/mementoembed/favicon.py
+++ b/mementoembed/favicon.py
@@ -112,9 +112,10 @@ def query_timegate_for_favicon(timegate_stem, candidate_favicon_uri, accept_date
 
     r = http_cache.get(favicon_timegate, headers={'accept-datetime': accept_datetime_str})
 
-    if r.status_code == 302:
+    if r.status_code == 200:
 
-        candidate_favicon_uri = r.headers['location']
+        # candidate_favicon_uri = r.headers['location']
+        candidate_favicon_uri = r.url
 
         r = http_cache.get(candidate_favicon_uri)
 
diff --git a/mementoembed/mementoresource.py b/mementoembed/mementoresource.py
index c71d0e5..140a272 100644
--- a/mementoembed/mementoresource.py
+++ b/mementoembed/mementoresource.py
@@ -28,6 +28,49 @@ class MementoParsingError(Exception):
         self.message = message
         self.original_exception = original_exception
 
+def get_memento_datetime_from_response(response):
+
+    memento_dt = None
+
+    try:
+        memento_dt = datetime.strptime(
+                response.headers['memento-datetime'], 
+                "%a, %d %b %Y %H:%M:%S GMT"
+            )
+    except KeyError as e:
+        raise NotAMementoError("no memento-datetime header", 
+            response=response, original_exception=e)
+
+    return memento_dt
+
+def get_timegate_from_response(response):
+
+    urig = None
+
+    try:
+        urig = aiu.convert_LinkTimeMap_to_dict(
+            response.headers['link'] )['timegate_uri']
+    except KeyError as e:
+        raise NotAMementoError(
+            "link header coult not be parsed for timegate URI",
+            response=response, original_exception=e)
+
+    return urig
+
+def get_original_uri_from_response(response):
+
+    urir = None
+
+    try:
+        urir = aiu.convert_LinkTimeMap_to_dict(
+            response.headers['link'] )['original_uri']
+    except KeyError as e:
+        raise NotAMementoError(
+            "link header coult not be parsed for original URI",
+            response=response, original_exception=e)
+
+    return urir
+
 def memento_resource_factory(urim, http_cache):
 
     response = http_cache.get(urim)
@@ -112,6 +155,29 @@ def memento_resource_factory(urim, http_cache):
         module_logger.info("memento at {} is an Archive.is memento".format(urim))
         return ArchiveIsMemento(http_cache, urim, given_uri=given_urim)
 
+    # if we got here, we haven't categorized the URI-M into an Archive type yet
+    # it might be a "hash-style" memento that actually resolves to a Wayback
+    memento_dt = get_memento_datetime_from_response(response)
+
+    # TODO: make this unnecessary, it is solely here for memento header testing
+    urir = get_original_uri_from_response(response)
+
+    mdt = datetime.strftime(memento_dt, "%a, %d %b %Y %H:%M:%S GMT")
+    urig = get_timegate_from_response(response)
+    tg_resp = http_cache.get(urig, headers={"accept-datetime": mdt})
+    candidate_urim = tg_resp.url
+
+    if wayback_pattern.search(candidate_urim):
+        module_logger.debug("derived URI-M {} matches the wayback pattern".format(candidate_urim))
+        candidate_raw_urim = wayback_pattern.sub(r'\1id_/', candidate_urim)
+
+        resp = http_cache.get(candidate_raw_urim)
+        urim = candidate_urim
+
+        if resp.status_code == 200:
+            module_logger.info("memento at {} is a Wayback memento".format(urim))
+            return WaybackMemento(http_cache, urim, given_uri=given_urim)
+
     # fall through to the base class
     return MementoResource(http_cache, urim, given_uri=given_urim)
 
@@ -131,23 +197,9 @@ class MementoResource:
         self.urig = None
         self.memento_dt = None
 
-        try:
-            self.memento_dt = self.memento_datetime
-        except KeyError as e:
-            raise NotAMementoError("no memento-datetime header", 
-                response=self.response, original_exception=e)
-
-        try:
-            self.urir = self.original_uri
-        except KeyError as e:
-            raise NotAMementoError("error parsing link header for original URI",
-                response=self.response, original_exception=e)
-
-        try:
-            self.urig = self.timegate
-        except KeyError as e:
-            raise NotAMementoError("error parsing link header for timegate URI",
-                response=self.response, original_exception=e)
+        self.memento_dt = self.memento_datetime
+        self.urir = self.original_uri
+        self.urig = self.timegate
         
         if 'text/html' not in self.response.headers['content-type']:
             raise MementoParsingError("Cannot process non-HTML content")
@@ -159,9 +211,8 @@ class MementoResource:
     def memento_datetime(self):
         
         if self.memento_dt is None:
-            self.memento_dt = datetime.strptime(
-                self.response.headers['memento-datetime'], 
-                "%a, %d %b %Y %H:%M:%S GMT"
+            self.memento_dt = get_memento_datetime_from_response(
+                self.response
             )
         
         return self.memento_dt
@@ -169,14 +220,14 @@ class MementoResource:
     @property
     def original_uri(self):
         if self.urir is None:
-            self.urir = aiu.convert_LinkTimeMap_to_dict( self.response.headers['link'] )['original_uri']
+            self.urir = get_original_uri_from_response(self.response)
 
         return self.urir
 
     @property
     def timegate(self):
         if self.urig is None:
-            self.urig = aiu.convert_LinkTimeMap_to_dict( self.response.headers['link'] )['timegate_uri']
+            self.urig = get_timegate_from_response(self.response)
 
         return self.urig
 


Test patch:
diff --git a/tests/test_favicon.py b/tests/test_favicon.py
index 3b03cbf..fbbf551 100644
--- a/tests/test_favicon.py
+++ b/tests/test_favicon.py
@@ -221,15 +221,15 @@ class TestFavicon(unittest.TestCase):
                 mock_response(
                     headers = { 'location': urim },
                     content = "",
-                    status = 302,
-                    url = "testing-url://notused"
+                    status = 200,
+                    url = urim
                 ),
             urim:
                 mock_response(
                     headers = { 'content-type': 'image/testing' },
                     content = "a",
                     status = 200,
-                    url = "testing-url://notused"
+                    url = urim
                 )
         }
 
diff --git a/tests/test_mementoresource.py b/tests/test_mementoresource.py
index 6138604..18eadbf 100644
--- a/tests/test_mementoresource.py
+++ b/tests/test_mementoresource.py
@@ -13,9 +13,10 @@ testdir = os.path.dirname(os.path.realpath(__file__))
 
 class mock_response:
 
-    def __init__(self, headers, text, status, content=None):
+    def __init__(self, headers, text, status, url, content=None):
         self.headers = headers
         self.text = text
+        self.url = url
         
         if content is None:
 
@@ -80,7 +81,23 @@ class TestMementoResource(unittest.TestCase):
                             """.format(expected_original_uri, expected_urig, urim)
                     },
                     text = expected_content,
-                    status=200
+                    status=200,
+                    url = urim
+                ),
+            expected_urig: # requests follows all redirects, so we present the result at the end of the chain
+                mock_response(
+                    headers = {
+                        'content-type': 'text/html',
+                        'memento-datetime': "Fri, 22 Jun 2018 21:16:36 GMT",
+                        'link': """<{}>; rel="original", 
+                            <{}>; rel="timegate",
+                            <http://myarchive.org/timemap/http://example.com/something>; rel="timemap",
+                            <{}>; rel="memento"
+                            """.format(expected_original_uri, expected_urig, urim)
+                    },
+                    text = expected_content,
+                    status=200,
+                    url = urim
                 )
         }
 
@@ -142,7 +159,8 @@ class TestMementoResource(unittest.TestCase):
                             """.format(expected_original_uri, expected_urig, urim)
                     },
                     text = expected_content,
-                    status=200
+                    status=200,
+                    url = urim
                 ),
             raw_urim:
                 mock_response(
@@ -150,7 +168,8 @@ class TestMementoResource(unittest.TestCase):
                         'content-type': 'text/html'
                     },
                     text = expected_raw_content,
-                    status=200
+                    status=200,
+                    url = raw_urim
                 )
         }
 
@@ -212,7 +231,8 @@ class TestMementoResource(unittest.TestCase):
                             """.format(expected_original_uri, expected_urig, urim)
                     },
                     text = expected_content,
-                    status=200
+                    status=200,
+                    url = urim
                 ),
             raw_urim:
                 mock_response(
@@ -220,7 +240,8 @@ class TestMementoResource(unittest.TestCase):
                         'content-type': 'text/html'
                     },
                     text = expected_raw_content,
-                    status=200
+                    status=200,
+                    url = raw_urim
                 )
         }
 
@@ -292,7 +313,8 @@ class TestMementoResource(unittest.TestCase):
                             """.format(expected_original_uri, expected_urig, urim)
                     },
                     text = expected_content,
-                    status=200
+                    status=200,
+                    url = urim
                 ),
             zipurim:
                 mock_response(
@@ -301,7 +323,8 @@ class TestMementoResource(unittest.TestCase):
                     },
                     text = "",
                     content = zip_content,
-                    status=200
+                    status=200,
+                    url = zipurim
                 )
         }
 
@@ -356,13 +379,15 @@ class TestMementoResource(unittest.TestCase):
                             """.format(urir, expected_urig, urim)
                     },
                     text = content,
-                    status=200
+                    status=200,
+                    url = urim
                 ),
             raw_urim:
                 mock_response(
                     headers = {},
                     text = "",
-                    status = 404
+                    status = 404,
+                    url = raw_urim
                 )
         }
 
@@ -382,13 +407,15 @@ class TestMementoResource(unittest.TestCase):
                             """.format(expected_urig, urim)
                     },
                     text = content,
-                    status=200
+                    status=200,
+                    url = urim
                 ),
             raw_urim:
                 mock_response(
                     headers = {},
                     text = "",
-                    status = 404
+                    status = 404,
+                    url = raw_urim
                 )
         }
 
@@ -403,13 +430,15 @@ class TestMementoResource(unittest.TestCase):
                         'memento-datetime': "Sat, 02 Feb 2008 06:29:13 GMT"
                         },
                     text = content,
-                    status=200
+                    status=200,
+                    url = urim
                 ),
             raw_urim:
                 mock_response(
                     headers = {},
                     text = "",
-                    status = 404
+                    status = 404,
+                    url = raw_urim
                 )
         }
 
@@ -446,13 +475,15 @@ class TestMementoResource(unittest.TestCase):
                             """.format(expected_original_uri, expected_urig, urim)
                     },
                     text = expected_content,
-                    status=200
+                    status=200,
+                    url = urim
                 ),
             "http://archive.is/20130508132946id_/http://flexispy.com/":
                 mock_response(
                     headers = {},
                     text= "",
-                    status=404
+                    status=404,
+                    url = "http://archive.is/20130508132946id_/http://flexispy.com/"
                 ),
             zipurim:
                 mock_response(
@@ -461,7 +492,8 @@ class TestMementoResource(unittest.TestCase):
                     },
                     text = "",
                     content = zip_content,
-                    status=200
+                    status=200,
+                    url = zipurim
                 )
         }
 
@@ -519,7 +551,8 @@ class TestMementoResource(unittest.TestCase):
                     },
                     text = metaredirecthtml,
                     content = metaredirecthtml,
-                    status = 200
+                    status = 200,
+                    url = urim
                 ),
             redirurim: 
                 mock_response(
@@ -534,7 +567,8 @@ class TestMementoResource(unittest.TestCase):
                     },
                     text = expected_content,
                     content = expected_content,
-                    status = 200
+                    status = 200,
+                    url = redirurim
                 ),
             redirurim_raw: 
                 mock_response(
@@ -543,7 +577,8 @@ class TestMementoResource(unittest.TestCase):
                     },
                     text = expected_raw_content,
                     content = expected_raw_content,
-                    status = 200
+                    status = 200,
+                    url = redirurim_raw
                 )
         }
 
@@ -564,46 +599,16 @@ class TestMementoResource(unittest.TestCase):
         self.assertEqual(mr.content, expected_content)
         self.assertEqual(mr.raw_content, expected_raw_content)
 
-    def test_waybackframesets(self):
-
-        # TODO: rework this test so that it passes
-        self.skipTest("Integration tests work, but this unit test does not produce the correct behavior")
-
-        urim = "http://myarchive.org/memento/20080202062913/http://example.com/something"
-        urir = "http://example.com/something"
-        raw_urim = "http://myarchive.org/memento/20080202062913id_/http://example.com/something"
-        expected_urig = "http://myarchive.org/timegate/http://example.com/something"
-        expected_original_uri = "http://example.com/something"
-
-        content = """
-        <html>
-            <head>
-                <title>Is this a good title?</title>
-            </head>
-                <!-- ARCHIVE SPECIFIC STUFF -->
-                <frameset rows="*" cols="130,*" framespacing="0" border="0">
-                    <frame src="frame1.htm">
-                    <frame src="pages/frame2.htm">
-                    <frame src="/content/frame3.htm">
-                    <frame src="http://example2.com/content/frame4.htm">
-                </frameset>
-        </html>"""
+    def test_permacc_hashstyle_uris(self):
 
-        raw_content = """
-        <html>
-            <head>
-                <title>Is this a good title?</title>
-            </head>
-                <frameset rows="*" cols="130,*" framespacing="0" border="0">
-                    <frame src="frame1.htm">
-                    <frame src="pages/frame2.htm">
-                    <frame src="/content/frame3.htm">
-                    <frame src="http://example2.com/content/frame4.htm">
-                </frameset>
-        </html>"""
+        urim = "http://perma.cc/RZP7-3P4P"
+        expected_original_uri = "http://www.environment.gov.au/minister/hunt/2014/mr20141215a.html"
+        expected_urim = "https://perma-archives.org/warc/20151028031045/http://www.environment.gov.au/minister/hunt/2014/mr20141215a.html"
+        expected_raw_uri = "https://perma-archives.org/warc/20151028031045id_/http://www.environment.gov.au/minister/hunt/2014/mr20141215a.html"
+        expected_urig = "https://perma-archives.org/warc/timegate/http://www.environment.gov.au/minister/hunt/2014/mr20141215a.html"
 
-        timegate_stem = "http://myarchive.org/timegate/"
-        memento_stem = "http://myarchive.org/memento/"
+        expected_content = "hi"
+        expected_raw_content = "hi there"
 
         cachedict = {
             urim:
@@ -617,79 +622,57 @@ class TestMementoResource(unittest.TestCase):
                             <{}>; rel="memento"
                             """.format(expected_original_uri, expected_urig, urim)
                     },
-                    text = content,
-                    status=200
-                ),
-            raw_urim:
-                mock_response(
-                    headers = {
-                        'content-type': 'text/html'
-                    },
-                    text = raw_content,
-                    status=200
+                    text = expected_content,
+                    status=200,
+                    url = urim
                 ),
-            "{}/{}".format(memento_stem, urljoin(urir, "frame1.htm")):
+            expected_raw_uri:
                 mock_response(
                     headers = {
-                        'content-type': 'text/html'
+                        'content-type': 'text/html',
+                        'memento-datetime': "Sat, 02 Feb 2008 06:29:13 GMT",
+                        'link': """<{}>; rel="original", 
+                            <{}>; rel="timegate",
+                            <http://myarchive.org/timemap/http://example.com/something>; rel="timemap",
+                            <{}>; rel="memento"
+                            """.format(expected_original_uri, expected_urig, expected_urim)
                     },
-                    text = "<html><body><p>frame1</p></body></html>",
-                    status=200
-                ),
-            "{}{}".format(timegate_stem, urljoin(urir, "frame1.htm")):
-                mock_response(
-                    headers = { 'location':  "{}/{}".format(memento_stem, urljoin(urir, "frame1.htm")) },
-                    text = "",
-                    status=302
-                ),
-            "{}{}".format(memento_stem, urljoin(urir, "pages/frame2.htm")):
-                mock_response(
-                    headers = {},
-                    text = "<html><body><div>frame2</div></body></html>",
-                    status=200
-                ),
-            "{}{}".format(timegate_stem, urljoin(urir, "pages/frame2.htm")):
-                mock_response(
-                    headers = { 'location':  "{}{}".format(memento_stem, urljoin(urir, "pages/frame2.htm")) },
-                    text = "",
-                    status=302
-                ),
-            "{}{}".format(memento_stem, urljoin(urir, "/content/frame3.htm")):
-                mock_response(
-                    headers = {},
-                    text = "<html><body><span><p>frame3</p></span></body></html>",
-                    status=200
-                ),
-            "{}{}".format(timegate_stem, urljoin(urir, "/content/frame3.htm")):
-                mock_response(
-                    headers = { 'location': "{}{}".format(memento_stem, urljoin(urir, "/content/frame3.htm")) },
-                    text = "",
-                    status=302
+                    text = expected_raw_content,
+                    status = 200,
+                    url = expected_raw_uri
                 ),
-            "http://myarchive.org/memento/20080202062913/http://example2.com/content/frame4.htm":
+            expected_urig: # requests follows all redirects, so we present the result at the end of the chain
                 mock_response(
-                    headers = {},
-                    text = "<html><body><div><span><p>frame4</p></span></div></body></html>",
-                    status=200
+                    headers = { 
+                        'content-type': 'text/html',
+                        'memento-datetime': "Sat, 02 Feb 2008 06:29:13 GMT",
+                        'link': """<{}>; rel="original", 
+                            <{}>; rel="timegate",
+                            <http://myarchive.org/timemap/http://example.com/something>; rel="timemap",
+                            <{}>; rel="memento"
+                            """.format(expected_original_uri, expected_urig, expected_urim)
+                     },
+                    text = expected_content,
+                    status = 200, # after following redirects
+                    url = expected_urim
                 ),
-            "{}{}".format(timegate_stem, "http://example2.com/content/frame4.htm"):
+            expected_urim:
                 mock_response(
-                    headers = { 'location': "http://myarchive.org/memento/20080202062913/http://example2.com/content/frame4.htm" },
-                    text = "",
-                    status=302
+                    headers = { 
+                        'content-type': 'text/html',
+                        'memento-datetime': "Sat, 02 Feb 2008 06:29:13 GMT",
+                        'link': """<{}>; rel="original", 
+                            <{}>; rel="timegate",
+                            <http://myarchive.org/timemap/http://example.com/something>; rel="timemap",
+                            <{}>; rel="memento"
+                            """.format(expected_original_uri, expected_urig, expected_urim)
+                     },
+                    text = expected_content,
+                    status = 200, # after following redirects
+                    url = expected_urim
                 )
-
         }
 
-        expected_raw_content = """<html><head><title>Is this a good title?</title></head><body>
-<p>frame1</p>
-<div>frame2</div>
-<span><p>frame3</p></span>
-<div><span><p>frame4</p></span></div>
-</body></html>"""
-
-        expected_content = expected_raw_content
-
         mh = mock_httpcache(cachedict)
 
         mr = memento_resource_factory(urim, mh)
@@ -707,4 +690,149 @@ class TestMementoResource(unittest.TestCase):
         self.assertEqual(mr.timegate, expected_urig)
         self.assertEqual(mr.original_uri, expected_original_uri)
         self.assertEqual(mr.content, expected_content)
-        self.assertEqual(mr.raw_content, expected_raw_content)
\ No newline at end of file
+        self.assertEqual(mr.raw_content, expected_raw_content)
+
+#     def test_waybackframesets(self):
+
+#         # TODO: rework this test so that it passes
+#         self.skipTest("Integration tests work, but this unit test does not produce the correct behavior")
+
+#         urim = "http://myarchive.org/memento/20080202062913/http://example.com/something"
+#         urir = "http://example.com/something"
+#         raw_urim = "http://myarchive.org/memento/20080202062913id_/http://example.com/something"
+#         expected_urig = "http://myarchive.org/timegate/http://example.com/something"
+#         expected_original_uri = "http://example.com/something"
+
+#         content = """
+#         <html>
+#             <head>
+#                 <title>Is this a good title?</title>
+#             </head>
+#                 <!-- ARCHIVE SPECIFIC STUFF -->
+#                 <frameset rows="*" cols="130,*" framespacing="0" border="0">
+#                     <frame src="frame1.htm">
+#                     <frame src="pages/frame2.htm">
+#                     <frame src="/content/frame3.htm">
+#                     <frame src="http://example2.com/content/frame4.htm">
+#                 </frameset>
+#         </html>"""
+
+#         raw_content = """
+#         <html>
+#             <head>
+#                 <title>Is this a good title?</title>
+#             </head>
+#                 <frameset rows="*" cols="130,*" framespacing="0" border="0">
+#                     <frame src="frame1.htm">
+#                     <frame src="pages/frame2.htm">
+#                     <frame src="/content/frame3.htm">
+#                     <frame src="http://example2.com/content/frame4.htm">
+#                 </frameset>
+#         </html>"""
+
+#         timegate_stem = "http://myarchive.org/timegate/"
+#         memento_stem = "http://myarchive.org/memento/"
+
+#         cachedict = {
+#             urim:
+#                 mock_response(
+#                     headers = {
+#                         'content-type': 'text/html',
+#                         'memento-datetime': "Sat, 02 Feb 2008 06:29:13 GMT",
+#                         'link': """<{}>; rel="original", 
+#                             <{}>; rel="timegate",
+#                             <http://myarchive.org/timemap/http://example.com/something>; rel="timemap",
+#                             <{}>; rel="memento"
+#                             """.format(expected_original_uri, expected_urig, urim)
+#                     },
+#                     text = content,
+#                     status=200
+#                 ),
+#             raw_urim:
+#                 mock_response(
+#                     headers = {
+#                         'content-type': 'text/html'
+#                     },
+#                     text = raw_content,
+#                     status=200
+#                 ),
+#             "{}/{}".format(memento_stem, urljoin(urir, "frame1.htm")):
+#                 mock_response(
+#                     headers = {
+#                         'content-type': 'text/html'
+#                     },
+#                     text = "<html><body><p>frame1</p></body></html>",
+#                     status=200
+#                 ),
+#             "{}{}".format(timegate_stem, urljoin(urir, "frame1.htm")):
+#                 mock_response(
+#                     headers = { 'location':  "{}/{}".format(memento_stem, urljoin(urir, "frame1.htm")) },
+#                     text = "",
+#                     status=302
+#                 ),
+#             "{}{}".format(memento_stem, urljoin(urir, "pages/frame2.htm")):
+#                 mock_response(
+#                     headers = {},
+#                     text = "<html><body><div>frame2</div></body></html>",
+#                     status=200
+#                 ),
+#             "{}{}".format(timegate_stem, urljoin(urir, "pages/frame2.htm")):
+#                 mock_response(
+#                     headers = { 'location':  "{}{}".format(memento_stem, urljoin(urir, "pages/frame2.htm")) },
+#                     text = "",
+#                     status=302
+#                 ),
+#             "{}{}".format(memento_stem, urljoin(urir, "/content/frame3.htm")):
+#                 mock_response(
+#                     headers = {},
+#                     text = "<html><body><span><p>frame3</p></span></body></html>",
+#                     status=200
+#                 ),
+#             "{}{}".format(timegate_stem, urljoin(urir, "/content/frame3.htm")):
+#                 mock_response(
+#                     headers = { 'location': "{}{}".format(memento_stem, urljoin(urir, "/content/frame3.htm")) },
+#                     text = "",
+#                     status=302
+#                 ),
+#             "http://myarchive.org/memento/20080202062913/http://example2.com/content/frame4.htm":
+#                 mock_response(
+#                     headers = {},
+#                     text = "<html><body><div><span><p>frame4</p></span></div></body></html>",
+#                     status=200
+#                 ),
+#             "{}{}".format(timegate_stem, "http://example2.com/content/frame4.htm"):
+#                 mock_response(
+#                     headers = { 'location': "http://myarchive.org/memento/20080202062913/http://example2.com/content/frame4.htm" },
+#                     text = "",
+#                     status=302
+#                 )
+
+#         }
+
+#         expected_raw_content = """<html><head><title>Is this a good title?</title></head><body>
+# <p>frame1</p>
+# <div>frame2</div>
+# <span><p>frame3</p></span>
+# <div><span><p>frame4</p></span></div>
+# </body></html>"""
+
+#         expected_content = expected_raw_content
+
+#         mh = mock_httpcache(cachedict)
+
+#         mr = memento_resource_factory(urim, mh)
+
+#         expected_mdt = datetime.strptime(
+#             "Sat, 02 Feb 2008 06:29:13 GMT", 
+#             "%a, %d %b %Y %H:%M:%S GMT"
+#         )
+
+#         self.maxDiff = None
+
+#         self.assertEqual(type(mr), WaybackMemento)
+
+#         self.assertEqual(mr.memento_datetime, expected_mdt)
+#         self.assertEqual(mr.timegate, expected_urig)
+#         self.assertEqual(mr.original_uri, expected_original_uri)
+#         self.assertEqual(mr.content, expected_content)
+#         self.assertEqual(mr.raw_content, expected_raw_content)
\ No newline at end of file
diff --git a/tests/test_originalresource.py b/tests/test_originalresource.py
index 1112582..6f2e84e 100644
--- a/tests/test_originalresource.py
+++ b/tests/test_originalresource.py
@@ -64,14 +64,29 @@ class TestOriginalResource(unittest.TestCase):
                     },
                     text = expected_content,
                     status=200,
-                    url = "testing-url://notused"
+                    url = urim
+                ),
+            expected_urig:
+                mock_response(
+                    headers = {
+                        'content-type': 'text/html',
+                        'memento-datetime': "Fri, 22 Jun 2018 21:16:36 GMT",
+                        'link': """<{}>; rel="original", 
+                            <{}>; rel="timegate",
+                            <http://myarchive.org/timemap/http://example.com/something>; rel="timemap",
+                            <{}>; rel="memento"
+                            """.format(expected_original_uri, expected_urig, urim)
+                    },
+                    text = expected_content,
+                    status=200,
+                    url = urim
                 ),
             expected_original_uri:
                 mock_response(
                     headers = {},
                     text = "",
                     status=404,
-                    url = "testing-url://notused"
+                    url = expected_original_uri
                 )
         }
 
@@ -115,7 +130,22 @@ class TestOriginalResource(unittest.TestCase):
                     },
                     text = expected_content,
                     status=200,
-                    url = "testing-url://notused"
+                    url = urim
+                ),
+            expected_urig:
+                mock_response(
+                    headers = {
+                        'content-type': 'text/html',
+                        'memento-datetime': "Fri, 22 Jun 2018 21:16:36 GMT",
+                        'link': """<{}>; rel="original", 
+                            <{}>; rel="timegate",
+                            <http://myarchive.org/timemap/http://example.com/something>; rel="timemap",
+                            <{}>; rel="memento"
+                            """.format(expected_original_uri, expected_urig, urim)
+                    },
+                    text = expected_content,
+                    status=200,
+                    url = urim
                 ),
             expected_original_uri:
                 mock_response(
@@ -124,7 +154,7 @@ class TestOriginalResource(unittest.TestCase):
                     },
                     text = "",
                     status=200,
-                    url = "testing-url://notused"
+                    url = expected_original_uri
                 )
         }
 
@@ -145,6 +175,7 @@ class TestOriginalResource(unittest.TestCase):
         expected_original_uri = "http://example.com/something"
         expected_favicon = "http://myarchive.org/memento/http://example.com/content/favicon.ico"
         original_favicon = "http://example.com/content/favicon.ico"
+        favicon_urig = "http://myarchive.org/timegate/http://example.com/favicon.ico"
 
         expected_content = """
         <html>
@@ -171,7 +202,22 @@ class TestOriginalResource(unittest.TestCase):
                     },
                     text = expected_content,
                     status=200,
-                    url = "testing-url://notused"
+                    url = urim
+                ),
+            expected_urig:
+                mock_response(
+                    headers = {
+                        'content-type': 'text/html',
+                        'memento-datetime': "Fri, 22 Jun 2018 21:16:36 GMT",
+                        'link': """<{}>; rel="original", 
+                            <{}>; rel="timegate",
+                            <http://myarchive.org/timemap/http://example.com/something>; rel="timemap",
+                            <{}>; rel="memento"
+                            """.format(expected_original_uri, expected_urig, urim)
+                    },
+                    text = expected_content,
+                    status=200,
+                    url = urim
                 ),
             expected_original_uri:
                 mock_response(
@@ -180,21 +226,28 @@ class TestOriginalResource(unittest.TestCase):
                     },
                     text = "",
                     status=200,
-                    url = "testing-url://notused"
+                    url = expected_original_uri
                 ),
             "http://myarchive.org/timegate/http://example.com/content/favicon.ico":
                 mock_response(
                     headers = {"location": expected_favicon},
                     text = "",
-                    status = 302,
-                    url = "testing-url://notused"
+                    status = 200,
+                    url = expected_favicon
+                ),
+            favicon_urig:
+                mock_response(
+                    headers = {'content-type': 'image/'},
+                    text = "a",
+                    status=200,
+                    url = expected_favicon
                 ),
             expected_favicon:
                 mock_response(
                     headers = {'content-type': 'image/'},
                     text = "a",
                     status=200,
-                    url = "testing-url://notused"
+                    url = expected_favicon
                 )
 
         }