Commit a1ffa761 authored by VAN ZUIJLEN Nils's avatar VAN ZUIJLEN Nils
Browse files

Add tests for OrderEditView.get_context_data

And get_object
parent f6b38861
......@@ -3,6 +3,7 @@ from datetime import timedelta
from decimal import Decimal
from os import path
from typing import Tuple
from unittest.mock import Mock
from django.urls import reverse
from django.utils import timezone
......@@ -23,6 +24,7 @@ from ..views import DeliveryView
from ..views import ItemCreateView
from ..views import ItemEditView
from ..views import ItemListView
from ..views import OrderEditView
class ItemListViewTest(ItemTestCase, UserTestCase):
......@@ -394,6 +396,111 @@ class ManageCategoryViewTest(UserTestCase):
self.assertTrue(len(form.errors) > 0)
class OrderEditViewTest(OrderItemTestCase):
def test_get_object(self) -> None:
view = OrderEditView()
view.request = Mock()
view.request.user = self.user
self.assertEqual(view.get_object(), Order.objects.get_current_order(self.user))
@user_logged_in
def test_context_data_user(self) -> None:
url = reverse('boutique:order_edit')
# Empty order
resp = self.client.get(url)
context = resp.context
self.assertNotIn("form", context)
self.assertIn("formset", context)
self.assertIn("total_price", context)
self.assertIn("is_contributor", context)
self.assertFalse(context["is_contributor"])
# Item in order
item = self.create_item()
item.add_to_user(self.user)
resp = self.client.get(url)
context = resp.context
self.assertNotIn("form", context)
self.assertIn("formset", context)
self.assertIn("total_price", context)
self.assertIn("is_contributor", context)
self.assertEqual(context["total_price"], item.price)
self.assertFalse(context["is_contributor"])
# Cotiz in order
cotiz = self.create_item()
cotiz.action = "full_cotiz"
cotiz.save()
cotiz.refresh_from_db()
cotiz.add_to_user(self.user)
resp = self.client.get(url)
context = resp.context
self.assertNotIn("form", context)
self.assertIn("formset", context)
self.assertIn("total_price", context)
self.assertIn("is_contributor", context)
self.assertEqual(context["total_price"], cotiz.price_contributor + item.price_contributor)
self.assertTrue(context["is_contributor"])
@contrib_user_logged_in
def test_context_data_contrib_user(self) -> None:
url = reverse('boutique:order_edit')
# Empty order
resp = self.client.get(url)
context = resp.context
self.assertNotIn("form", context)
self.assertIn("formset", context)
self.assertIn("total_price", context)
self.assertIn("is_contributor", context)
self.assertTrue(context["is_contributor"])
# Item in order
item = self.create_item()
item.add_to_user(self.contributor_user)
resp = self.client.get(url)
context = resp.context
self.assertNotIn("form", context)
self.assertIn("formset", context)
self.assertIn("total_price", context)
self.assertIn("is_contributor", context)
self.assertEqual(context["total_price"], item.price_contributor)
self.assertTrue(context["is_contributor"])
# Cotiz in order
cotiz = self.create_item()
cotiz.action = "full_cotiz"
cotiz.save()
cotiz.refresh_from_db()
cotiz.add_to_user(self.contributor_user)
resp = self.client.get(url)
context = resp.context
self.assertNotIn("form", context)
self.assertIn("formset", context)
self.assertIn("total_price", context)
self.assertIn("is_contributor", context)
self.assertEqual(context["total_price"], cotiz.price_contributor + item.price_contributor)
self.assertTrue(context["is_contributor"])
class DeliveryViewTest(PaymentTestCase, OrderItemTestCase):
"""Tests for views.DeliveryView"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment