Skip to content
Permalink
Browse files

fixes for link header problems identified in #136

  • Loading branch information...
shawnmjones committed Oct 11, 2018
1 parent 1246756 commit 190c8c0cd7b19103c39feb12cf835ddc19313638
Showing with 173 additions and 24 deletions.
  1. +6 −4 mementoembed/mementoresource.py
  2. +110 −13 tests/test_mementoresource.py
  3. +57 −7 tests/test_originalresource.py
@@ -105,8 +105,9 @@ def get_timegate_from_response(response):
urig = None

try:
urig = aiu.convert_LinkTimeMap_to_dict(
response.headers['link'] )['timegate_uri']
# urig = aiu.convert_LinkTimeMap_to_dict(
# response.headers['link'] )['timegate_uri']
urig = response.links['timegate']['url']
except KeyError as e:
raise NotAMementoError(
"link header coult not be parsed for timegate URI",
@@ -119,8 +120,9 @@ def get_original_uri_from_response(response):
urir = None

try:
urir = aiu.convert_LinkTimeMap_to_dict(
response.headers['link'] )['original_uri']
# urir = aiu.convert_LinkTimeMap_to_dict(
# response.headers['link'] )['original_uri']
urir = response.links['original']['url']
except KeyError as e:
raise NotAMementoError(
"link header coult not be parsed for original URI",
@@ -13,10 +13,11 @@

class mock_response:

def __init__(self, headers, text, status, url, content=None):
def __init__(self, headers, text, status, url, content=None, links={}):
self.headers = headers
self.text = text
self.url = url
self.links = links

if content is None:

@@ -82,7 +83,15 @@ def test_simplecase(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
expected_urig: # requests follows all redirects, so we present the result at the end of the chain
mock_response(
@@ -97,7 +106,15 @@ def test_simplecase(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
)
}

@@ -160,7 +177,15 @@ def test_waybackcase(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
raw_urim:
mock_response(
@@ -232,7 +257,15 @@ def test_imfcase(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
raw_urim:
mock_response(
@@ -314,7 +347,15 @@ def test_archiveiscase(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
zipurim:
mock_response(
@@ -476,7 +517,15 @@ def test_archiveiscase_datetime_in_uri(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
"http://archive.is/20130508132946id_/http://flexispy.com/":
mock_response(
@@ -552,7 +601,15 @@ def test_meta_redirect(self):
text = metaredirecthtml,
content = metaredirecthtml,
status = 200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
redirurim:
mock_response(
@@ -568,7 +625,15 @@ def test_meta_redirect(self):
text = expected_content,
content = expected_content,
status = 200,
url = redirurim
url = redirurim,
links = {
"original": {
"url": redir_expected_original_uri
},
"timegate": {
"url": redir_expected_urig
}
}
),
redirurim_raw:
mock_response(
@@ -624,7 +689,15 @@ def test_permacc_hashstyle_uris(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
expected_raw_uri:
mock_response(
@@ -639,7 +712,15 @@ def test_permacc_hashstyle_uris(self):
},
text = expected_raw_content,
status = 200,
url = expected_raw_uri
url = expected_raw_uri,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
expected_urig: # requests follows all redirects, so we present the result at the end of the chain
mock_response(
@@ -654,7 +735,15 @@ def test_permacc_hashstyle_uris(self):
},
text = expected_content,
status = 200, # after following redirects
url = expected_urim
url = expected_urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
expected_urim:
mock_response(
@@ -669,7 +758,15 @@ def test_permacc_hashstyle_uris(self):
},
text = expected_content,
status = 200, # after following redirects
url = expected_urim
url = expected_urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
)
}

@@ -5,7 +5,7 @@

class mock_response:

def __init__(self, headers, text, status, url, content=None):
def __init__(self, headers, text, status, url, content=None, links={}):
self.headers = headers
self.text = text
if content is None:
@@ -16,6 +16,8 @@ def __init__(self, headers, text, status, url, content=None):
self.status_code = status
self.url = url

self.links = links

class mock_httpcache:
"""
rather than hitting the actual HTTP cache,
@@ -64,7 +66,15 @@ def test_simplecase_rotten_resource(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
expected_urig:
mock_response(
@@ -79,7 +89,15 @@ def test_simplecase_rotten_resource(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
expected_original_uri:
mock_response(
@@ -130,7 +148,15 @@ def test_simplecase_live_resource(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
expected_urig:
mock_response(
@@ -145,7 +171,15 @@ def test_simplecase_live_resource(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
expected_original_uri:
mock_response(
@@ -202,7 +236,15 @@ def test_favicon_from_html(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
expected_urig:
mock_response(
@@ -217,7 +259,15 @@ def test_favicon_from_html(self):
},
text = expected_content,
status=200,
url = urim
url = urim,
links = {
"original": {
"url": expected_original_uri
},
"timegate": {
"url": expected_urig
}
}
),
expected_original_uri:
mock_response(

0 comments on commit 190c8c0

Please sign in to comment.
You can’t perform that action at this time.