network_inventory/customers/tests/test_location_form.py

26 lines
822 B
Python
Raw Normal View History

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-23 12:18:40 +01:00
user = fixture['admin']
form = forms.LocationForm(user=user, data={})
2022-03-05 15:13:27 +01:00
assert form.is_valid() is False, (
"Should be false because no data was given")
data = {"name": "Main Office",
"customer": 3}
2022-03-23 12:18:40 +01:00
form = forms.LocationForm(user=user, data=data)
2022-03-05 15:13:27 +01:00
assert form.is_valid() is False, (
"Should be false because the customer doesn't exist.")
2022-03-23 10:34:53 +01:00
data = {"name": mixer.blend('customers.Location').name,
2022-03-05 15:13:27 +01:00
"customer": fixture['customer'].id}
2022-03-23 12:18:40 +01:00
form = forms.LocationForm(user=user, data=data)
2022-03-05 15:13:27 +01:00
assert form.is_valid() is True, ("Should be valid with the given data.")