Skip to content

Commit 0528e5b

Browse files
committed
fix: add types to fixtures
1 parent 2216c0a commit 0528e5b

File tree

10 files changed

+72
-20
lines changed

10 files changed

+72
-20
lines changed

api/src/data_providers/clients/ClientInterface.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import abstractmethod
2-
from typing import Generic, List, TypeVar
2+
from typing import Dict, Generic, List, Optional, TypeVar
33

44
# Type definition for Model
55
M = TypeVar("M")
@@ -32,3 +32,15 @@ def update(self, id: K, instance: M) -> M:
3232
@abstractmethod
3333
def insert_many(self, instances: List[M]):
3434
pass
35+
36+
@abstractmethod
37+
def delete_many(self, query: Dict):
38+
pass
39+
40+
@abstractmethod
41+
def find(self, filters: Dict) -> M:
42+
pass
43+
44+
@abstractmethod
45+
def find_one(self, filters: Dict) -> Optional[M]:
46+
pass
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pytest
22
from starlette.status import HTTP_200_OK
3+
from starlette.testclient import TestClient
34

45
pytestmark = pytest.mark.integration
56

67

78
class TestTodo:
8-
def test_get(self, test_app):
9+
def test_get(self, test_app: TestClient):
910
response = test_app.get("/health-check")
1011
assert response.status_code == HTTP_200_OK
1112
assert response.content == b"OK"

api/src/tests/integration/features/todo/test_todo_feature.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import pytest
22
from starlette.status import HTTP_200_OK, HTTP_422_UNPROCESSABLE_ENTITY
3+
from starlette.testclient import TestClient
4+
5+
from data_providers.clients.ClientInterface import ClientInterface
36

47
pytestmark = pytest.mark.integration
58

69

710
class TestTodo:
811
@pytest.fixture(autouse=True)
9-
def setup_database(self, test_client):
12+
def setup_database(self, test_client: ClientInterface):
1013
test_client.insert_many(
1114
[
1215
{"_id": "1", "id": "1", "title": "title 1"},
1316
{"_id": "2", "id": "2", "title": "title 2"},
1417
]
1518
)
1619

17-
def test_get_todo_all(self, test_app):
20+
def test_get_todo_all(self, test_app: TestClient):
1821
response = test_app.get("/todos")
1922
items = response.json()
2023

@@ -25,21 +28,21 @@ def test_get_todo_all(self, test_app):
2528
assert items[1]["id"] == "2"
2629
assert items[1]["title"] == "title 2"
2730

28-
def test_get_todo_by_id(self, test_app):
31+
def test_get_todo_by_id(self, test_app: TestClient):
2932
response = test_app.get("/todos/1")
3033

3134
assert response.status_code == HTTP_200_OK
3235
assert response.json()["id"] == "1"
3336
assert response.json()["title"] == "title 1"
3437

35-
def test_add_todo(self, test_app):
38+
def test_add_todo(self, test_app: TestClient):
3639
response = test_app.post("/todos", json={"title": "title 3"})
3740
item = response.json()
3841

3942
assert response.status_code == HTTP_200_OK
4043
assert item["title"] == "title 3"
4144

42-
def test_add_todo_should_return_unprocessable_when_invalid_entity(self, test_app):
45+
def test_add_todo_should_return_unprocessable_when_invalid_entity(self, test_app: TestClient):
4346
response = test_app.post("/todos", json=None)
4447

4548
assert response.status_code == HTTP_422_UNPROCESSABLE_ENTITY
@@ -50,12 +53,12 @@ def test_update_todo(self, test_app):
5053
assert response.status_code == HTTP_200_OK
5154
assert response.json()["success"]
5255

53-
def test_update_todo_should_return_unprocessable_when_invalid_entity(self, test_app):
56+
def test_update_todo_should_return_unprocessable_when_invalid_entity(self, test_app: TestClient):
5457
response = test_app.put("/todos/1", json={"title": ""})
5558

5659
assert response.status_code == HTTP_422_UNPROCESSABLE_ENTITY
5760

58-
def test_delete_todo(self, test_app):
61+
def test_delete_todo(self, test_app: TestClient):
5962
response = test_app.delete("/todos/1")
6063

6164
assert response.status_code == HTTP_200_OK

api/src/tests/integration/features/whoami/test_whoami_feature.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
from starlette.status import HTTP_200_OK
3+
from starlette.testclient import TestClient
34

45
from authentication.mock_token_generator import generate_mock_token
56
from authentication.models import User
@@ -9,7 +10,7 @@
910

1011

1112
class TestWhoami:
12-
def test_whoami(self, test_app):
13+
def test_whoami(self, test_app: TestClient):
1314
config.AUTH_ENABLED = True
1415
config.TEST_TOKEN = True
1516
user = User(user_id=1, username="foo", roles=["a"])
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import pytest
22
from pydantic.error_wrappers import ValidationError
33

4+
from data_providers.repository_interfaces.TodoRepositoryInterface import (
5+
TodoRepositoryInterface,
6+
)
47
from features.todo.use_cases.add_todo import AddTodoRequest, add_todo_use_case
58

