diff --git a/requirements-dev.txt b/requirements-dev.txt index 35cfc87..21e346f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,7 +1,8 @@ click==7.1.2 pytest==7.4.2 pytest-cov==4.1.0 -flake8 -safety -pip-audit -selenium +flake8==6.1.0 +safety==1.10.3 +pip-audit==2.6.1 +selenium==4.14.0 +responses==0.23.3 diff --git a/tests/conftest.py b/tests/conftest.py index db3df8e..d643886 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ import os import pytest +import responses from selenium import webdriver from selenium.webdriver.chrome.options import Options @@ -35,6 +36,12 @@ def db(app): sqlalchemy_db.drop_all() +@pytest.fixture() +def mocker(): + with responses.RequestsMock() as rsps: + yield rsps + + @pytest.fixture() def driver(): options = Options() diff --git a/tests/unit/test_hello.py b/tests/unit/test_hello.py index 7d262e5..f1069e6 100644 --- a/tests/unit/test_hello.py +++ b/tests/unit/test_hello.py @@ -36,6 +36,22 @@ def test_db_rollback(db): assert User.query.filter_by(name='test').first() is None +def test_mocking(mocker): + """ + Test that api mocking works + """ + import requests + mocker.get( + "http://xyz.com/api/1/foobar", + body="{}", + status=200, + content_type="application/json", + ) + resp = requests.get("http://xyz.com/api/1/foobar") + assert resp.status_code == 200 + assert resp.json() == {} + + def test_multiple_fixtures(app, client, db): """ Test that multiple fixtures work