2019-06-16 22:09:51 +02:00
|
|
|
import pytest
|
2019-08-28 23:09:06 +02:00
|
|
|
from mixer.backend.django import mixer
|
|
|
|
|
2019-06-16 22:09:51 +02:00
|
|
|
from django.core.management import call_command
|
2019-07-14 12:58:10 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.contrib.auth.models import Group
|
2019-08-04 20:46:02 +02:00
|
|
|
from guardian.shortcuts import assign_perm
|
2019-07-14 12:58:10 +02:00
|
|
|
|
2019-06-16 22:09:51 +02:00
|
|
|
|
2022-03-27 14:50:44 +02:00
|
|
|
@pytest.fixture(scope="session")
|
2019-06-16 22:09:51 +02:00
|
|
|
def django_db_setup(django_db_setup, django_db_blocker):
|
|
|
|
with django_db_blocker.unblock():
|
2022-03-27 14:50:44 +02:00
|
|
|
call_command("loaddata", "backups.yaml")
|
|
|
|
call_command("loaddata", "computers.yaml")
|
|
|
|
call_command("loaddata", "core.yaml")
|
|
|
|
call_command("loaddata", "devices.yaml")
|
|
|
|
call_command("loaddata", "nets.yaml")
|
|
|
|
call_command("loaddata", "softwares.yaml")
|
2019-07-14 12:58:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2019-08-04 20:46:02 +02:00
|
|
|
def create_admin_user():
|
|
|
|
def _create_admin_user():
|
|
|
|
User = get_user_model()
|
2022-03-27 14:50:44 +02:00
|
|
|
admin = User.objects.create_user(
|
|
|
|
"pharma-admin", "admin@pharma.com", "password"
|
|
|
|
)
|
|
|
|
customer = mixer.blend("customers.Customer")
|
2020-03-15 19:54:43 +01:00
|
|
|
group = Group.objects.create(name="Pharma Corp. Admin")
|
2019-08-04 20:46:02 +02:00
|
|
|
admin.groups.add(group)
|
2022-03-27 14:50:44 +02:00
|
|
|
assign_perm("view_customer", admin, customer)
|
2019-08-04 20:46:02 +02:00
|
|
|
result = {}
|
2022-03-27 14:50:44 +02:00
|
|
|
result["admin"] = admin
|
|
|
|
result["customer"] = customer
|
|
|
|
result["group"] = group
|
2019-08-04 20:46:02 +02:00
|
|
|
return result
|
2022-03-27 14:50:44 +02:00
|
|
|
|
2019-08-04 20:46:02 +02:00
|
|
|
return _create_admin_user
|