feat: mixin for update forms
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from shop.tests.mixins import CreateProductsMixin
|
||||
|
||||
|
||||
class TestChangeUserPassword(TestCase, CreateProductsMixin):
|
||||
def setUp(self):
|
||||
self.password = "ihatesand"
|
||||
self.user = User.objects.create_user("vader", "darth@vader.com", self.password)
|
||||
|
||||
def test_update_user_info(self):
|
||||
self.client.force_login(self.user)
|
||||
response = self.client.get(reverse("web:change_password_component"))
|
||||
|
||||
assert response.status_code == 200
|
||||
new_password = "ifnhatesandbro"
|
||||
data = {
|
||||
"old_password": self.password,
|
||||
"new_password1": new_password,
|
||||
"new_password2": new_password,
|
||||
}
|
||||
|
||||
response = self.client.post(reverse("web:change_password_component"), data)
|
||||
|
||||
assert response.status_code == 200
|
||||
self.user.refresh_from_db()
|
||||
|
||||
assert self.user.check_password(new_password)
|
||||
@@ -11,7 +11,7 @@ class TestCustomerAddresses(TestCase, CreateProductsMixin):
|
||||
self.user = User.objects.create_user("vader", "darth@vader.com", "ihatesand")
|
||||
self.customer_address = CustomerAddress.objects.create(
|
||||
user=self.user,
|
||||
full_name='Darth Vader',
|
||||
full_name="Darth Vader",
|
||||
address_type=CustomerAddress.Types.SHIPPING,
|
||||
address="Vader Fortress",
|
||||
address_town="Mustafar",
|
||||
@@ -33,13 +33,18 @@ class TestCustomerAddresses(TestCase, CreateProductsMixin):
|
||||
"address_zip": "00001",
|
||||
}
|
||||
|
||||
response = self.client.post(reverse("web:update_customer_address", kwargs={"pk": self.customer_address.pk}), data)
|
||||
response = self.client.post(
|
||||
reverse(
|
||||
"web:update_customer_address", kwargs={"pk": self.customer_address.pk}
|
||||
),
|
||||
data,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
self.customer_address.refresh_from_db()
|
||||
|
||||
assert self.customer_address.full_name == data.get('full_name')
|
||||
assert self.customer_address.address == data.get('address')
|
||||
assert self.customer_address.address_town == data.get('address_town')
|
||||
assert self.customer_address.address_state == data.get('address_state')
|
||||
assert self.customer_address.address_phone == data.get('address_phone')
|
||||
assert self.customer_address.full_name == data.get("full_name")
|
||||
assert self.customer_address.address == data.get("address")
|
||||
assert self.customer_address.address_town == data.get("address_town")
|
||||
assert self.customer_address.address_state == data.get("address_state")
|
||||
assert self.customer_address.address_phone == data.get("address_phone")
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.contrib.auth.models import User
|
||||
from django.test import TestCase
|
||||
from django.urls import reverse
|
||||
|
||||
from shop.models import CustomerAddress
|
||||
from shop.tests.mixins import CreateProductsMixin
|
||||
|
||||
|
||||
@@ -13,12 +12,13 @@ class TestUserInfo(TestCase, CreateProductsMixin):
|
||||
def test_update_user_info(self):
|
||||
self.client.force_login(self.user)
|
||||
response = self.client.get(reverse("web:user_info_component"))
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
data = {
|
||||
"first_name": "Anakin",
|
||||
"last_name": "Skywalker",
|
||||
"email": "anakin@skywalker.com"
|
||||
"email": "anakin@skywalker.com",
|
||||
}
|
||||
|
||||
response = self.client.post(reverse("web:user_info_component"), data)
|
||||
@@ -26,6 +26,6 @@ class TestUserInfo(TestCase, CreateProductsMixin):
|
||||
assert response.status_code == 200
|
||||
self.user.refresh_from_db()
|
||||
|
||||
assert self.user.first_name == data.get('first_name')
|
||||
assert self.user.last_name == data.get('last_name')
|
||||
assert self.user.email == data.get('email')
|
||||
assert self.user.first_name == data.get("first_name")
|
||||
assert self.user.last_name == data.get("last_name")
|
||||
assert self.user.email == data.get("email")
|
||||
|
||||
Reference in New Issue
Block a user