def put(self, request, organization_slug, work_batch_id): workbatch = self.app.workbatches.get(id=work_batch_id) serializer = WorkBatchDetailsSerializer(workbatch, data=request.data) if not serializer.is_valid(): return self.respond(serializer.errors, status=400) serializer.save() return Response({}, status=status.HTTP_200_OK)
def test_can_instantiate_serializer__with_no_properties(self): data = { 'properties': None, 'id': 1, 'name': 'Test1', } serializer = WorkBatchDetailsSerializer(data=data) assert serializer.is_valid(), serializer.errors
def test_can_update_workbatch_properties__with_properties_set_to_empty(self): data = { 'id': 1, 'name': 'Test1', 'properties': {} } workbatch = MyWorkbatchImplementation(name='my_workbatch') workbatch.save() serializer = WorkBatchDetailsSerializer(workbatch, data=data) assert serializer.is_valid() updated_workbatch = serializer.save() assert updated_workbatch.kit_type is None
def test_update_workbatch_properties__with_empty_dict__previous_values_dont_change(self): # TODO: is this the intended behavour? data = { 'id': 1, 'name': 'Test1', 'properties': {} } workbatch = MyWorkbatchImplementation(name='my_workbatch') workbatch.kit_type = 'kit type value' workbatch.save() serializer = WorkBatchDetailsSerializer(workbatch, data=data) assert serializer.is_valid() updated_workbatch = serializer.save() assert updated_workbatch.kit_type == 'kit type value'
def test_can_update_workbatch_property__from_no_value(self): data = { 'id': 1, 'name': 'Test1', 'properties': { 'kit_type': {'value': 'kit type value'}, } } workbatch = MyWorkbatchImplementation(name='my_workbatch') workbatch.save() serializer = WorkBatchDetailsSerializer(workbatch, data=data) assert serializer.is_valid() updated_workbatch = serializer.save() assert updated_workbatch.kit_type == 'kit type value'