feat: reset migrations and created customer address model

This commit is contained in:
2024-12-07 10:10:14 +01:00
parent 1ffa5b117f
commit 48d39f55ba
18 changed files with 863 additions and 908 deletions
+62 -43
View File
@@ -1,10 +1,13 @@
from decimal import Decimal
from django.contrib.auth import get_user_model
from rest_framework import status
from rest_framework.test import APITestCase
from config.tests.mixins import TestUserAuthenticationMixin
from shop.models import Customer, Product, ProductPrice, Tax
from shop.models import Product, ProductPrice, Tax, Customer, CustomerAddress
User = get_user_model()
class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin):
@@ -16,16 +19,32 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin):
code="IVA",
value=21,
)
self.customer = Customer.objects.create(
vat_id="11111111H",
self.customer = get_user_model().objects.create_user(
username="11111111H",
first_name="Darth",
last_name="Maull",
email="darth@maul.com",
password="dathomir",
)
self.customer_shipping_address = CustomerAddress.objects.create(
user=self.customer,
address="Dathomir",
city="Dathomir",
state="Dathomir",
country="Dathomir",
zip="00001",
address_town="Dathomir",
address_zip="00001",
address_state="Dathomir",
address_phone="900000000",
address_type=CustomerAddress.Types.SHIPPING,
)
self.customer_billing_address = CustomerAddress.objects.create(
user=self.customer,
address="Dathomir",
address_town="Dathomir",
address_zip="00001",
address_state="Dathomir",
address_phone="900000000",
address_type=CustomerAddress.Types.BILLING,
)
self.create_products()
@@ -49,18 +68,18 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin):
response = self.client.post(
f"/api/v1/shop/orders/",
{
"customer": self.customer.pk,
"billing_address": self.customer.address,
"billing_city": self.customer.city,
"billing_state": self.customer.state,
"billing_country": self.customer.country,
"billing_zip": self.customer.zip,
"shipping_address": self.customer.address,
"shipping_city": self.customer.city,
"shipping_state": self.customer.state,
"shipping_country": self.customer.country,
"shipping_zip": self.customer.zip,
"contact_phone": "612345678",
"user": self.user.pk,
"billing_address": self.customer_billing_address.address,
"billing_city": self.customer_billing_address.address_town,
"billing_state": self.customer_billing_address.address_state,
"billing_country": self.customer_billing_address.address_country,
"billing_zip": self.customer_billing_address.address_zip,
"shipping_address": self.customer_shipping_address.address,
"shipping_city": self.customer_shipping_address.address_town,
"shipping_state": self.customer_shipping_address.address_state,
"shipping_country": self.customer_shipping_address.address_country,
"shipping_zip": self.customer_shipping_address.address_zip,
"contact_phone": self.customer_shipping_address.address_phone,
},
)
@@ -76,18 +95,18 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin):
response = self.client.post(
f"/api/v1/shop/orders/",
{
"customer": self.customer.pk,
"billing_address": self.customer.address,
"billing_city": self.customer.city,
"billing_state": self.customer.state,
"billing_country": self.customer.country,
"billing_zip": self.customer.zip,
"shipping_address": self.customer.address,
"shipping_city": self.customer.city,
"shipping_state": self.customer.state,
"shipping_country": self.customer.country,
"shipping_zip": self.customer.zip,
"contact_phone": "612345678",
"user": self.user.pk,
"billing_address": self.customer_billing_address.address,
"billing_city": self.customer_billing_address.address_town,
"billing_state": self.customer_billing_address.address_state,
"billing_country": self.customer_billing_address.address_country,
"billing_zip": self.customer_billing_address.address_zip,
"shipping_address": self.customer_shipping_address.address,
"shipping_city": self.customer_shipping_address.address_town,
"shipping_state": self.customer_shipping_address.address_state,
"shipping_country": self.customer_shipping_address.address_country,
"shipping_zip": self.customer_shipping_address.address_zip,
"contact_phone": self.customer_shipping_address.address_phone,
},
)
@@ -126,18 +145,18 @@ class TestOrdersAPI(APITestCase, TestUserAuthenticationMixin):
response = self.client.post(
f"/api/v1/shop/orders/",
{
"customer": self.customer.pk,
"billing_address": self.customer.address,
"billing_city": self.customer.city,
"billing_state": self.customer.state,
"billing_country": self.customer.country,
"billing_zip": self.customer.zip,
"shipping_address": self.customer.address,
"shipping_city": self.customer.city,
"shipping_state": self.customer.state,
"shipping_country": self.customer.country,
"shipping_zip": self.customer.zip,
"contact_phone": "612345678",
"user": self.user.pk,
"billing_address": self.customer_billing_address.address,
"billing_city": self.customer_billing_address.address_town,
"billing_state": self.customer_billing_address.address_state,
"billing_country": self.customer_billing_address.address_country,
"billing_zip": self.customer_billing_address.address_zip,
"shipping_address": self.customer_shipping_address.address,
"shipping_city": self.customer_shipping_address.address_town,
"shipping_state": self.customer_shipping_address.address_state,
"shipping_country": self.customer_shipping_address.address_country,
"shipping_zip": self.customer_shipping_address.address_zip,
"contact_phone": self.customer_shipping_address.address_phone,
},
)