def test_add_customer_form(staff_user): user_count = User.objects.count() customer_form = CustomerForm( {'email': '*****@*****.**'}, user=staff_user) customer_form.is_valid() customer_form.save() assert User.objects.count() == user_count + 1
def test_add_customer_form(staff_user): user_count = User.objects.count() customer_form = CustomerForm({"email": "*****@*****.**"}, user=staff_user) customer_form.is_valid() new_customer = customer_form.save() assert User.objects.count() == user_count + 1 event = account_events.CustomerEvent.objects.get() assert event.type == account_events.CustomerEvents.ACCOUNT_CREATED assert event.user == new_customer
def test_edit_customer_form(customer_user, staff_user): customer = customer_user customer_form = CustomerForm( {'first_name': 'Jan', 'last_name': 'Nowak', 'email': customer.email}, instance=customer, user=staff_user) customer_form.is_valid() customer_form.save() customer.refresh_from_db() assert customer.first_name == 'Jan' assert customer.last_name == 'Nowak'
def test_edit_customer_form_no_changes_generates_no_event(customer_user, staff_user): customer = customer_user customer_form = CustomerForm( { "first_name": customer.first_name, "last_name": customer.last_name, "email": customer.email, }, instance=customer, user=staff_user, ) customer_form.is_valid() customer_form.save() assert not account_events.CustomerEvent.objects.exists()
def test_edit_customer_form(customer_user, staff_user): customer = customer_user customer_form = CustomerForm( {"first_name": "Jan", "last_name": "Nowak", "email": customer.email}, instance=customer, user=staff_user, ) customer_form.is_valid() customer_form.save() customer.refresh_from_db() assert customer.first_name == "Jan" assert customer.last_name == "Nowak" event = account_events.CustomerEvent.objects.get() assert event.type == account_events.CustomerEvents.NAME_ASSIGNED assert event.user == staff_user assert event.parameters == {"message": customer.get_full_name()}
def test_edit_customer_form_new_email_generates_event(customer_user, staff_user): customer = customer_user customer_form = CustomerForm( { "first_name": customer.first_name, "last_name": customer.last_name, "email": "*****@*****.**", }, instance=customer, user=staff_user, ) customer_form.is_valid() customer_form.save() customer.refresh_from_db() assert customer.email == "*****@*****.**" event = account_events.CustomerEvent.objects.get() assert event.type == account_events.CustomerEvents.EMAIL_ASSIGNED assert event.user == staff_user assert event.parameters == {"message": customer.email}
def test_add_customer_form(staff_user): user_count = User.objects.count() customer_form = CustomerForm({'email': '*****@*****.**'}, user=staff_user) customer_form.is_valid() customer_form.save() assert User.objects.count() == user_count + 1
def test_edit_customer_form(customer_user): customer = customer_user customer_form = CustomerForm( {'first_name': 'Jan', 'last_name': 'Nowak', 'email': customer.email}, instance=customer) customer_form.is_valid() customer_form.save() customer.refresh_from_db() assert customer.first_name == 'Jan' assert customer.last_name == 'Nowak'
def test_edit_customer_form(customer_user, staff_user): customer = customer_user customer_form = CustomerForm( { "first_name": "Jan", "last_name": "Nowak", "email": customer.email }, instance=customer, user=staff_user, ) customer_form.is_valid() customer_form.save() customer.refresh_from_db() assert customer.first_name == "Jan" assert customer.last_name == "Nowak"
def test_customer_form(): data = {'email': '*****@*****.**', 'is_active': True} form = CustomerForm(data) assert form.is_valid() form.save() assert User.objects.get(email=data['email'])