def test_update_row_error(db_conn, session): query = """ UPDATE users SET name = %(name)s WHERE id = %(id)s RETURNING *; """ prev_data = { 'id': convert_slug_to_uuid(user_id), 'email': '*****@*****.**', 'password': '******', } data = { 'name': 'Hello!', } result, errors = update_row(db_conn, user_schema, query, prev_data, data) assert errors assert not result
def update_proposal(db_conn, prev_data, data): """ Update an existing proposal. """ schema = proposal_schema query = """ UPDATE posts SET body = %(body)s WHERE id = %(id)s AND kind = 'proposal' RETURNING *; """ data = { 'id': convert_slug_to_uuid(prev_data['id']), 'body': data.get('body') or prev_data.get('body'), } data, errors = update_row(db_conn, schema, query, prev_data, data) if not errors: add_post_to_es(db_conn, data) return data, errors
def update_topic(db_conn, prev_data, data): """ Update an existing topic. Only the name can be changed. """ schema = topic_schema query = """ UPDATE topics SET name = %(name)s WHERE id = %(id)s RETURNING *; """ data = { 'id': convert_slug_to_uuid(prev_data['id']), 'name': data['name'], } data, errors = update_row(db_conn, schema, query, prev_data, data) if not errors: add_topic_to_es(data) return data, errors
def update_card_parameters(db_conn, prev_data, data): """ Update Card Parameters [hidden] """ schema = card_parameters_schema query = """ UPDATE cards_parameters SET guess_distribution = %(guess_distribution)s, slip_distribution = %(slip_distribution)s WHERE entity_id = %(entity_id)s RETURNING *; """ data = { 'entity_id': convert_slug_to_uuid(prev_data['entity_id']), 'guess_distribution': data['guess_distribution'], 'slip_distribution': data['slip_distribution'], } data, errors = update_row(db_conn, schema, query, prev_data, data) return data, errors
def update_user(db_conn, prev_data, data): """ Update the user. Does not update password! """ schema = user_schema query = """ UPDATE users SET name = %(name)s, email = %(email)s, settings = %(settings)s WHERE id = %(id)s RETURNING *; """ data = { 'id': convert_slug_to_uuid(prev_data['id']), 'name': data.get('name', '').lower().strip() or None, 'email': data.get('email', '').lower().strip() or None, 'settings': data.get('settings'), } data, errors = update_row(db_conn, schema, query, prev_data, data) if not errors: add_user_to_es(data) return data, errors
def update_user_password(db_conn, prev_data, data): """ Update the user's password """ schema = user_schema query = """ UPDATE users SET password = %(password)s WHERE id = %(id)s RETURNING *; """ data = { 'id': convert_slug_to_uuid(prev_data['id']), 'password': data['password'], } data, errors = update_row(db_conn, schema, query, prev_data, data) if not errors: send_mail( subject='Sagefy - Password Updated', recipient=data['email'], body=PASSWORD_TEXT, ) return data, errors
def update_vote(db_conn, prev_data, data): """ Update an existing vote. """ schema = vote_schema query = """ UPDATE posts SET body = %(body)s, response = %(response)s WHERE id = %(id)s AND kind = 'vote' RETURNING *; """ data = { 'id': convert_slug_to_uuid(prev_data['id']), 'body': data.get('body') or prev_data.get('body'), 'response': (data['response'] if data['response'] is not None else prev_data['response']), } data, errors = update_row(db_conn, schema, query, prev_data, data) if not errors: add_post_to_es(db_conn, data) return data, errors