Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add pytest-socket to make sure that we don't call external API in tests (#9101)

Maciej Korycinskid0d7a18c2fbf
diff --git a/poetry.lock b/poetry.lock
index 28168cdf73..4685f672ec 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -2030,6 +2030,17 @@ pytest = ">=5.0"
[package.extras]
dev = ["pre-commit", "tox", "pytest-asyncio"]
+[[package]]
+name = "pytest-socket"
+version = "0.5.1"
+description = "Pytest Plugin to disable socket calls during tests"
+category = "dev"
+optional = false
+python-versions = ">=3.7,<4.0"
+
+[package.dependencies]
+pytest = ">=3.6.3"
+
[[package]]
name = "pytest-vcr"
version = "1.0.2"
@@ -2755,7 +2766,7 @@ python-versions = "*"
[metadata]
lock-version = "1.1"
python-versions = "~3.9"
-content-hash = "de8d1ace4577a79066f08dd560f7c49082c18cccbd39356a7361ee0f7410b4c6"
+content-hash = "a93f3de9fa343e30e981356cc8049ccae38d41237de7bca541c0e44a73bf7837"
[metadata.files]
adyen = [
@@ -4015,6 +4026,10 @@ pytest-mock = [
{file = "pytest-mock-3.7.0.tar.gz", hash = "sha256:5112bd92cc9f186ee96e1a92efc84969ea494939c3aead39c50f421c4cc69534"},
{file = "pytest_mock-3.7.0-py3-none-any.whl", hash = "sha256:6cff27cec936bf81dc5ee87f07132b807bcda51106b5ec4b90a04331cba76231"},
]
+pytest-socket = [
+ {file = "pytest-socket-0.5.1.tar.gz", hash = "sha256:7c4b81dc6a51cbc0093f11791de00ff4a15ac698f5da96879a80f5d9ad4179b6"},
+ {file = "pytest_socket-0.5.1-py3-none-any.whl", hash = "sha256:8726fd47b83b127451532b6d570c5b6c4cd204fca363936509b1f53195de6f4f"},
+]
pytest-vcr = [
{file = "pytest-vcr-1.0.2.tar.gz", hash = "sha256:23ee51b75abbcc43d926272773aae4f39f93aceb75ed56852d0bf618f92e1896"},
{file = "pytest_vcr-1.0.2-py2.py3-none-any.whl", hash = "sha256:2f316e0539399bea0296e8b8401145c62b6f85e9066af7e57b6151481b0d6d9c"},
diff --git a/pyproject.toml b/pyproject.toml
index b040515ecc..1d720181e5 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -119,6 +119,7 @@ documentation = "https://docs.saleor.io/"
types-python-dateutil = "^2.8.0"
# django-stubs locked to 1.8.0 due to https://github.com/typeddjango/django-stubs/issues/700
django-stubs = "1.8.0"
+ pytest-socket = "^0.5.1"
[tool.black]
target_version = [ "py35", "py36", "py37", "py38" ]
diff --git a/requirements_dev.txt b/requirements_dev.txt
index 76461e9bab..2ac5c6fc94 100644
--- a/requirements_dev.txt
+++ b/requirements_dev.txt
@@ -1,3 +1,4 @@
+
adyen==4.0.0
amqp==5.0.9; python_version >= "3.7"
aniso8601==7.0.0
@@ -28,7 +29,7 @@ click-repl==0.2.0; python_version >= "3.6"
click==7.1.2; python_full_version >= "3.6.2" and python_version >= "3.6" and (python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0") and (python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6") and python_full_version < "4.0.0"
codecov==2.1.12; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
colorama==0.4.4; sys_platform == "win32" and python_full_version >= "3.6.2" and (python_version >= "3.6" and python_full_version < "3.0.0" and sys_platform == "win32" or sys_platform == "win32" and python_version >= "3.6" and python_full_version >= "3.5.0") and (python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0") and (python_version >= "2.7" and python_full_version < "3.0.0" and platform_system == "Windows" or python_full_version >= "3.5.0" and platform_system == "Windows")
-coverage==6.3; python_version >= "3.7"
+coverage==6.3.1; python_version >= "3.7"
cryptography==36.0.1; python_version >= "3.6"
cssselect2==0.4.1; python_version >= "3.6"
deprecated==1.2.13; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version >= "3.6"
@@ -157,6 +158,7 @@ pytest-django-queries==1.2.0
pytest-django==4.5.2; python_version >= "3.5"
pytest-forked==1.4.0; python_version >= "3.6"
pytest-mock==3.7.0; python_version >= "3.7"
+pytest-socket==0.5.1; python_version >= "3.7" and python_version < "4.0"
pytest-vcr==1.0.2
pytest-xdist==2.5.0; python_version >= "3.6"
pytest==6.2.5; python_version >= "3.6"
@@ -215,7 +217,7 @@ vine==5.0.0; python_version >= "3.7"
virtualenv==20.13.0; python_full_version >= "3.6.1"
watchgod==0.7; python_version >= "3.5"
wcwidth==0.2.5; python_full_version >= "3.6.2" and python_version >= "3.6"
-weasyprint==54.0; python_version >= "3.6"
+weasyprint==54.1; python_version >= "3.6"
webencodings==0.5.1; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
websockets==8.1; python_full_version >= "3.6.1"
wrapt==1.13.3; python_full_version >= "3.6.2" and python_version >= "3.5" and (python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6")
diff --git a/saleor/graphql/core/tests/test_core.py b/saleor/graphql/core/tests/test_core.py
index 59838b3ae4..5f7aee6434 100644
--- a/saleor/graphql/core/tests/test_core.py
+++ b/saleor/graphql/core/tests/test_core.py
@@ -10,6 +10,7 @@ from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.core.files.uploadedfile import SimpleUploadedFile
from django.utils import timezone
from graphene import InputField
+from micawber import ProviderException, ProviderRegistry
from PIL import Image
from ....core.utils.validators import get_oembed_data
@@ -402,7 +403,9 @@ def test_get_oembed_data(url, expected_media_type):
"http://onet.pl/",
],
)
-def test_get_oembed_data_unsupported_media_provider(url):
[email protected](ProviderRegistry, "request")
+def test_get_oembed_data_unsupported_media_provider(mocked_provider, url):
+ mocked_provider.side_effect = ProviderException()
with pytest.raises(
ValidationError, match="Unsupported media provider or incorrect URL."
):
diff --git a/setup.cfg b/setup.cfg
index 0f35d794b2..e4a0a9ab36 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -16,7 +16,7 @@ exclude_lines =
if TYPE_CHECKING:
[tool:pytest]
-addopts = -n auto --vcr-record-mode=none --ds=saleor.tests.settings
+addopts = -n auto --vcr-record-mode=none --ds=saleor.tests.settings --disable-socket
testpaths = saleor
filterwarnings =
ignore::DeprecationWarning