Skip to content

Commit

Permalink
Feat: Add Test Mocking Lib (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reimirno authored Nov 3, 2023
1 parent 64d3635 commit f5b8de9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
9 changes: 5 additions & 4 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import pytest
import responses
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

Expand Down Expand Up @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test_hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5b8de9

Please sign in to comment.