This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
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.
- Loading branch information
1 parent
6763b93
commit f5ea6f7
Showing
5 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
Empty file.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from django.test import TestCase | ||
from dashboard.models import Menu | ||
from branches.models import Branch | ||
from orders.models import Order, PaymentMethod | ||
from orders.forms import OrderPlaceForm | ||
|
||
|
||
class OrderPlaceFormTest(TestCase): | ||
|
||
def setUp(self): | ||
self.branch = Branch.objects.create(branch_name='Pravin Branch', branch_address='pravin Address', branch_contact='Pravin Contact') | ||
self.menu = Menu.objects.create(name='Test Menu', description='Test Description', price=10.00) | ||
|
||
def test_order_place_form_valid(self): | ||
form_data = { | ||
'street': 'Pravin Street', | ||
'city': 'Klang City', | ||
'state': ' Selangor', | ||
'zipcode': '41200', | ||
'mobile': '0124596788', | ||
'payment_method': PaymentMethod.CASH, | ||
'total_amount': 10.00, | ||
'branch': self.branch.id, | ||
'menu': self.menu.id, | ||
} | ||
form = OrderPlaceForm(data=form_data) | ||
self.assertTrue(form.is_valid()) | ||
|
||
def test_order_place_form_invalid(self): | ||
form_data = { | ||
'street': 'Pravin Street', | ||
'city': 'Klang City', | ||
'state': ' Selangor', | ||
'zipcode': '41200', | ||
'mobile': '', | ||
'payment_method': PaymentMethod.CASH, | ||
'total_amount': 10.00, | ||
'branch': self.branch.id, | ||
'menu': self.menu.id, | ||
} | ||
form = OrderPlaceForm(data=form_data) | ||
self.assertFalse(form.is_valid()) |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from django.test import TestCase | ||
from django.contrib.auth.models import User | ||
from branches.models import Branch | ||
from dashboard.models import Menu | ||
from orders.models import Order, PaymentMethod, OrderStatus | ||
|
||
|
||
class OrderModelTest(TestCase): | ||
|
||
def setUp(self): | ||
self.user = User.objects.create_user(username='pravin', password='pg030399') | ||
self.branch = Branch.objects.create(branch_name='Pravin Branch', branch_address='Pravin Address', branch_contact='Pravin Contact') | ||
self.menu = Menu.objects.create(name='Pravin Menu', description='Pravin Description', price=10.00) | ||
|
||
def test_order_creation(self): | ||
order = Order.objects.create( | ||
street='Pravin Street', | ||
city='Klang City', | ||
state='Selangor', | ||
zipcode='41200', | ||
mobile='0124596788', | ||
total_amount=10.00, | ||
payment_method=PaymentMethod.CASH, | ||
user=self.user, | ||
branch=self.branch, | ||
menu=self.menu, | ||
) | ||
self.assertEqual(order.street, 'Pravin Street') | ||
self.assertEqual(order.city, 'Klang City') | ||
self.assertEqual(order.state, 'Selangor') | ||
self.assertEqual(order.zipcode, '41200') | ||
self.assertEqual(order.mobile, '0124596788') | ||
self.assertEqual(order.total_amount, 10.00) | ||
self.assertEqual(order.payment_method, PaymentMethod.CASH) | ||
self.assertEqual(order.order_status, OrderStatus.NEW) | ||
self.assertEqual(order.user, self.user) | ||
self.assertEqual(order.branch, self.branch) | ||
self.assertEqual(order.menu, self.menu) | ||
|
||
def test_get_name(self): | ||
order = Order.objects.create( | ||
street='Pravin Street', | ||
city='Klang City', | ||
state='Selangor', | ||
zipcode='41200', | ||
mobile='0124596788', | ||
total_amount=10.00, | ||
payment_method=PaymentMethod.CASH, | ||
user=self.user, | ||
branch=self.branch, | ||
menu=self.menu, | ||
) | ||
self.assertEqual(order.get_name(), f'{self.user.first_name} {self.user.last_name}') | ||
|
||
def test_get_address(self): | ||
order = Order.objects.create( | ||
street='Pravin Street', | ||
city='Klang City', | ||
state='Selangor', | ||
zipcode='41200', | ||
mobile='0124596788', | ||
total_amount=10.00, | ||
payment_method=PaymentMethod.CASH, | ||
user=self.user, | ||
branch=self.branch, | ||
menu=self.menu, | ||
) | ||
expected_address = 'Pravin Street, Klang City, Selangor, 41200' | ||
self.assertEqual(order.get_address(), expected_address) |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
from django.contrib.auth.models import User | ||
from django.test.client import Client | ||
from dashboard.models import Menu | ||
from orders.models import Order | ||
from orders.forms import OrderPlaceForm | ||
|
||
class OrderPlaceViewTests(TestCase): | ||
|
||
def setUp(self): | ||
self.user = User.objects.create_user(username='pravin', password='pg030399') | ||
self.menu = Menu.objects.create(name='Pravin Menu', description='Pravin Description', price=10.00) | ||
self.client = Client() | ||
self.client.login(username='pravin', password='pg030399') | ||
|
||
def test_get_order_place_view(self): | ||
response = self.client.get(reverse('orders:order') + f'?menu_id={self.menu.id}') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTemplateUsed(response, 'order-place.html') | ||
self.assertIsInstance(response.context['form'], OrderPlaceForm) | ||
self.assertEqual(response.context['form'].fields['menu'].queryset.count(), 1) | ||
self.assertEqual(response.context['menu'], self.menu) | ||
|
||
def test_post_order_place_view_invalid(self): | ||
form_data = { | ||
'street': 'Pravin Street', | ||
'city': 'Klang City', | ||
'state': ' Selangor', | ||
'zipcode': '41200', | ||
'mobile': '0124596788', | ||
'payment_method': 'CASH', | ||
'total_amount': 10.00, | ||
'branch': self.menu.branch_id, | ||
'menu': self.menu.id, | ||
} | ||
response = self.client.post(reverse('orders:order'), data=form_data) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTemplateUsed(response, 'order-place.html') | ||
self.assertTrue(response.context['form'].errors) | ||
self.assertFalse(Order.objects.filter(user=self.user, menu=self.menu).exists()) | ||
|
||
def test_post_order_place_view_valid(self): | ||
form_data = { | ||
'street': 'Pravin Street', | ||
'city': 'Klang City', | ||
'state': ' Selangor', | ||
'zipcode': '41200', | ||
'mobile': '0124596788', | ||
'payment_method': 'CASH', | ||
'total_amount': 10.00, | ||
'branch': self.menu.branch_id, | ||
'menu': self.menu.id, | ||
} | ||
response = self.client.post(reverse('orders:order'), data=form_data) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTemplateUsed(response, 'order-confirm.html') | ||
self.assertTrue(Order.objects.filter(user=self.user, menu=self.menu).exists()) |
This file was deleted.
Oops, something went wrong.