def switch_data_status(request): """switch the data status Returns: """ try: data_id = request.POST.get("data_id", None) new_status = request.POST.get("new_status", None) if data_id is not None and new_status is not None: data = data_api.get_by_id(data_id, request.user) data_registry_api.set_status(data, new_status, request) else: return HttpResponseBadRequest( json.dumps({"message": "The data id and the new status are required"}), content_type="application/javascript", ) except exceptions.DoesNotExist as dne: return HttpResponseBadRequest( json.dumps({"message": escape(str(dne))}), content_type="application/json" ) except Exception as e: return HttpResponseBadRequest( json.dumps({"message": escape(str(e))}), content_type="application/javascript", ) return HttpResponse(json.dumps({}), content_type="application/javascript")
def test_data_set_status_to_deleted_raise_exception_if_data_is_not_published(self, mock_convert_to_file): # Arrange user = create_mock_user('1', True, True) status = data_registry_api.get_status(self.fixture.data_1) self.assertTrue(status == DataStatus.ACTIVE) # Act Assert with self.assertRaises(exceptions.ModelError): data_registry_api.set_status(self.fixture.data_1, DataStatus.DELETED, user)
def switch_data_status(request): """ switch the data status Returns: """ try: data_id = request.POST.get('data_id', None) new_status = request.POST.get('new_status', None) if data_id is not None and new_status is not None: data = data_api.get_by_id(data_id, request.user) data_registry_api.set_status(data, new_status, request.user) else: return HttpResponseBadRequest(json.dumps({'message': 'The data id and the new status are required'}), content_type='application/javascript') except exceptions.DoesNotExist, dne: return HttpResponseBadRequest(json.dumps({'message': dne.message}), content_type='application/json')
def test_data_set_status_to_inactive_should_always_work(self, mock_convert_to_file): # Arrange user = create_mock_user('1', True, True) status = data_registry_api.get_status(self.fixture.data_1) self.assertTrue(status == DataStatus.ACTIVE) # Act data = data_registry_api.set_status(self.fixture.data_1, DataStatus.INACTIVE, user) status = data_registry_api.get_status(data) # Assert self.assertTrue(status == DataStatus.INACTIVE)