def test_create_missing_resource(self, mock_get_db_connection): """Raises an error when the resource data was not provided at init""" r = Resource(id='id') with pytest.raises(OperationOutcome, match='Missing resource data to create \ a Resource'): r = r.create() assert mock_get_db_connection.return_value.create.call_count == 0
def test_create_extra_id(self, mock_get_db_connection): """Raises an error when the resource data and an id were provided""" resource_data = {'my': 'resource'} test_id = {'id': 'id'} r = Resource(id=id, resource=resource_data) with pytest.raises(OperationOutcome, match='Cannot create a resource with \ an ID'): r = r.create() assert mock_get_db_connection.return_value.create.call_count == 0
def create_resource(res_type): if 'file' in request.files: _file = request.files['file'] options = { 'upload_file': _file, 'res_type': res_type, 'user_key': get_current_user() } if res_type == ResourceType.IMAGE: res = Image.create(**options) else: res = Resource.create(**options) return res.to_dict() else: raise errors.ApiError('NO_FILE_UPLOADED')
def test_create(self, mock_get_db_connection): """Calls the create method of the fhirbase client and registers the ID """ resource_data = {'my': 'resource'} test_id = {'id': 'id'} create_ret_data = {**resource_data, **test_id} mock_get_db_connection.return_value.create.return_value = \ create_ret_data r = Resource(resource=resource_data) r = r.create() mock_get_db_connection.return_value.create.assert_called_once_with({ 'resourceType': 'Resource', **resource_data }) assert r.id == test_id['id'] assert r.resource == create_ret_data