mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 23:51:09 +03:00
update unit tetsts
This commit is contained in:
parent
9baa9594c7
commit
b862a13d92
@ -11,6 +11,7 @@ from django.contrib.contenttypes.models import ContentType
|
||||
from awx.api.views import (
|
||||
RoleUsersList,
|
||||
UserRolesList,
|
||||
TeamRolesList,
|
||||
)
|
||||
|
||||
from awx.main.models import (
|
||||
@ -23,7 +24,7 @@ from awx.main.models import (
|
||||
(1, "may not perform"),
|
||||
])
|
||||
def test_user_roles_list_user_admin_role(pk, err):
|
||||
with mock.patch('awx.api.views.Role.objects.get') as role_get, \
|
||||
with mock.patch('awx.api.views.get_object_or_400') as role_get, \
|
||||
mock.patch('awx.api.views.ContentType.objects.get_for_model') as ct_get:
|
||||
|
||||
role_mock = mock.MagicMock(spec=Role, id=1, pk=1)
|
||||
@ -75,3 +76,25 @@ def test_role_users_list_other_user_admin_role(admin_role, err):
|
||||
|
||||
assert response.status_code == 403
|
||||
assert err in response.content
|
||||
|
||||
def test_team_roles_list_post_org_roles():
|
||||
with mock.patch('awx.api.views.get_object_or_400') as role_get, \
|
||||
mock.patch('awx.api.views.ContentType.objects.get_for_model') as ct_get:
|
||||
|
||||
role_mock = mock.MagicMock(spec=Role)
|
||||
content_type_mock = mock.MagicMock(spec=ContentType)
|
||||
role_mock.content_type = content_type_mock
|
||||
role_get.return_value = role_mock
|
||||
ct_get.return_value = content_type_mock
|
||||
|
||||
factory = APIRequestFactory()
|
||||
view = TeamRolesList.as_view()
|
||||
|
||||
request = factory.post("/team/1/roles", {'id':1}, format="json")
|
||||
force_authenticate(request, User(username="root", is_superuser=True))
|
||||
|
||||
response = view(request)
|
||||
response.render()
|
||||
|
||||
assert response.status_code == 400
|
||||
assert 'cannot assign' in response.content
|
||||
|
@ -1,22 +1,11 @@
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from rest_framework.test import APIRequestFactory
|
||||
from rest_framework.test import force_authenticate
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
from awx.api.views import (
|
||||
ApiV1RootView,
|
||||
TeamRolesList,
|
||||
JobTemplateLabelList,
|
||||
)
|
||||
|
||||
from awx.main.models import (
|
||||
User,
|
||||
Role,
|
||||
)
|
||||
|
||||
@pytest.fixture
|
||||
def mock_response_new(mocker):
|
||||
m = mocker.patch('awx.api.views.Response.__new__')
|
||||
@ -68,30 +57,6 @@ class TestJobTemplateLabelList:
|
||||
with mock.patch('awx.api.generics.DeleteLastUnattachLabelMixin.unattach') as mixin_unattach:
|
||||
view = JobTemplateLabelList()
|
||||
mock_request = mock.MagicMock()
|
||||
|
||||
|
||||
super(JobTemplateLabelList, view).unattach(mock_request, None, None)
|
||||
assert mixin_unattach.called_with(mock_request, None, None)
|
||||
|
||||
@pytest.mark.parametrize("url", ["/team/1/roles", "/role/1/teams"])
|
||||
def test_team_roles_list_post_org_roles(url):
|
||||
with mock.patch('awx.api.views.get_object_or_400') as mock_get_obj, \
|
||||
mock.patch('awx.api.views.ContentType.objects.get_for_model') as ct_get:
|
||||
|
||||
role_mock = mock.MagicMock(spec=Role)
|
||||
content_type_mock = mock.MagicMock(spec=ContentType)
|
||||
role_mock.content_type = content_type_mock
|
||||
mock_get_obj.return_value = role_mock
|
||||
ct_get.return_value = content_type_mock
|
||||
|
||||
factory = APIRequestFactory()
|
||||
view = TeamRolesList.as_view()
|
||||
|
||||
request = factory.post(url, {'id':1}, format="json")
|
||||
force_authenticate(request, User(username="root", is_superuser=True))
|
||||
|
||||
response = view(request)
|
||||
response.render()
|
||||
|
||||
assert response.status_code == 400
|
||||
assert 'cannot assign' in response.content
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user