mirror of
https://github.com/ansible/awx.git
synced 2026-03-08 05:01:09 -02:30
RoleTeam and TeamRole sublist NotFound exception handling and test update
This commit is contained in:
@@ -879,7 +879,7 @@ class TeamRolesList(SubListCreateAttachDetachAPIView):
|
|||||||
data = dict(msg="Role 'id' field is missing.")
|
data = dict(msg="Role 'id' field is missing.")
|
||||||
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
role = Role.objects.get(pk=sub_id)
|
role = get_object_or_400(Role, pk=sub_id)
|
||||||
content_type = ContentType.objects.get_for_model(Organization)
|
content_type = ContentType.objects.get_for_model(Organization)
|
||||||
if role.content_type == content_type:
|
if role.content_type == content_type:
|
||||||
data = dict(msg="You cannot assign an Organization role as a child role for a Team.")
|
data = dict(msg="You cannot assign an Organization role as a child role for a Team.")
|
||||||
@@ -3678,7 +3678,7 @@ class RoleTeamsList(SubListAPIView):
|
|||||||
data = dict(msg="You cannot assign an Organization role as a child role for a Team.")
|
data = dict(msg="You cannot assign an Organization role as a child role for a Team.")
|
||||||
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
return Response(data, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
team = Team.objects.get(pk=sub_id)
|
team = get_object_or_400(Team, pk=sub_id)
|
||||||
action = 'attach'
|
action = 'attach'
|
||||||
if request.data.get('disassociate', None):
|
if request.data.get('disassociate', None):
|
||||||
action = 'unattach'
|
action = 'unattach'
|
||||||
|
|||||||
@@ -74,13 +74,13 @@ class TestJobTemplateLabelList:
|
|||||||
|
|
||||||
@pytest.mark.parametrize("url", ["/team/1/roles", "/role/1/teams"])
|
@pytest.mark.parametrize("url", ["/team/1/roles", "/role/1/teams"])
|
||||||
def test_team_roles_list_post_org_roles(url):
|
def test_team_roles_list_post_org_roles(url):
|
||||||
with mock.patch('awx.api.views.Role.objects.get') as role_get, \
|
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:
|
mock.patch('awx.api.views.ContentType.objects.get_for_model') as ct_get:
|
||||||
|
|
||||||
role_mock = mock.MagicMock(spec=Role)
|
role_mock = mock.MagicMock(spec=Role)
|
||||||
content_type_mock = mock.MagicMock(spec=ContentType)
|
content_type_mock = mock.MagicMock(spec=ContentType)
|
||||||
role_mock.content_type = content_type_mock
|
role_mock.content_type = content_type_mock
|
||||||
role_get.return_value = role_mock
|
mock_get_obj.return_value = role_mock
|
||||||
ct_get.return_value = content_type_mock
|
ct_get.return_value = content_type_mock
|
||||||
|
|
||||||
factory = APIRequestFactory()
|
factory = APIRequestFactory()
|
||||||
|
|||||||
Reference in New Issue
Block a user