refacture the fixtures
the fixtures where overcomplicated and should be easier.
This commit is contained in:
parent
5317f42349
commit
b022b1747d
|
@ -2,6 +2,7 @@ import pytest
|
|||
from django.core.management import call_command
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group
|
||||
from guardian.shortcuts import assign_perm
|
||||
|
||||
from inventory.models import Customer, Computer
|
||||
|
||||
|
@ -13,49 +14,20 @@ def django_db_setup(django_db_setup, django_db_blocker):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def make_admin_users():
|
||||
def _make_admin_users(customer_names):
|
||||
admins = {}
|
||||
for name in customer_names:
|
||||
User = get_user_model()
|
||||
username = name.lower() + '_admin'
|
||||
domain = name.lower() + '.com'
|
||||
admins[name] = User.objects.create_user(
|
||||
username,
|
||||
username + '@' + domain,
|
||||
'password',
|
||||
is_staff=True)
|
||||
return admins
|
||||
return _make_admin_users
|
||||
def create_admin_user():
|
||||
def _create_admin_user():
|
||||
User = get_user_model()
|
||||
admin = User.objects.create_user("novartis-admin", "admin@novartis.com",
|
||||
"password", is_staff=True)
|
||||
customer = Customer(name="Novartis")
|
||||
customer.save()
|
||||
group = Group.objects.create(name="Novartis Admin")
|
||||
admin.groups.add(group)
|
||||
assign_perm('view_customer', admin, customer)
|
||||
result = {}
|
||||
result['admin'] = admin
|
||||
result['customer'] = customer
|
||||
result['group'] = group
|
||||
return result
|
||||
return _create_admin_user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_customers():
|
||||
def _make_customers(customer_names):
|
||||
customers = {}
|
||||
for name in customer_names:
|
||||
customers[name] = Customer.objects.create(name=name)
|
||||
return customers
|
||||
return _make_customers
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_admin_groups():
|
||||
def _make_admin_groups(customer_names):
|
||||
groups = {}
|
||||
for name in customer_names:
|
||||
groups[name] = Group.objects.create(name=name)
|
||||
return groups
|
||||
return _make_admin_groups
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def make_computers():
|
||||
def _make_computers(customer_names):
|
||||
computers = {}
|
||||
for name in customer_names:
|
||||
computers[name] = Computer.objects.create(
|
||||
name=name.lower() + '-pc1',
|
||||
customer=Customer.objects.get(name=name))
|
||||
return computers
|
||||
return _make_computers
|
||||
|
|
Loading…
Reference in New Issue