Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Pole-Web
Website
Commits
a1ffa761
Commit
a1ffa761
authored
Nov 26, 2020
by
VAN ZUIJLEN Nils
Browse files
Add tests for OrderEditView.get_context_data
And get_object
parent
f6b38861
Changes
1
Hide whitespace changes
Inline
Side-by-side
boutique/tests/test_views.py
View file @
a1ffa761
...
...
@@ -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"""
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment