diff --git a/awx/api/generics.py b/awx/api/generics.py index 6b4b7c6c3a..b4fbb45095 100644 --- a/awx/api/generics.py +++ b/awx/api/generics.py @@ -452,7 +452,7 @@ class SubListCreateAttachDetachAPIView(SubListCreateAPIView): class DeleteLastUnattachLabelMixin(object): def unattach(self, request, *args, **kwargs): - (sub_id, res) = super(DeleteLastUnattachLabelMixin, self).unattach_validate(request, *args, **kwargs) + (sub_id, res) = super(DeleteLastUnattachLabelMixin, self).unattach_validate(request) if res: return res diff --git a/awx/api/views.py b/awx/api/views.py index 59f7adb745..dec8307e05 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -2380,7 +2380,7 @@ class JobTemplateNotificationTemplatesSuccessList(SubListCreateAttachDetachAPIVi parent_model = JobTemplate relationship = 'notification_templates_success' -class JobTemplateLabelList(SubListCreateAttachDetachAPIView, DeleteLastUnattachLabelMixin): +class JobTemplateLabelList(DeleteLastUnattachLabelMixin, SubListCreateAttachDetachAPIView): model = Label serializer_class = LabelSerializer diff --git a/awx/main/tests/unit/api/test_generics.py b/awx/main/tests/unit/api/test_generics.py index 42d755abcf..ea925d68cb 100644 --- a/awx/main/tests/unit/api/test_generics.py +++ b/awx/main/tests/unit/api/test_generics.py @@ -138,7 +138,7 @@ class TestDeleteLastUnattachLabelMixin: view.unattach(mock_request, None, None) - super.unattach_validate.assert_called_with(mock_request, None, None) + super.unattach_validate.assert_called_with(mock_request) super.unattach_by_id.assert_called_with(mock_request, mock_sub_id) mock_label.is_detached.assert_called_with() mock_label.objects.get.assert_called_with(id=mock_sub_id) @@ -154,7 +154,7 @@ class TestDeleteLastUnattachLabelMixin: res = view.unattach(mock_request, None, None) - super.unattach_validate.assert_called_with(mock_request, None, None) + super.unattach_validate.assert_called_with(mock_request) assert mock_response == res class TestParentMixin: diff --git a/awx/main/tests/unit/api/test_views.py b/awx/main/tests/unit/api/test_views.py index 27442286c6..a03ef7adae 100644 --- a/awx/main/tests/unit/api/test_views.py +++ b/awx/main/tests/unit/api/test_views.py @@ -9,6 +9,7 @@ from django.contrib.contenttypes.models import ContentType from awx.api.views import ( ApiV1RootView, TeamRolesList, + JobTemplateLabelList, ) from awx.main.models import ( @@ -62,6 +63,15 @@ class TestApiV1RootView: for endpoint in endpoints: assert endpoint in data_arg +class TestJobTemplateLabelList: + def test_inherited_mixin_unattach(self): + 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.Role.objects.get') as role_get, \ @@ -84,3 +94,4 @@ def test_team_roles_list_post_org_roles(url): assert response.status_code == 400 assert 'cannot assign' in response.content +