generated from westfarn/web_django_template
Add customer accounts, shipment tracking, and purchase reviews.
CI / test (pull_request) Successful in 35s
CI / test (pull_request) Successful in 35s
Shoppers can register, save shipping details, and view order history while cards stay on Stripe. EasyPost tracker updates (including numbers from Pirate Ship) and 1–5 star reviews are limited to buyers. The contact form now only asks for email and a message.
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from accounts.models import CustomerProfile
|
||||
from shop.models import Order
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
class CustomerAccountTests(TestCase):
|
||||
def test_register_login_and_profile(self):
|
||||
client = Client()
|
||||
response = client.post(
|
||||
reverse("account:register"),
|
||||
{
|
||||
"email": "buyer@example.com",
|
||||
"first_name": "Pat",
|
||||
"last_name": "Lee",
|
||||
"password1": "s3cure-pass-123",
|
||||
"password2": "s3cure-pass-123",
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
user = User.objects.get(email="buyer@example.com")
|
||||
self.assertEqual(user.username, "buyer@example.com")
|
||||
self.assertFalse(user.is_staff)
|
||||
self.assertTrue(CustomerProfile.objects.filter(user=user).exists())
|
||||
|
||||
client.logout()
|
||||
login = client.post(
|
||||
reverse("account:login"),
|
||||
{"username": "buyer@example.com", "password": "s3cure-pass-123"},
|
||||
)
|
||||
self.assertEqual(login.status_code, 302)
|
||||
|
||||
save = client.post(
|
||||
reverse("account:profile"),
|
||||
{
|
||||
"first_name": "Patricia",
|
||||
"last_name": "Lee",
|
||||
"phone": "6305550100",
|
||||
"address_line1": "10 Main St",
|
||||
"address_city": "Aurora",
|
||||
"address_state": "IL",
|
||||
"address_zip": "60505",
|
||||
},
|
||||
)
|
||||
self.assertEqual(save.status_code, 302)
|
||||
user.refresh_from_db()
|
||||
profile = user.customer_profile
|
||||
self.assertEqual(user.first_name, "Patricia")
|
||||
self.assertEqual(profile.phone, "6305550100")
|
||||
self.assertEqual(profile.shipping_address.get("line1"), "10 Main St")
|
||||
|
||||
def test_register_claims_guest_orders(self):
|
||||
order = Order.objects.create(
|
||||
number="ORD-CLAIM-001",
|
||||
email="buyer@example.com",
|
||||
status=Order.Status.PAID,
|
||||
amount="18.00",
|
||||
)
|
||||
client = Client()
|
||||
client.post(
|
||||
reverse("account:register"),
|
||||
{
|
||||
"email": "buyer@example.com",
|
||||
"password1": "s3cure-pass-123",
|
||||
"password2": "s3cure-pass-123",
|
||||
},
|
||||
)
|
||||
order.refresh_from_db()
|
||||
self.assertEqual(order.user.email, "buyer@example.com")
|
||||
history = client.get(reverse("account:orders"))
|
||||
self.assertEqual(history.status_code, 200)
|
||||
self.assertContains(history, "ORD-CLAIM-001")
|
||||
|
||||
def test_customer_cannot_open_portal(self):
|
||||
User.objects.create_user(
|
||||
username="buyer@example.com",
|
||||
email="buyer@example.com",
|
||||
password="s3cure-pass-123",
|
||||
)
|
||||
client = Client()
|
||||
client.login(username="buyer@example.com", password="s3cure-pass-123")
|
||||
response = client.get(reverse("dashboard:home"))
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertEqual(response["Location"], reverse("account:home"))
|
||||
Reference in New Issue
Block a user