-
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.
Merge pull request #61 from dev-lymar/kroshkaview
Kroshkaview
- Loading branch information
Showing
8 changed files
with
210 additions
and
18 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
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,14 @@ | ||
from rest_framework import serializers | ||
|
||
|
||
class OrderItemSerializer(serializers.Serializer): # type: ignore | ||
product_id = serializers.IntegerField() | ||
quantity = serializers.IntegerField() | ||
discount = serializers.IntegerField(required=False, default=0) | ||
|
||
|
||
class DataDocSerializer(serializers.Serializer): # type: ignore | ||
client_id = serializers.IntegerField() | ||
items = serializers.ListField(child=OrderItemSerializer()) | ||
factory_id = serializers.IntegerField() | ||
destination = serializers.CharField() |
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,19 @@ | ||
import pytest | ||
from rest_framework.test import APIClient | ||
from rest_framework_simplejwt.tokens import RefreshToken | ||
|
||
from users.models import CustomUser | ||
|
||
|
||
@pytest.fixture | ||
def user(django_user_model): | ||
return CustomUser.objects.create_user(email='test@example.com', full_name='Test User', | ||
password='testpassword') | ||
|
||
|
||
@pytest.fixture | ||
def authorized_client(user): | ||
client = APIClient() | ||
refresh = RefreshToken.for_user(user) | ||
client.credentials(HTTP_AUTHORIZATION=f"Bearer {str(refresh.access_token)}") | ||
return client |
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,52 @@ | ||
import pytest | ||
from django.urls import reverse | ||
from rest_framework.test import APIClient | ||
|
||
|
||
@pytest.mark.django_db | ||
def test__data_view__unauthorized_user_cannot_post_data() -> None: | ||
client = APIClient() | ||
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 = client.post(url, data, format='json') | ||
assert response.status_code == 401 # Unauthorized | ||
|
||
|
||
@pytest.mark.django_db | ||
def test__goods__authorized_user_can_post_data(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.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 |
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,7 +1,9 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
from .views import DataDocView | ||
|
||
urlpatterns = [ | ||
path("filemake/", views.create_docs, name="file"), | ||
path("data/", DataDocView.as_view(), name="data"), | ||
] |
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