def patch_connection(connection_id): conn_type = request.args.get('connection_type') connection = Connection.query.get(connection_id) connection.connection_type = conn_type connection.update(connection) connection_schema = ConnectionSchema() return connection_schema.jsonify(connection), HTTPStatus.OK
def test_schema_validates_parent_older_than_child(db, from_dob, to_dob, conn_type, error_message): from_person = PersonFactory(date_of_birth=date(*from_dob)) to_person = PersonFactory(date_of_birth=date(*to_dob)) db.session.commit() schema = ConnectionSchema() with pytest.raises(ValidationError) as exception_info: schema.load({'from_person_id': from_person.id, 'to_person_id': to_person.id, 'connection_type': conn_type}) schema_validation_messages = exception_info.value.messages['_schema'] assert len(schema_validation_messages) == 1 assert schema_validation_messages[0] == f'Invalid connection - {error_message}.'
def update_connection_type(args, connection_id): connection_schema = ConnectionSchema() new_connection_type = args['connection_type'] connection = Connection.query.get_or_404( connection_id) # If not found, return 404 # Validate Connection Type if new_connection_type not in ConnectionType.list(): return 'Invalid Connection Type', HTTPStatus.BAD_REQUEST # Set value and save connection.connection_type = ConnectionType[new_connection_type] connection.save() return connection_schema.jsonify(connection), HTTPStatus.OK
def update_connection(data, connection_id): connection = Connection.query.get(connection_id) connection.connection_type = data.connection_type connection.save() # It's arguably whether or not we need to return # result body. But let's keep in consistent return ConnectionSchema().jsonify(connection), HTTPStatus.OK
def patch_connection(args, connection_id): Connection.query.get_or_404(connection_id) Connection.query.filter_by(id=connection_id).update( {'connection_type': args['connection_type']}) return ConnectionSchema().jsonify( Connection.query.get(connection_id)), HTTPStatus.OK
def patch_connection(args, connection_id): Connection.query.get_or_404(connection_id) (Connection.query .filter_by(id=connection_id) .update({'connection_type': args['connection_type']})) cache.delete('all_connections') cache.delete('mutual_friends') return ConnectionSchema().jsonify(Connection.query.get(connection_id)), HTTPStatus.OK
def update_connection(connection_data, connection_id): connection = Connection.query.get(connection_id) if connection is not None: connection.connection_type = connection_data.connection_type connection.save() return ConnectionSchema().jsonify(connection), HTTPStatus.OK else: res = {"description": "Connection ID does not exist."} return flask.jsonify(res), HTTPStatus.BAD_REQUEST
def create_connection(connection): connection.save() cache.delete('all_connections') cache.delete('mutual_friends') return ConnectionSchema().jsonify(connection), HTTPStatus.CREATED
def get_connections(): connection_schema = ConnectionSchema(many=True) connections = Connection.query.all() return connection_schema.jsonify(connections), HTTPStatus.OK
mutuals = source.mutual_friends(target) return people_schema.jsonify(mutuals), HTTPStatus.OK @blueprint.route('/connections', methods=['GET']) @cache.cached(key_prefix='all_connections') def get_connections(): connection_schema = ConnectionSchema(many=True) connections = Connection.query.all() return connection_schema.jsonify(connections), HTTPStatus.OK @blueprint.route('/connections', methods=['POST']) @use_args(ConnectionSchema(), locations=('json',)) def create_connection(connection): connection.save() cache.delete('all_connections') cache.delete('mutual_friends') return ConnectionSchema().jsonify(connection), HTTPStatus.CREATED @blueprint.route('/connections/<connection_id>', methods=['PATCH']) @use_args({'connection_type': fields.Str( location='json', validate=lambda x: ConnectionType.has_type(x) )}) def patch_connection(args, connection_id): Connection.query.get_or_404(connection_id) (Connection.query
def patch_connection(connection, connection_id): Connection.update().filter(Connection.id == connection_id) return ConnectionSchema().jsonify(connection), HTTPStatus.CREATED
def create_connection(connection): connection.save() return ConnectionSchema().jsonify(connection), HTTPStatus.CREATED
def get_connection(): connection_schema = ConnectionSchema(many=True) connection = Connection.query.join( Person, Person.id == Connection.from_person_id).all() pprint.pprint(connection[0]) return connection_schema.jsonify(connection), HTTPStatus.OK
def delete_connection(connection_id): connection = Connection.query.get(connection_id) connection.delete(connection) connection_schema = ConnectionSchema() return connection_schema.jsonify(connection), HTTPStatus.OK
def get_connection(connection_id): connection_schema = ConnectionSchema() connection = Connection.query.get(connection_id) return connection_schema.jsonify(connection), HTTPStatus.OK
def update_connection_type(request, connection_id): connection = Connection.query.filter(Connection.id == connection_id).one() connection.connection_type = request.connection_type return ConnectionSchema().jsonify(connection), HTTPStatus.OK