Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9696287
D2133.id7228.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D2133.id7228.diff
View Options
diff --git a/swh/core/pytest_plugin.py b/swh/core/pytest_plugin.py
--- a/swh/core/pytest_plugin.py
+++ b/swh/core/pytest_plugin.py
@@ -44,9 +44,9 @@
Eg. if you use the requests_mock fixture in your test file as:
- requests_mock.get('https://nowhere.com', body=get_response_cb)
+ requests_mock.get('https?://nowhere.com', body=get_response_cb)
# or even
- requests_mock.get(re.compile('https://'), body=get_response_cb)
+ requests_mock.get(re.compile('https?://'), body=get_response_cb)
then a call requests.get like:
@@ -56,6 +56,14 @@
datadir/nowhere.com/path_to_resource,a=b,c=d
+ or a call requests.get like:
+
+ requests.get('http://nowhere.com/path/to/resource?a=b&c=d')
+
+ will look the content of the response in:
+
+ datadir/http_nowhere.com/path_to_resource,a=b,c=d
+
Args:
request (requests.Request): Object requests
context (requests.Context): Object holding response metadata
@@ -76,7 +84,12 @@
context.status_code = 404
return None
url = urlparse(request.url)
- dirname = url.hostname # pypi.org | files.pythonhosted.org
+ if url.scheme == 'http':
+ # http://pypi.org ~> http_pypi.org
+ dirname = '%s_%s' % (url.scheme, url.hostname)
+ else: # FIXME: Use the same policy for both scheme when ready
+ # https://f.p.org ~> f.p.org
+ dirname = url.hostname
# url.path: pypi/<project>/json -> local file: pypi_<project>_json
filename = url.path[1:]
if filename.endswith('/'):
@@ -159,10 +172,10 @@
cb = partial(get_response_cb,
ignore_urls=ignore_urls,
datadir=datadir)
- requests_mock.get(re.compile('https://'), body=cb)
+ requests_mock.get(re.compile('https?://'), body=cb)
else:
visits = {}
- requests_mock.get(re.compile('https://'), body=partial(
+ requests_mock.get(re.compile('https?://'), body=partial(
get_response_cb, ignore_urls=ignore_urls, visits=visits,
datadir=datadir)
)
diff --git a/swh/core/tests/data/http_example.com/something.json b/swh/core/tests/data/http_example.com/something.json
new file mode 100644
--- /dev/null
+++ b/swh/core/tests/data/http_example.com/something.json
@@ -0,0 +1 @@
+"something"
diff --git a/swh/core/tests/test_pytest_plugin.py b/swh/core/tests/test_pytest_plugin.py
--- a/swh/core/tests/test_pytest_plugin.py
+++ b/swh/core/tests/test_pytest_plugin.py
@@ -15,6 +15,10 @@
assert response.ok
assert response.json() == {'hello': 'you'}
+ response = requests.get('http://example.com/something.json')
+ assert response.ok
+ assert response.json() == "something"
+
response = requests.get('https://example.com/file.json')
assert response.ok
assert response.json() == {'hello': 'world'}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Aug 17, 7:42 PM (1 w, 5 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3229876
Attached To
D2133: pytest_plugin: Add support for http request (debian lister related)
Event Timeline
Log In to Comment