-
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.
redirect product changes to new branch
- Loading branch information
1 parent
4c6f8e8
commit 6861bbc
Showing
1 changed file
with
0 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +0,0 @@ | ||
import pytest | ||
from django.urls import reverse | ||
from rest_framework import status | ||
from rest_framework.test import APIClient | ||
from users.models import User | ||
from inventory.models import Product | ||
|
||
@pytest.fixture | ||
def api_client(): | ||
return APIClient() | ||
|
||
@pytest.fixture | ||
def admin_user(db): | ||
return User.objects.create_user(email='[email protected]', username='admin', password='admin123', is_staff=True) | ||
|
||
@pytest.fixture | ||
def regular_user(db): | ||
return User.objects.create_user(username='user',email='[email protected]', password='user123') | ||
|
||
@pytest.fixture | ||
def product_data(): | ||
return { | ||
'name': 'Test Product', | ||
'description': 'Test Description', | ||
'quantity': 10, | ||
'price': 100.0 | ||
} | ||
|
||
@pytest.mark.django_db | ||
def test_admin_can_create_product(api_client, admin_user, product_data): | ||
url = reverse('product_add') | ||
api_client.force_authenticate(user=admin_user) | ||
response = api_client.post(url, product_data, format='json') | ||
assert response.status_code == status.HTTP_201_CREATED | ||
assert response.data['name'] == product_data['name'] | ||
assert response.data['description'] == product_data['description'] | ||
assert response.data['quantity'] == product_data['quantity'] | ||
assert response.data['price'] == product_data['price'] | ||
|
||
# @pytest.mark.django_db | ||
# def test_non_admin_cannot_create_product(api_client, regular_user, product_data): | ||
# url = reverse('product_add') | ||
# api_client.force_authenticate(user=regular_user) | ||
# response = api_client.post(url, product_data, format='json') | ||
# assert response.status_code == status.HTTP_403_FORBIDDEN | ||
|
||
# @pytest.mark.django_db | ||
# def test_create_product_with_invalid_data(api_client, admin_user, product_data): | ||
# url = reverse('product_add') | ||
# api_client.force_authenticate(user=admin_user) | ||
# invalid_data = product_data.copy() | ||
# invalid_data['price'] = -100 # Invalid price | ||
# response = api_client.post(url, invalid_data, format='json') | ||
# assert response.status_code == status.HTTP_400_BAD_REQUEST | ||
# assert 'price' in response.data | ||
|
||
# @pytest.mark.django_db | ||
# def test_unauthenticated_user_cannot_create_product(api_client, product_data): | ||
# url = reverse('product_add') | ||
# response = api_client.post(url, product_data, format='json') | ||
# assert response.status_code == status.HTTP_401_UNAUTHORIZED | ||