evorepo/conftest.py

76 lines
1.7 KiB
Python
Raw Normal View History

2021-09-13 13:37:18 -07:00
import pytest
from django.contrib.auth.models import Group
from django.core.management import call_command
2021-09-21 03:34:04 -07:00
from main.models import Repo
2021-09-13 13:37:18 -07:00
from devel.models import UserProfile
USERNAME = 'joeuser'
FIRSTNAME = 'Joe'
LASTNAME = 'User'
EMAIL = 'user1@example.com'
@pytest.fixture
def arches(db):
# TODO: create Arch object
call_command('loaddata', 'main/fixtures/arches.json')
@pytest.fixture
2021-09-21 03:34:04 -07:00
def repos(arches):
2021-09-13 13:37:18 -07:00
# TODO: create Repo object
call_command('loaddata', 'main/fixtures/repos.json')
@pytest.fixture
def package(db, arches, repos):
# TODO: convert to create_package with standard parameters
call_command('loaddata', 'main/fixtures/package.json')
@pytest.fixture
def groups(db):
call_command('loaddata', 'main/fixtures/groups.json')
@pytest.fixture
def staff_groups(db):
call_command('loaddata', 'devel/fixtures/staff_groups.json')
@pytest.fixture
def user(django_user_model):
user = django_user_model.objects.create_user(username=USERNAME, password=USERNAME, email=EMAIL)
2021-09-13 13:37:18 -07:00
yield user
user.delete()
@pytest.fixture
def userprofile(user):
profile = UserProfile.objects.create(user=user,
public_email=f'{user.username}@archlinux.org')
yield profile
profile.delete()
@pytest.fixture
2021-09-21 03:34:04 -07:00
def developer(user, userprofile, repos, groups):
2021-09-13 13:37:18 -07:00
user.groups.add(Group.objects.get(name='Developers'))
2021-09-21 03:34:04 -07:00
userprofile.allowed_repos.add(Repo.objects.get(name='Core'))
return user
@pytest.fixture
def developer_client(client, developer, userprofile, groups):
2021-09-13 13:37:18 -07:00
client.login(username=USERNAME, password=USERNAME)
return client
2021-09-21 03:34:04 -07:00
@pytest.fixture
def denylist(db):
# TODO: create Denylist object
call_command('loaddata', 'main/fixtures/denylist.json')