69

7-
def test_add_with_valid_title_should_return_todo(todo_repository):
10+
def test_add_with_valid_title_should_return_todo(todo_repository: TodoRepositoryInterface):
811
data = AddTodoRequest(title="new todo")
912
result = add_todo_use_case(data, todo_repository=todo_repository)
1013
assert result.title == data.title
1114

1215

13-
def test_add_with_empty_title_should_throw_validation_error(todo_repository):
16+
def test_add_with_empty_title_should_throw_validation_error(todo_repository: TodoRepositoryInterface):
1417
with pytest.raises(ValidationError):
1518
data = AddTodoRequest(title="")
1619
add_todo_use_case(data, todo_repository=todo_repository)
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import pytest as pytest
22

33
from common.exceptions import NotFoundException
4+
from data_providers.repository_interfaces.TodoRepositoryInterface import (
5+
TodoRepositoryInterface,
6+
)
47
from features.todo.use_cases.delete_todo_by_id import (
58
DeleteTodoByIdResponse,
69
delete_todo_use_case,
710
)
811

912

10-
def test_delete_todo_should_return_success(todo_repository):
13+
def test_delete_todo_should_return_success(todo_repository: TodoRepositoryInterface):
1114
id = "dh2109"
1215
result: DeleteTodoByIdResponse = delete_todo_use_case(id=id, todo_repository=todo_repository)
1316
assert result.success
1417

1518

16-
def test_delete_todo_should_return_not_success(todo_repository):
19+
def test_delete_todo_should_return_not_success(todo_repository: TodoRepositoryInterface):
1720
id = "unkown"
1821
with pytest.raises(NotFoundException) as error:
1922
delete_todo_use_case(id=id, todo_repository=todo_repository)
20-
assert error.message == "The todo item you specified does not exist."
23+
assert error.value.message == "The todo item you specified does not exist."
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
from typing import Dict
2+
3+
from data_providers.repository_interfaces.TodoRepositoryInterface import (
4+
TodoRepositoryInterface,
5+
)
16
from features.todo.use_cases.get_todo_all import get_todo_all_use_case
27

38

4-
def test_get_todos_should_return_todos(todo_repository, todo_test_data):
9+
def test_get_todos_should_return_todos(todo_repository: TodoRepositoryInterface, todo_test_data: Dict[str, dict]):
510
todos = get_todo_all_use_case(todo_repository=todo_repository)
611
assert len(todos) == len(todo_test_data.keys())
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1+
from typing import Dict
2+
13
import pytest as pytest
24

35
from common.exceptions import NotFoundException
6+
from data_providers.repository_interfaces.TodoRepositoryInterface import (
7+
TodoRepositoryInterface,
8+
)
49
from features.todo.use_cases.get_todo_by_id import (
510
GetTodoByIdResponse,
611
get_todo_by_id_use_case,
712
)
813

914

10-
def test_get_todo_by_id_should_return_todo(todo_repository, todo_test_data):
15+
def test_get_todo_by_id_should_return_todo(todo_repository: TodoRepositoryInterface, todo_test_data: Dict[str, dict]):
1116
id = "dh2109"
1217
todo: GetTodoByIdResponse = get_todo_by_id_use_case(id, todo_repository=todo_repository)
1318
assert todo.title == todo_test_data[id]["title"]
1419

1520

16-
def test_get_todo_by_id_should_throw_todo_not_found_error(todo_repository):
21+
def test_get_todo_by_id_should_throw_todo_not_found_error(todo_repository: TodoRepositoryInterface):
1722
id = "unknown"
1823
with pytest.raises(NotFoundException) as error:
1924
get_todo_by_id_use_case(id, todo_repository=todo_repository)
20-
assert error.message == "The todo item you specified does not exist."
25+
assert error.value.message == "The todo item you specified does not exist."

api/src/tests/unit/features/todo/use_cases/test_update_todo.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
from data_providers.repository_interfaces.TodoRepositoryInterface import (
2+
TodoRepositoryInterface,
3+
)
14
from features.todo.use_cases.update_todo import UpdateTodoRequest, update_todo_use_case
25

36

4-
def test_update_todos_should_return_success(todo_repository, todo_test_data):
7+
def test_update_todos_should_return_success(todo_repository: TodoRepositoryInterface):
58
id = "dh2109"
69
data = UpdateTodoRequest(title="new title", is_completed=False)
710
result = update_todo_use_case(id, data, todo_repository=todo_repository)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Use case
2+
3+
There will be one use case for each individual action/command of an actor. An actor is a person or another system that interacts with our application. Typically, it will be a regular user.
4+
5+
## Examples
6+
7+
For a meetup.com clone, it could be:
8+
9+
* Confirming attendance as an attendee
10+
* Cancelling attendance as an attendee
11+
* Drafting new meeting as an organizer
12+
13+
## Related concepts
14+
15+
16+

0 commit comments

Comments
 (0)