Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7066400
D2133.id7230.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Subscribers
None
D2133.id7230.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:
@@ -54,7 +54,15 @@
will look the content of the response in:
- datadir/nowhere.com/path_to_resource,a=b,c=d
+ datadir/https_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
@@ -76,7 +84,9 @@
context.status_code = 404
return None
url = urlparse(request.url)
- dirname = url.hostname # pypi.org | files.pythonhosted.org
+ # http://pypi.org ~> http_pypi.org
+ # https://files.pythonhosted.org ~> https_files.pythonhosted.org
+ dirname = '%s_%s' % (url.scheme, url.hostname)
# url.path: pypi/<project>/json -> local file: pypi_<project>_json
filename = url.path[1:]
if filename.endswith('/'):
@@ -159,10 +169,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/data/example.com/file.json b/swh/core/tests/data/https_example.com/file.json
rename from swh/core/tests/data/example.com/file.json
rename to swh/core/tests/data/https_example.com/file.json
diff --git a/swh/core/tests/data/example.com/file.json,name=doe,firstname=jane b/swh/core/tests/data/https_example.com/file.json,name=doe,firstname=jane
rename from swh/core/tests/data/example.com/file.json,name=doe,firstname=jane
rename to swh/core/tests/data/https_example.com/file.json,name=doe,firstname=jane
diff --git a/swh/core/tests/data/example.com/file.json_visit1 b/swh/core/tests/data/https_example.com/file.json_visit1
rename from swh/core/tests/data/example.com/file.json_visit1
rename to swh/core/tests/data/https_example.com/file.json_visit1
diff --git a/swh/core/tests/data/example.com/other.json b/swh/core/tests/data/https_example.com/other.json
rename from swh/core/tests/data/example.com/other.json
rename to swh/core/tests/data/https_example.com/other.json
diff --git a/swh/core/tests/fixture/data/example.com/file.json b/swh/core/tests/fixture/data/https_example.com/file.json
rename from swh/core/tests/fixture/data/example.com/file.json
rename to swh/core/tests/fixture/data/https_example.com/file.json
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
Nov 5 2024, 7:49 AM (8 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3230036
Attached To
D2133: pytest_plugin: Add support for http request (debian lister related)
Event Timeline
Log In to Comment