mirror of
https://github.com/ansible/awx.git
synced 2026-02-19 12:10:06 -03:30
Merge pull request #2707 from chrismeyersfsu/fix-label_mixin_ordering
fix delete last label disassociate
This commit is contained in:
@@ -452,7 +452,7 @@ class SubListCreateAttachDetachAPIView(SubListCreateAPIView):
|
|||||||
|
|
||||||
class DeleteLastUnattachLabelMixin(object):
|
class DeleteLastUnattachLabelMixin(object):
|
||||||
def unattach(self, request, *args, **kwargs):
|
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:
|
if res:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|||||||
@@ -2380,7 +2380,7 @@ class JobTemplateNotificationTemplatesSuccessList(SubListCreateAttachDetachAPIVi
|
|||||||
parent_model = JobTemplate
|
parent_model = JobTemplate
|
||||||
relationship = 'notification_templates_success'
|
relationship = 'notification_templates_success'
|
||||||
|
|
||||||
class JobTemplateLabelList(SubListCreateAttachDetachAPIView, DeleteLastUnattachLabelMixin):
|
class JobTemplateLabelList(DeleteLastUnattachLabelMixin, SubListCreateAttachDetachAPIView):
|
||||||
|
|
||||||
model = Label
|
model = Label
|
||||||
serializer_class = LabelSerializer
|
serializer_class = LabelSerializer
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ class TestDeleteLastUnattachLabelMixin:
|
|||||||
|
|
||||||
view.unattach(mock_request, None, None)
|
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)
|
super.unattach_by_id.assert_called_with(mock_request, mock_sub_id)
|
||||||
mock_label.is_detached.assert_called_with()
|
mock_label.is_detached.assert_called_with()
|
||||||
mock_label.objects.get.assert_called_with(id=mock_sub_id)
|
mock_label.objects.get.assert_called_with(id=mock_sub_id)
|
||||||
@@ -154,7 +154,7 @@ class TestDeleteLastUnattachLabelMixin:
|
|||||||
|
|
||||||
res = view.unattach(mock_request, None, None)
|
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
|
assert mock_response == res
|
||||||
|
|
||||||
class TestParentMixin:
|
class TestParentMixin:
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||||||
from awx.api.views import (
|
from awx.api.views import (
|
||||||
ApiV1RootView,
|
ApiV1RootView,
|
||||||
TeamRolesList,
|
TeamRolesList,
|
||||||
|
JobTemplateLabelList,
|
||||||
)
|
)
|
||||||
|
|
||||||
from awx.main.models import (
|
from awx.main.models import (
|
||||||
@@ -62,6 +63,15 @@ class TestApiV1RootView:
|
|||||||
for endpoint in endpoints:
|
for endpoint in endpoints:
|
||||||
assert endpoint in data_arg
|
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"])
|
@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.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 response.status_code == 400
|
||||||
assert 'cannot assign' in response.content
|
assert 'cannot assign' in response.content
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user