Skip to content

Commit

Permalink
Merge pull request #10 from Horlawhumy-dev/fix-api-doc
Browse files Browse the repository at this point in the history
made changes
  • Loading branch information
Horlawhumy-dev authored Jul 4, 2024
2 parents 6378fe1 + 6861bbc commit 3456817
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 63 deletions.
4 changes: 2 additions & 2 deletions inventory/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
app_name = 'inventory'

urlpatterns = [
path('products', InventoryProductList.as_view(), name='product_list'),
path('products/', InventoryProductCreate.as_view(), name='product_add'),
path('products/', InventoryProductList.as_view(), name='product_list'),
path('products/add/', InventoryProductCreate.as_view(), name='product_add'), #test required to distinguish url not only with slash
path('products/<str:pk>/', InventoryProductDetail.as_view(), name='product_detail'),
path('orders/', OrderListCreate.as_view(), name='order_list_create'),
path('orders/<str:pk>/', OrderDetail.as_view(), name='order_detail'),
Expand Down
1 change: 1 addition & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
_#!/bin/bash
export PYTHONPATH=./
rm -rf db.sqlite3
make migrate
pytest
61 changes: 0 additions & 61 deletions test/test_product.py
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

0 comments on commit 3456817

Please sign in to comment.