mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 04:47:44 -02:30
Wrap up Tower configuration unit tests
This commit is contained in:
43
awx/conf/tests/functional/conftest.py
Normal file
43
awx/conf/tests/functional/conftest.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import pytest
|
||||
|
||||
from django.core.urlresolvers import resolve
|
||||
from django.utils.six.moves.urllib.parse import urlparse
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from rest_framework.test import (
|
||||
APIRequestFactory,
|
||||
force_authenticate,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def normal_user():
|
||||
try:
|
||||
user = User.objects.get(username='conf-normal')
|
||||
except User.DoesNotExist:
|
||||
user = User(username='conf-normal', is_superuser=False, password='conf-normal')
|
||||
user.save()
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin():
|
||||
try:
|
||||
user = User.objects.get(username='conf-admin')
|
||||
except User.DoesNotExist:
|
||||
user = User(username='conf-admin', is_superuser=True, password='conf-admin')
|
||||
user.save()
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def api_request(admin):
|
||||
def rf(verb, url, data=None, user=admin):
|
||||
view, view_args, view_kwargs = resolve(urlparse(url)[2])
|
||||
request = getattr(APIRequestFactory(), verb)(url, data=data, format='json')
|
||||
if user:
|
||||
force_authenticate(request, user=user)
|
||||
response = view(request, *view_args, **view_kwargs)
|
||||
response.render()
|
||||
return response
|
||||
return rf
|
||||
Reference in New Issue
Block a user