mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 08:21:15 +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 (
|
from awx.api.views import (
|
||||||
RoleUsersList,
|
RoleUsersList,
|
||||||
UserRolesList,
|
UserRolesList,
|
||||||
|
TeamRolesList,
|
||||||
)
|
)
|
||||||
|
|
||||||
from awx.main.models import (
|
from awx.main.models import (
|
||||||
@ -23,7 +24,7 @@ from awx.main.models import (
|
|||||||
(1, "may not perform"),
|
(1, "may not perform"),
|
||||||
])
|
])
|
||||||
def test_user_roles_list_user_admin_role(pk, err):
|
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:
|
mock.patch('awx.api.views.ContentType.objects.get_for_model') as ct_get:
|
||||||
|
|
||||||
role_mock = mock.MagicMock(spec=Role, id=1, pk=1)
|
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 response.status_code == 403
|
||||||
assert err in response.content
|
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 mock
|
||||||
import pytest
|
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 (
|
from awx.api.views import (
|
||||||
ApiV1RootView,
|
ApiV1RootView,
|
||||||
TeamRolesList,
|
|
||||||
JobTemplateLabelList,
|
JobTemplateLabelList,
|
||||||
)
|
)
|
||||||
|
|
||||||
from awx.main.models import (
|
|
||||||
User,
|
|
||||||
Role,
|
|
||||||
)
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_response_new(mocker):
|
def mock_response_new(mocker):
|
||||||
m = mocker.patch('awx.api.views.Response.__new__')
|
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:
|
with mock.patch('awx.api.generics.DeleteLastUnattachLabelMixin.unattach') as mixin_unattach:
|
||||||
view = JobTemplateLabelList()
|
view = JobTemplateLabelList()
|
||||||
mock_request = mock.MagicMock()
|
mock_request = mock.MagicMock()
|
||||||
|
|
||||||
super(JobTemplateLabelList, view).unattach(mock_request, None, None)
|
super(JobTemplateLabelList, view).unattach(mock_request, None, None)
|
||||||
assert mixin_unattach.called_with(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