def post(self): """Initiate transfer request""" data = request.json subject_model = api.resolve_model(data["subject"]) subject_id = data["subject"]["id"] subject = subject_model.objects.get(id=subject_id) recipient_model = api.resolve_model(data["recipient"]) recipient_id = data["recipient"]["id"] recipient = recipient_model.objects.get(id=recipient_id) comment = data.get("comment") transfer = request_transfer(subject, recipient, comment) return transfer, 201
def post(self): '''Initiate transfer request''' data = request.json subject_model = api.resolve_model(data['subject']) subject_id = data['subject']['id'] subject = subject_model.objects.get(id=subject_id) recipient_model = api.resolve_model(data['recipient']) recipient_id = data['recipient']['id'] recipient = recipient_model.objects.get(id=recipient_id) comment = data.get('comment') transfer = request_transfer(subject, recipient, comment) return transfer, 201
def test_raise_if_missing_class_entry(self): with self.assertRaises(ValueError): api.resolve_model({'field': 'value'})
def test_resolve_exact_match(self): self.assertEqual(api.resolve_model('Dataset'), Dataset)
def test_raise_if_none(self): with self.assertRaises(ValueError): api.resolve_model(None)
def test_raise_if_not_a_document(self): with self.assertRaises(ValueError): api.resolve_model('UDataMongoEngine')
def test_raise_if_not_found(self): with self.assertRaises(ValueError): api.resolve_model('NotFound')
def test_resolve_from_dict(self): self.assertEqual(api.resolve_model({'class': 'Dataset'}), Dataset)
def test_resolve_convention_full(self): self.assertEqual(api.resolve_model('DatasetFull'), Dataset)