-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 500 error due to None data in DAB response
- Loading branch information
1 parent
48e3afb
commit 245a33c
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,11 @@ | |
import pytest | ||
|
||
from django.contrib.sessions.middleware import SessionMiddleware | ||
from django.test.utils import override_settings | ||
from django.contrib.auth.models import AnonymousUser | ||
|
||
from ansible_base.lib.utils.response import get_relative_url | ||
from ansible_base.lib.testing.fixtures import settings_override_mutable | ||
|
||
from awx.main.models import User | ||
from awx.api.versioning import reverse | ||
|
@@ -16,6 +21,33 @@ | |
EXAMPLE_USER_DATA = {"username": "affable", "first_name": "a", "last_name": "a", "email": "[email protected]", "is_superuser": False, "password": "r$TyKiOCb#ED"} | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_validate_local_user(post, admin_user, settings, settings_override_mutable): | ||
"Copy of the test by same name in django-ansible-base for integration and compatibility testing" | ||
url = get_relative_url('validate-local-account') | ||
admin_user.set_password('password') | ||
admin_user.save() | ||
data = { | ||
"username": admin_user.username, | ||
"password": "password", | ||
} | ||
with override_settings(RESOURCE_SERVER={"URL": "https://foo.invalid", "SECRET_KEY": "foobar"}): | ||
response = post(url=url, data=data, user=AnonymousUser(), expect=200) | ||
|
||
assert 'ansible_id' in response.data | ||
assert response.data['auth_code'] is not None, response.data | ||
|
||
# No resource server, return coherent response but can not provide auth code | ||
response = post(url=url, data=data, user=AnonymousUser(), expect=200) | ||
assert 'ansible_id' in response.data | ||
assert response.data['auth_code'] is None | ||
|
||
# wrong password | ||
data['password'] = 'foobar' | ||
response = post(url=url, data=data, user=AnonymousUser(), expect=401) | ||
# response.data may be none here, this is just testing that we get no server error | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_user_create(post, admin): | ||
response = post(reverse('api:user_list'), EXAMPLE_USER_DATA, admin, middleware=SessionMiddleware(mock.Mock())) | ||
|