mirror of
https://github.com/ansible/awx.git
synced 2026-04-05 01:59:25 -02:30
test org role as child for team 400s
This commit is contained in:
@@ -1,9 +1,17 @@
|
|||||||
|
import mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from rest_framework.test import APIRequestFactory
|
||||||
|
from rest_framework.test import force_authenticate
|
||||||
|
|
||||||
from awx.api.views import (
|
from awx.api.views import (
|
||||||
ApiV1RootView,
|
ApiV1RootView,
|
||||||
|
TeamRolesList,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from awx.main.models import (
|
||||||
|
User,
|
||||||
|
)
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_response_new(mocker):
|
def mock_response_new(mocker):
|
||||||
@@ -11,7 +19,6 @@ def mock_response_new(mocker):
|
|||||||
m.return_value = m
|
m.return_value = m
|
||||||
return m
|
return m
|
||||||
|
|
||||||
|
|
||||||
class TestApiV1RootView:
|
class TestApiV1RootView:
|
||||||
def test_get_endpoints(self, mocker, mock_response_new):
|
def test_get_endpoints(self, mocker, mock_response_new):
|
||||||
endpoints = [
|
endpoints = [
|
||||||
@@ -52,3 +59,24 @@ class TestApiV1RootView:
|
|||||||
for endpoint in endpoints:
|
for endpoint in endpoints:
|
||||||
assert endpoint in data_arg
|
assert endpoint in data_arg
|
||||||
|
|
||||||
|
@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.Role.objects.get', create=True) as role_get, \
|
||||||
|
mock.patch('awx.api.views.ContentType.objects.get_for_model', create=True) as ct_get:
|
||||||
|
|
||||||
|
role_mock = mock.MagicMock()
|
||||||
|
role_mock.content_type = 1
|
||||||
|
role_get.return_value = role_mock
|
||||||
|
ct_get.return_value = 1
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user