Skip to content

Commit

Permalink
Mapping reactivate test
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Apr 1, 2022
1 parent 65b35d0 commit 14b25ee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
27 changes: 27 additions & 0 deletions core/integration_tests/tests_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,3 +779,30 @@ def test_delete_204(self):
self.assertEqual(self.mapping.versions.first().extras, dict(foo='bar', tao='ching'))
self.mapping.refresh_from_db()
self.assertEqual(self.mapping.extras, dict(tao='ching'))


class MappingReactivateViewTest(OCLAPITestCase):
def test_put(self):
mapping = MappingFactory(retired=True)
self.assertTrue(mapping.retired)
self.assertTrue(mapping.get_latest_version().retired)
token = mapping.created_by.get_token()

response = self.client.put(
mapping.url + 'reactivate/',
HTTP_AUTHORIZATION='Token ' + token,
)

self.assertEqual(response.status_code, 204)
mapping.refresh_from_db()
self.assertFalse(mapping.retired)
self.assertFalse(mapping.get_latest_version().retired)
self.assertTrue(mapping.get_latest_version().prev_version.retired)

response = self.client.put(
mapping.url + 'reactivate/',
HTTP_AUTHORIZATION='Token ' + token,
)

self.assertEqual(response.status_code, 400)
self.assertEqual(response.data, {'__all__': 'Mapping is already not retired'})
7 changes: 1 addition & 6 deletions core/mappings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def get(self, request, *args, **kwargs):

class MappingReactivateView(MappingBaseView, UpdateAPIView):
serializer_class = MappingDetailSerializer
permission_classes = (CanEditParentDictionary, )

def get_object(self, queryset=None):
instance = self.get_queryset().filter(id=F('versioned_object_id')).first()
Expand All @@ -240,12 +241,6 @@ def get_object(self, queryset=None):
self.check_object_permissions(self.request, instance)
return instance

def get_permissions(self):
if self.request.method in ['GET']:
return [CanViewParentDictionary(), ]

return [CanEditParentDictionary(), ]

def update(self, request, *args, **kwargs):
mapping = self.get_object()
comment = request.data.get('update_comment', None) or request.data.get('comment', None)
Expand Down

0 comments on commit 14b25ee

Please sign in to comment.