network_inventory/src/customers/tests/test_customer_list_view.py

84 lines
3.4 KiB
Python
Raw Normal View History

import pytest
from django.test import Client
from django.contrib.auth import get_user_model
from guardian.shortcuts import assign_perm
from mixer.backend.django import mixer
from core.tests import helper
2019-11-30 16:08:53 +01:00
pytestmark = pytest.mark.django_db
def test_customer_list_view_not_logged_in():
2022-03-27 14:50:44 +02:00
response = Client().get("/")
assert response.status_code == 302 and "login" in response.url
def test_customer_list_view_no_customer():
User = get_user_model()
2022-03-27 14:50:44 +02:00
User.objects.create_user(
"pharma-admin", "admin@pharma.com", "password", is_staff=True
)
client = Client()
client.login(username="pharma-admin", password="password")
2022-03-27 14:50:44 +02:00
response = client.get("/")
assert response.status_code == 200
def test_customer_list_view(create_admin_user):
2022-03-29 22:03:43 +02:00
User = get_user_model()
project_manager = User.objects.create_superuser(
"meyer", "meyer@contria.com", "password"
)
fixture = create_admin_user()
2022-03-27 14:50:44 +02:00
customer = fixture["customer"]
2022-03-29 22:03:43 +02:00
customer.project_manager = project_manager
customer.save()
client = Client()
client.login(username="pharma-admin", password="password")
2022-03-27 14:50:44 +02:00
response = client.get("/")
assert (
response.status_code == 200
and helper.in_content(response, customer)
2023-07-10 16:47:01 +02:00
and helper.in_content(response, "/customer/" + str(customer.id) + "/nets/")
and helper.in_content(response, "/customer/" + str(customer.id) + "/computers/")
and helper.in_content(response, "/customer/" + str(customer.id) + "/devices/")
and helper.in_content(response, "/customer/" + str(customer.id) + "/backups/")
and helper.in_content(response, "/customer/" + str(customer.id) + "/licenses/")
and helper.in_content(response, "/customer/" + str(customer.id) + "/users/")
2022-03-29 22:03:43 +02:00
and helper.in_content(response, project_manager)
2022-03-27 14:50:44 +02:00
)
def test_customer_list_view_multiple_customers(create_admin_user):
fixture = create_admin_user()
2022-03-27 14:50:44 +02:00
customer1 = fixture["customer"]
customer2 = mixer.blend("customers.Customer")
assign_perm("view_customer", fixture["admin"], customer2)
client = Client()
client.login(username="pharma-admin", password="password")
2022-03-27 14:50:44 +02:00
response = client.get("/")
assert (
response.status_code == 200
and helper.in_content(response, customer1)
2023-07-10 16:47:01 +02:00
and helper.in_content(response, "/customer/" + str(customer1.id) + "/nets/")
2022-03-27 14:50:44 +02:00
and helper.in_content(
response, "/customer/" + str(customer1.id) + "/computers/"
)
2023-07-10 16:47:01 +02:00
and helper.in_content(response, "/customer/" + str(customer1.id) + "/devices/")
and helper.in_content(response, "/customer/" + str(customer1.id) + "/backups/")
and helper.in_content(response, "/customer/" + str(customer1.id) + "/licenses/")
and helper.in_content(response, "/customer/" + str(customer1.id) + "/users/")
2022-03-27 14:50:44 +02:00
and helper.in_content(response, customer2)
2023-07-10 16:47:01 +02:00
and helper.in_content(response, "/customer/" + str(customer2.id) + "/nets/")
2022-03-27 14:50:44 +02:00
and helper.in_content(
response, "/customer/" + str(customer2.id) + "/computers/"
)
2023-07-10 16:47:01 +02:00
and helper.in_content(response, "/customer/" + str(customer2.id) + "/devices/")
and helper.in_content(response, "/customer/" + str(customer2.id) + "/backups/")
and helper.in_content(response, "/customer/" + str(customer2.id) + "/licenses/")
and helper.in_content(response, "/customer/" + str(customer1.id) + "/users/")
2022-03-27 14:50:44 +02:00
)