2022-03-05 15:13:27 +01:00
|
|
|
import pytest
|
|
|
|
from mixer.backend.django import mixer
|
|
|
|
|
|
|
|
from customers import forms
|
|
|
|
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
|
|
|
|
|
|
def test_location_form(create_admin_user):
|
|
|
|
fixture = create_admin_user()
|
2022-03-27 14:50:44 +02:00
|
|
|
user = fixture["admin"]
|
2022-03-23 12:18:40 +01:00
|
|
|
form = forms.LocationForm(user=user, data={})
|
2023-07-10 16:47:01 +02:00
|
|
|
assert form.is_valid() is False, "Should be false because no data was given"
|
2022-03-05 15:13:27 +01:00
|
|
|
|
2022-03-27 14:50:44 +02:00
|
|
|
data = {"name": "Main Office", "customer": 3}
|
2022-03-23 12:18:40 +01:00
|
|
|
form = forms.LocationForm(user=user, data=data)
|
2022-03-27 14:50:44 +02:00
|
|
|
assert (
|
|
|
|
form.is_valid() is False
|
|
|
|
), "Should be false because the customer doesn't exist."
|
2022-03-05 15:13:27 +01:00
|
|
|
|
2022-03-27 14:50:44 +02:00
|
|
|
data = {
|
|
|
|
"name": mixer.blend("customers.Location").name,
|
|
|
|
"customer": fixture["customer"].id,
|
|
|
|
}
|
2022-03-23 12:18:40 +01:00
|
|
|
form = forms.LocationForm(user=user, data=data)
|
2022-03-27 14:50:44 +02:00
|
|
|
assert form.is_valid() is True, "Should be valid with the given data."
|