-
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
Showing
5 changed files
with
143 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,54 @@ | |
from rest_framework.test import APIClient | ||
from rest_framework.authtoken.models import Token | ||
|
||
from apps.prices.models import DealerPrice | ||
from apps.prices.services import create_prices | ||
|
||
from .utils import TEST_PRICE_DATA | ||
|
||
|
||
@pytest.fixture | ||
def user(django_user_model): | ||
"""Тестовый пользователь оператор.""" | ||
return django_user_model.objects.create_user( | ||
email="[email protected]", password="Password-123" | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def user_token(user): | ||
"""Токен для оператора.""" | ||
token = Token.objects.create(user=user) | ||
return token.key | ||
|
||
|
||
@pytest.fixture | ||
def user_client(user_token): | ||
"""Аутентифицированный клиент-оператор.""" | ||
client = APIClient() | ||
client.credentials(HTTP_AUTHORIZATION=f"Token {user_token}") | ||
return client | ||
|
||
|
||
@pytest.fixture | ||
def price(): | ||
"""Цена для ключа с указанным продуктом.""" | ||
return DealerPrice.objects.create( | ||
key_id=1, | ||
price=233, | ||
name="Средство универсальное Prosept Universal Spray, 500мл", | ||
date="2023-07-14", | ||
product_url=( | ||
"https://akson.ru//p/sredstvo_universalnoe" | ||
"_prosept_universal_spray_500ml/" | ||
), | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def price2(): | ||
"""Цена для ключа без подобранного продукта.""" | ||
create_prices(price_data=TEST_PRICE_DATA) | ||
key = TEST_PRICE_DATA[0]["product_key"] | ||
dealer_id = TEST_PRICE_DATA[0]["dealer_id"] | ||
return DealerPrice.objects.get(key__key=key, key__dealer_id=dealer_id) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from http import HTTPStatus | ||
|
||
import pytest | ||
from rest_framework.test import APIClient | ||
|
||
from apps.prices.services import create_prices | ||
|
||
from .utils import TEST_PRICE_DATA | ||
|
||
|
||
@pytest.mark.django_db() | ||
class Test04DealerPrice: | ||
url = "/api/v1/prices/" | ||
|
||
def test_01_load_prices_fail(self, user_client: APIClient) -> None: | ||
"""Создание цен и попытка загрузки цен из файла.""" | ||
create_prices(TEST_PRICE_DATA) | ||
response = user_client.post(self.url) | ||
assert response.status_code == HTTPStatus.BAD_REQUEST | ||
|
||
def test_02_delete_prices_from_db(self, user_client: APIClient) -> None: | ||
"""Удаление всех цен и связанных объектов из базы данных.""" | ||
|
||
response = user_client.delete(self.url) | ||
assert response.status_code == HTTPStatus.NO_CONTENT |
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