Skip to content

Commit

Permalink
Merge branch 'mr/ramonat/get-rid-of-httpretty' into 'master'
Browse files Browse the repository at this point in the history
Remove httpretty dependency

See merge request it/e3-core!99
  • Loading branch information
enzbang committed Jan 23, 2025
2 parents 64ffd67 + 4e0f233 commit f791962
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ test = [
"pytest-html",
"pytest-socket",
"ansi2html",
"httpretty",
# set urllib version because urllib3>=2.3.0 breaks httpretty (https://github.com/gabrielfalcao/HTTPretty/issues/484)
"urllib3<2.3.0",
"ptyprocess; sys_platform!='win32'",
"requests-mock"
]
Expand Down
53 changes: 27 additions & 26 deletions tests/tests_e3/store/main_test.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import os

from unittest.mock import patch, MagicMock
from e3.store.backends.http_simple_store import HTTPSimpleStore
from e3.store.cache.backends.filecache import FileCache

import httpretty
import httpretty.core
FAKE_BODY_CONTENT = b"a body content"


def mock_download() -> MagicMock:
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.headers = {
"content-disposition": 'attachment; filename="foo.tar.gz"',
"Content-Length": str(len(FAKE_BODY_CONTENT)),
}
mock_response.iter_content = lambda chunk_size: iter([FAKE_BODY_CONTENT])
return mock_response


def test_simple_store(caplog):
"""Basic test of HTTPSimpleStore."""
with httpretty.core.httprettized():
httpretty.HTTPretty.allow_net_connect = False

httpretty.register_uri(
httpretty.GET,
"http://test.example",
body="a body content",
content_disposition='attachment; filename="foo.tar.gz"',
)
query = {
"url": "http://test.example",
"sha": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
}
query = {
"url": "http://test.example",
"sha": "da39a3ee5e6b4b0d3255bfef95601890afd80709",
}

store = HTTPSimpleStore({}, None)

store = HTTPSimpleStore({}, None)
with patch("e3.net.http.requests.Session.request") as mock_request:
mock_request.return_value = mock_download()

# Store a wrong sha (= sha1sum of an empty string)
metadata = store.get_resource_metadata(query)
assert {metadata.url, metadata.sha} == set(query.values())

Expand All @@ -32,6 +38,7 @@ def test_simple_store(caplog):
assert path is None
assert "expecting da39a3ee5e6b4b0d3255bfef95601890afd80709 got" in caplog.text

# Fix sha (sha1sum of "a body content")
metadata.sha = "0c8ef1a401f4564abba7b85676464ac4bbb5cb05"
path = store.download_resource_content(metadata, current_dir)
assert path is not None
Expand All @@ -40,15 +47,9 @@ def test_simple_store(caplog):
def test_store_with_cache():
"""Test HTTPSimpleStore with a FileCache."""
fc = FileCache({"cache_dir": os.path.join(os.getcwd(), "cache")})
with httpretty.core.httprettized():
httpretty.HTTPretty.allow_net_connect = False

httpretty.register_uri(
httpretty.GET,
"http://test.example",
body="a body content",
content_disposition='attachment; filename="foo.tar.gz"',
)

with patch("e3.net.http.requests.Session.request") as mock_request:
mock_request.return_value = mock_download()

query = {
"url": "http://test.example",
Expand Down

0 comments on commit f791962

Please sign in to comment.