Skip to content

Commit

Permalink
refactor and split tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-lymar committed Jun 5, 2024
1 parent e7db6f3 commit 2992215
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
5 changes: 0 additions & 5 deletions makedoc/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ def user(django_user_model):
password='testpassword')


@pytest.fixture
def api_client() -> APIClient:
return APIClient()


@pytest.fixture
def authorized_client(user):
client = APIClient()
Expand Down
22 changes: 19 additions & 3 deletions makedoc/tests/test_views_makedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


@pytest.mark.django_db
def test_data_doc_view_status_code(api_client: APIClient) -> None:
def test__data_view__unauthorized_user_cannot_post_data() -> None:
client = APIClient()
url = reverse('data')
data = {
"client_id": 123,
Expand All @@ -15,12 +16,12 @@ def test_data_doc_view_status_code(api_client: APIClient) -> None:
"factory_id": 1,
"destination": "New York"
}
response = api_client.post(url, data, format='json')
response = client.post(url, data, format='json')
assert response.status_code == 401 # Unauthorized


@pytest.mark.django_db
def test_data_doc_view_response_data(authorized_client) -> None:
def test__goods__authorized_user_can_post_data(authorized_client) -> None:
url = reverse('data')
data = {
"client_id": 123,
Expand All @@ -33,4 +34,19 @@ def test_data_doc_view_response_data(authorized_client) -> None:
}
response = authorized_client.post(url, data, format='json')
assert response.status_code == 200


@pytest.mark.django_db
def test__goods__authorized_user_post_data_response_is_correct(authorized_client) -> None:
url = reverse('data')
data = {
"client_id": 123,
"items": [
{"product_id": 1, "quantity": 2, "discount": 10},
{"product_id": 2, "quantity": 5, "discount": 4}
],
"factory_id": 1,
"destination": "New York"
}
response = authorized_client.post(url, data, format='json')
assert response.json() == data

0 comments on commit 2992215

Please sign in to comment.