Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dinoperovic committed Nov 4, 2022
1 parent 673938b commit 7fabeef
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion example/tests/admin/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from salesman.admin import admin
from salesman.conf import app_settings
from salesman.core.utils import get_salesman_model
from shop.models import Product

site = AdminSite()

Expand All @@ -22,8 +23,9 @@ def test_order_item_inline(rf, django_user_model):
)
modeladmin = admin.OrderItemInline(OrderItem, site)
order = Order.objects.create(ref="1")
product = Product.objects.create(name="Test", price=10)
item = OrderItem.objects.create(
order=order, unit_price=10, subtotal=20, total=20, quantity=2
order=order, product=product, unit_price=10, subtotal=20, total=20, quantity=2
)
modeladmin.get_queryset(request)
assert modeladmin.model.request == request
Expand Down
3 changes: 3 additions & 0 deletions example/tests/admin/test_admin_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from salesman.admin.wagtail.mixins import WagtailOrderAdminMixin
from salesman.conf import app_settings
from salesman.core.utils import get_salesman_model
from shop.models import Product

site = AdminSite()

Expand All @@ -35,8 +36,10 @@ def test_order_item_admin_mixin():
order = Order.objects.create(ref="1")
extra = {"test": "123", "rows": ["value"]}
product_data = {"name": "Test product"}
product = Product.objects.create(name="Test Product", price=10)
item = OrderItem.objects.create(
order=order,
product=product,
unit_price=10,
subtotal=20,
total=20,
Expand Down
4 changes: 3 additions & 1 deletion example/tests/admin/test_admin_panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from salesman.admin.wagtail.forms import WagtailOrderModelForm
from salesman.admin.wagtail_hooks import OrderAdmin
from salesman.core.utils import get_salesman_model
from shop.models import Product

Order = get_salesman_model("Order")
OrderItem = get_salesman_model("OrderItem")
Expand Down Expand Up @@ -117,8 +118,9 @@ def test_order_checkbox_panel():
@pytest.mark.django_db
def test_order_items_panel():
order = Order.objects.create(ref="1", subtotal=120, total=120)
product = Product.objects.create(name="Test Product", price=50)
OrderItem.objects.create(
order=order, unit_price=50, subtotal=100, total=120, quantity=2
order=order, product=product, unit_price=50, subtotal=100, total=120, quantity=2
)
panel = OrderItemsPanel("items")
panel.model = Order
Expand Down
8 changes: 6 additions & 2 deletions example/tests/admin/test_admin_wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from salesman.admin import wagtail_hooks
from salesman.core.utils import get_salesman_model
from shop.models import Product

site = AdminSite()

Expand All @@ -21,10 +22,13 @@ def test_order_admin(rf, client, django_user_model):
request.session = {}
request._messages = FallbackStorage(request)
order = Order.objects.create(ref="2020-00001", subtotal=100, total=120)
product = Product.objects.create(name="Test Product", price=100)
OrderItem.objects.create(
order=order, unit_price=10, subtotal=20, total=20, quantity=2
order=order, product=product, unit_price=10, subtotal=20, total=20, quantity=2
)
OrderItem.objects.create(
order=order, product=product, unit_price=1, subtotal=2, total=2, quantity=1
)
OrderItem.objects.create(order=order, unit_price=1, subtotal=2, total=2, quantity=1)
modeladmin = wagtail_hooks.OrderAdmin()
modeladmin.model = Order
modeladmin.model.request = request
Expand Down
1 change: 1 addition & 0 deletions example/tests/orders/test_orders_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_order_views(django_user_model):
)
OrderItem.objects.create(
order=order2,
product=product,
product_data={"name": "Test data"},
unit_price=70,
subtotal=70,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ djangorestframework = ">=3.11,<3.15"

# Optional
Pygments = {version = "^2.6", optional = true}
wagtail = {version = ">=2.9,<5.0", optional = true}
wagtail = {version = ">=2.9,<4.2", optional = true}
pytest = {version = "~7.0.0", optional = true}
pytest-django = {version = "~4.5.0", optional = true}
pytest-cov = {version = "~3.0.0", optional = true}
Expand Down

0 comments on commit 7fabeef

Please sign in to comment.