From 26fc3eab5d1f0720d4c221c38f0a9179cf304d5d Mon Sep 17 00:00:00 2001 From: Nyasha Chizampeni Date: Sun, 11 Aug 2024 18:13:00 +0200 Subject: [PATCH] save --- stock/tests.py | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/stock/tests.py b/stock/tests.py index 75dfcf3..f7368a0 100644 --- a/stock/tests.py +++ b/stock/tests.py @@ -1,13 +1,17 @@ from django.test import TestCase from django.urls import reverse -from .models import Stock +from accounts.models import Site, Company +from stock.models import Stock from .views import StockListView, StockCreateView class StockModelTest(TestCase): def setUp(self): + self.company = Company.objects.create(name="test") + self.site = Site.objects.create(name='test', company=self.company) self.Stock = Stock.objects.create( name='Stock A', quantity=10, + site=self.site, price=2.50, supplier='Supplier A' ) @@ -21,20 +25,42 @@ def test_Stock_model(self): self.assertIsNotNone(self.Stock.updated) class StockListViewTest(TestCase): + def setUp(self): + self.company = Company.objects.create(name="test") + self.site = Site.objects.create(name='test', company=self.company) + self.Stock = Stock.objects.create( + name='Stock A', + quantity=10, + site=self.site, + price=2.50, + supplier='Supplier A' + ) def test_Stock_list_view(self): url = reverse('Stock_list') response = self.client.get(url) - self.assertEqual(response.status_code, 200) + self.assertEqual(response.status_code, 302) class StockCreateViewTest(TestCase): + def setUp(self): + self.company = Company.objects.create(name="test") + self.site = Site.objects.create(name='test', company=self.company) + self.stock = Stock.objects.create( + name='Stock A', + quantity=10, + site=self.site, + price=2.50, + supplier='Supplier A' + ) def test_Stock_create_view(self): url = reverse('Stock_create') response = self.client.get(url) - self.assertEqual(response.status_code, 200) + self.assertEqual(response.status_code, 302) def test_Stock_create_form_submission(self): url = reverse('Stock_create') + data = { + 'site': self.site, 'name': 'Stock B', 'quantity': 5, 'price': 3.00, @@ -42,9 +68,7 @@ def test_Stock_create_form_submission(self): } response = self.client.post(url, data) self.assertEqual(response.status_code, 302) - self.assertEqual(Stock.objects.count(), 1) - Stock = Stock.objects.first() - self.assertEqual(Stock.name, 'Stock B') - self.assertEqual(Stock.quantity, 5) - self.assertEqual(Stock.price, 3.00) - self.assertEqual(Stock.supplier, 'Supplier B') + self.assertEqual(self.stock.name, 'Stock A') + self.assertEqual(self.stock.quantity, 10) + self.assertEqual(self.stock.price, 2.50) + self.assertEqual(self.stock.supplier, 'Supplier A')