Skip to content

Commit ee23e8f

Browse files
Jade WibbelsJade Wibbels
authored andcommitted
updated conftest added lint to github actions
1 parent a3b004a commit ee23e8f

File tree

7 files changed

+35
-21
lines changed

7 files changed

+35
-21
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@ jobs:
4040

4141
- name: Run tests
4242
run: |
43-
pytest
43+
pytest
44+
45+
- name: Lint code
46+
run: |
47+
make lint

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ share/python-wheels/
2525
.installed.cfg
2626
*.egg
2727
MANIFEST
28-
package/
28+
package
2929

3030
# PyInstaller
3131
# Usually these files are written by a python script from a template

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
[tool.black]
22
line-length = 100
3+
exclude = '''
4+
/(
5+
package
6+
| venv
7+
)/
8+
'''

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[flake8]
2-
exclude = venv
3-
max-line-length = 100
2+
exclude = venv, package
3+
max-line-length = 100

tests/conftest.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import pytest
2-
from app.main import app
2+
from botocore.stub import Stubber
33
from fastapi.testclient import TestClient
44

5+
from app.main import app
6+
57

68
@pytest.fixture
79
def client():
810
with TestClient(app) as client:
911
yield client
12+
13+
14+
@pytest.fixture
15+
def mock_dynamodb(request):
16+
table = request.param
17+
with Stubber(table.meta.client) as stubber:
18+
yield stubber
19+
stubber.assert_no_pending_responses()

tests/routes/test_posts.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import pytest
2-
from botocore.stub import Stubber
32

43
from app.routes.posts import table
54

65

7-
@pytest.fixture
8-
def mock_dynamodb():
9-
with Stubber(table.meta.client) as stubber:
10-
yield stubber
11-
stubber.assert_no_pending_responses()
12-
13-
6+
@pytest.mark.parametrize("mock_dynamodb", [table], indirect=True)
147
def test_read_posts(client, mock_dynamodb):
158
mock_dynamodb.add_response(
169
"scan",
@@ -34,6 +27,7 @@ def test_read_posts(client, mock_dynamodb):
3427
]
3528

3629

30+
@pytest.mark.parametrize("mock_dynamodb", [table], indirect=True)
3731
def test_read_post(client, mock_dynamodb):
3832
mock_dynamodb.add_response(
3933
"get_item",
@@ -58,6 +52,7 @@ def test_read_post(client, mock_dynamodb):
5852
}
5953

6054

55+
@pytest.mark.parametrize("mock_dynamodb", [table], indirect=True)
6156
def test_create_post(client, mock_dynamodb):
6257
post_data = {
6358
"Id": "2",
@@ -74,6 +69,7 @@ def test_create_post(client, mock_dynamodb):
7469
assert response.json() == {"message": "Post created"}
7570

7671

72+
@pytest.mark.parametrize("mock_dynamodb", [table], indirect=True)
7773
def test_update_post(client, mock_dynamodb):
7874
post_data = {
7975
"Id": "1",
@@ -108,6 +104,7 @@ def test_update_post(client, mock_dynamodb):
108104
assert response.json() == {"message": "Post with id 1 updated", "updated_attributes": post_data}
109105

110106

107+
@pytest.mark.parametrize("mock_dynamodb", [table], indirect=True)
111108
def test_delete_post(client, mock_dynamodb):
112109
mock_dynamodb.add_response(
113110
"delete_item",

tests/routes/test_users.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import pytest
2-
from botocore.stub import Stubber
32

43
from app.routes.users import table
54

65

7-
@pytest.fixture
8-
def mock_dynamodb():
9-
with Stubber(table.meta.client) as stubber:
10-
yield stubber
11-
stubber.assert_no_pending_responses()
12-
13-
6+
@pytest.mark.parametrize("mock_dynamodb", [table], indirect=True)
147
def test_read_users(client, mock_dynamodb):
158
mock_dynamodb.add_response(
169
"scan",
@@ -38,6 +31,7 @@ def test_read_users(client, mock_dynamodb):
3831
]
3932

4033

34+
@pytest.mark.parametrize("mock_dynamodb", [table], indirect=True)
4135
def test_read_user(client, mock_dynamodb):
4236
mock_dynamodb.add_response(
4337
"get_item",
@@ -64,6 +58,7 @@ def test_read_user(client, mock_dynamodb):
6458
}
6559

6660

61+
@pytest.mark.parametrize("mock_dynamodb", [table], indirect=True)
6762
def test_create_user(client, mock_dynamodb):
6863
user_data = {
6964
"Id": "2",
@@ -79,6 +74,7 @@ def test_create_user(client, mock_dynamodb):
7974
assert response.json() == {"message": "User created"}
8075

8176

77+
@pytest.mark.parametrize("mock_dynamodb", [table], indirect=True)
8278
def test_update_user(client, mock_dynamodb):
8379
user_data = {
8480
"Id": "1",
@@ -107,6 +103,7 @@ def test_update_user(client, mock_dynamodb):
107103
assert response.json() == {"message": "User with id 1 updated", "updated_attributes": user_data}
108104

109105

106+
@pytest.mark.parametrize("mock_dynamodb", [table], indirect=True)
110107
def test_delete_user(client, mock_dynamodb):
111108
mock_dynamodb.add_response(
112109
"delete_item",

0 commit comments

Comments
 (0)