mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 08:21:15 +03:00
Merge pull request #2707 from chrismeyersfsu/fix-label_mixin_ordering
fix delete last label disassociate
This commit is contained in:
commit
c0ef749c64
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user