Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
nyashaChiza committed Aug 11, 2024
1 parent 1636430 commit 26fc3ea
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions stock/tests.py
Original file line number Diff line number Diff line change
@@ -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'
)
Expand All @@ -21,30 +25,50 @@ 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,
'supplier': 'Supplier B'
}
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')

0 comments on commit 26fc3ea

Please sign in to comment.