-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating increase / decrease quantity views functions :
** this code depends on suppliers.html code which hasn't been merged yes once the code is merged i will change it ** two functions has been created : which increase and decrease the quantity of a product by it's supplier *** modifie the code so it increase / decrease the quantity by "n" not one
- Loading branch information
1 parent
d7e3128
commit a984014
Showing
5 changed files
with
38 additions
and
114 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 |
---|---|---|
@@ -1,39 +1,26 @@ | ||
from django.test import TestCase, Client | ||
from django.test import Client | ||
from django.urls import reverse | ||
from .models import SupplierProduct, Product, Supplier | ||
from django.contrib.auth.models import User | ||
from .models import SupplierProduct | ||
import pytest | ||
|
||
|
||
@pytest.mark.django_db() | ||
class IncreaseQuantityTest(TestCase): | ||
def setUp(self): | ||
# Create a test client | ||
self.client = Client() | ||
# Create a test user | ||
self.user = User.objects.create_user(username='testuser', password='testpassword') | ||
self.supplier = Supplier.objects.create(supplier_account=self.user) | ||
self.product = Product.objects.create(product_name='product1') | ||
self.supplier_product = SupplierProduct.objects.create( | ||
supplier_product_id=1, | ||
qr_code=self.product, | ||
user_name=self.supplier, | ||
price=100, | ||
quantity=10 | ||
) | ||
def test_increase_quantity(saved_supplier_product0): | ||
supplier_product = saved_supplier_product0 | ||
client = Client() | ||
n=3 | ||
response = client.get(reverse('supplier_product:increase_quantity', kwargs={'id': supplier_product.supplier_product_id, 'n': n})) | ||
updated_product = SupplierProduct.objects.get(supplier_product_id=supplier_product.supplier_product_id) | ||
assert updated_product.quantity == supplier_product.quantity + n | ||
assert response.status_code == 302 | ||
|
||
def increase_quantity_by_one(self): | ||
response = self.client.get( | ||
reverse( | ||
'supplier_product:increase_quantity_by_one', kwargs={'id': self.supplier_product.supplier_product_id})) | ||
updated_product = SupplierProduct.objects.get(supplier_product_id=self.supplier_product.supplier_product_id) | ||
self.assertEqual(updated_product.quantity, self.supplier_product.quantity + 1) | ||
self.assertEqual(response.status_code, 302) | ||
@pytest.mark.django_db() | ||
def test_decrease_quantity(saved_supplier_product0): | ||
supplier_product = saved_supplier_product0 | ||
client = Client() | ||
n = 3 | ||
response = client.get(reverse('supplier_product:decrease_quantity', kwargs={'id': supplier_product.supplier_product_id, 'n': n})) | ||
updated_product = SupplierProduct.objects.get(supplier_product_id=supplier_product.supplier_product_id) | ||
assert updated_product.quantity == supplier_product.quantity - n | ||
assert response.status_code == 302 | ||
|
||
def decrease_quantity_by_one(self): | ||
response = self.client.get( | ||
reverse( | ||
'supplier_product:decrease_quantity_by_one', kwargs={'id': self.supplier_product.supplier_product_id})) | ||
updated_product = SupplierProduct.objects.get(supplier_product_id=self.supplier_product.supplier_product_id) | ||
self.assertEqual(updated_product.quantity, self.supplier_product.quantity - 1) | ||
self.assertEqual(response.status_code, 302) |
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 was deleted.
Oops, something went wrong.