-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14de900
commit 792627d
Showing
6 changed files
with
32 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 19 additions & 13 deletions
32
tests/apps/companies/services/test_materials_statistic_validator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
import pytest | ||
|
||
from rest_framework.exceptions import ValidationError | ||
from rest_framework.request import Request | ||
|
||
from django.http.request import QueryDict | ||
|
||
from companies.services import DateValidatorService | ||
|
||
|
||
def test_valid_date_params(mock_request: Request, material_date_query_params: dict[str, str]): | ||
mock_request.query_params = material_date_query_params # type: ignore | ||
def test_valid_date_params(material_date_query_params: dict[str, str]): | ||
query_params = QueryDict(mutable=True) | ||
query_params.update(**material_date_query_params) | ||
|
||
assert DateValidatorService(mock_request)() is True | ||
assert DateValidatorService(query_params)() is True | ||
|
||
|
||
def test_only_date_from_param(mock_request: Request, material_date_query_params: dict[str, str]): | ||
def test_only_date_from_param(material_date_query_params: dict[str, str]): | ||
del material_date_query_params["date_to"] | ||
mock_request.query_params = material_date_query_params # type: ignore | ||
query_params = QueryDict(mutable=True) | ||
query_params.update(**material_date_query_params) | ||
|
||
assert DateValidatorService(mock_request)() is True | ||
assert DateValidatorService(query_params)() is True | ||
|
||
|
||
def test_only_date_to_param(mock_request: Request, material_date_query_params: dict[str, str]): | ||
def test_only_date_to_param(material_date_query_params: dict[str, str]): | ||
del material_date_query_params["date_from"] | ||
mock_request.query_params = material_date_query_params # type: ignore | ||
query_params = QueryDict(mutable=True) | ||
query_params.update(**material_date_query_params) | ||
|
||
assert DateValidatorService(query_params)() is True | ||
|
||
assert DateValidatorService(mock_request)() is True | ||
|
||
def test_invalid_date_params(invalide_material_date_query_params: dict[str, str]): | ||
query_params = QueryDict(mutable=True) | ||
query_params.update(**invalide_material_date_query_params) | ||
|
||
def test_invalid_date_params(mock_request: Request, invalide_material_date_query_params: dict[str, str]): | ||
mock_request.query_params = invalide_material_date_query_params # type: ignore | ||
with pytest.raises(ValidationError): | ||
DateValidatorService(mock_request)() | ||
DateValidatorService(query_params)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
from tests.fixtures.apps.app.api import as_anon, as_superuser, as_user, mock_request | ||
from tests.fixtures.apps.app.api import as_anon, as_superuser, as_user | ||
from tests.fixtures.apps.app.factory import factory | ||
|
||
__all__ = [ | ||
"as_anon", | ||
"as_superuser", | ||
"as_user", | ||
"factory", | ||
"mock_request", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters