def test_follow_409(db_conn, session): """ Expect to fail to follow entity if already followed. """ raw_insert_units(db_conn, [{ 'entity_id': unit_a_uuid, 'name': 'Foo', 'body': 'Foo', }]) raw_insert_follows(db_conn, [{ 'user_id': user_id, 'entity_kind': 'unit', 'entity_id': unit_a_uuid, }]) request = { 'cookies': { 'session_id': session }, 'params': { 'entity_kind': 'unit', 'entity_id': unit_a_uuid, }, 'db_conn': db_conn } code, _ = routes.follow.follow_route(request) assert code == 400
def test_list_follows_route(db_conn, session): """ Expect to get a list of follows for user. """ raw_insert_follows(db_conn, [{ 'user_id': user_id, 'entity_kind': 'card', 'entity_id': card_b_uuid, }, { 'user_id': user_id, 'entity_kind': 'unit', 'entity_id': unit_a_uuid, }]) request = { 'cookies': { 'session_id': session }, 'params': {}, 'db_conn': db_conn, } code, response = routes.follow.get_follows_route(request) assert code == 200 assert len(response['follows']) == 2
def test_unfollow(db_conn, session): """ Expect to unfollow an entity. """ raw_insert_follows(db_conn, [{ 'id': follow_a_uuid, 'user_id': user_id, 'entity_kind': 'unit', 'entity_id': unit_a_uuid, }]) request = {'cookies': {'session_id': session}, 'db_conn': db_conn} code, _ = routes.follow.unfollow_route(request, follow_a_uuid) assert code == 200
def create_test_follows(db_conn): users = [{ 'id': user_uuid, 'name': 'test', 'email': '*****@*****.**', 'password': '******', }, { 'id': user_b_uuid, 'name': 'other', 'email': '*****@*****.**', 'password': '******', }] raw_insert_users(db_conn, users) units = [{ 'user_id': user_uuid, 'entity_id': test_unit_uuid, 'name': 'test unit add', 'body': 'adding numbers is fun' }, { 'user_id': user_uuid, 'entity_id': test_unit_b_uuid, 'name': 'test unit subtract', 'body': 'subtracting numbers is fun' }] raw_insert_units(db_conn, units) follows = [{ 'id': test_follow_a_id, 'user_id': user_uuid, 'entity_id': test_unit_uuid, 'entity_kind': 'unit', }, { 'user_id': user_uuid, 'entity_id': test_unit_b_uuid, 'entity_kind': 'unit', }, { 'user_id': user_b_uuid, 'entity_id': test_unit_uuid, 'entity_kind': 'unit', }] raw_insert_follows(db_conn, follows)
def test_unfollow_403(db_conn, session): """ Expect to unfollow an entity. """ user_b_uuid = uuid.uuid4() raw_insert_users(db_conn, [{ 'id': user_b_uuid, 'name': 'other', 'email': '*****@*****.**', 'password': '******', }]) raw_insert_follows(db_conn, [{ 'id': follow_a_uuid, 'user_id': user_b_uuid, 'entity_kind': 'unit', 'entity_id': unit_a_uuid, }]) request = {'cookies': {'session_id': session}, 'db_conn': db_conn} code, _ = routes.follow.unfollow_route(request, follow_a_uuid) assert code == 403