def test_delete_friendship_relationship_fails_when_user_is_not_found(): with patch('app_server.relationships_functions.send_notification_to_user') as _mock: client = MongoClient() collection = client[DB]['users'] data = [] for i in range(0, 3): data.append({'email': 'test_{0}@test.com'.format(i), 'full name': '{0}'.format(i)}) insert_new_user(data[i], collection) for i in range(0, 1): insert_new_friendship_request(data[i]['email'], data[2]['email'], collection) respond_to_friendship_request(data[2]['email'], data[i]['email'], collection, accept=True) user = collection.find_one({'email': data[2]['email']}) assert len(user['friends']) == 1 status_code = delete_friendship_relationship(data[2]['email'], data[0]['email'], collection) assert status_code == HTTP_OK third_user = '******' # Not existing status_code = delete_friendship_relationship(data[2]['email'], third_user, collection) assert status_code == HTTP_NOT_FOUND user = collection.find_one({'email': data[2]['email']}) assert len(user['friends']) == 0 client.close()
def test_get_user_requests(): with patch('app_server.relationships_functions.send_notification_to_user') as _mock: client = MongoClient() collection = client[DB]['users'] data = [] for i in range(0, 4): data.append({'email': 'test_{0}@test.com'.format(i), 'full name': '{0}'.format(i)}) insert_new_user(data[i], collection) result = collection.find({}) assert len(list(result)) == 4 my_user = data[3] for i in range(0, 3): insert_new_friendship_request(data[i]['email'], my_user['email'], collection) result = get_user_requests_from_db(my_user['email'], collection) assert len(result) == 3 list_result = list(result) for i in range(0, 3): assert data[i]['email'] == list_result[i]['email'] for i in range(0, 3): respond_to_friendship_request(my_user['email'], data[i]['email'], collection, accept=True) result = get_user_requests_from_db(my_user['email'], collection) assert len(result) == 0 client.close()
def test_delete_friendship_relationship_fails_when_friendship_does_not_exist(): with patch('app_server.relationships_functions.send_notification_to_user') as _mock: client = MongoClient() collection = client[DB]['users'] data = [] for i in range(0, 3): data.append({'email': 'test_{0}@test.com'.format(i), 'full name': '{0}'.format(i)}) insert_new_user(data[i], collection) for i in range(0, 1): insert_new_friendship_request(data[i]['email'], data[2]['email'], collection) respond_to_friendship_request(data[2]['email'], data[i]['email'], collection, accept=True) user = collection.find_one({'email': data[2]['email']}) assert len(user['friends']) == 1 status_code = delete_friendship_relationship(data[2]['email'], data[1]['email'], collection) assert status_code == HTTP_FORBIDDEN user = collection.find_one({'email': data[2]['email']}) assert len(user['friends']) == 1 client.close()
def test_reject_friendship_non_existing_user_fails(): with patch('app_server.relationships_functions.send_notification_to_user') as _mock: client = MongoClient() collection = client[DB]['users'] data = [] for i in range(0, 2): data.append({'email': 'test_{0}@test.com'.format(i), 'full name': ''}) insert_new_user(data[i], collection) status_code = insert_new_friendship_request(data[1]['email'], data[0]['email'], collection) assert status_code == HTTP_CREATED user = collection.find_one({'email': data[0]['email']}) assert len(user['requests']) == 1 respond_to_friendship_request(data[0]['email'], data[1]['email'], collection, accept=True) third_user = '******' # Not existing result, status_code = respond_to_friendship_request(data[0]['email'], third_user, collection, accept=False) assert status_code == HTTP_NOT_FOUND assert result == {'Reject_friendship_request': 'La solicitud no se pudo completar porque uno de los usuarios no existe'} client.close()
def test_reject_friendship_non_existing_fails(): with patch('app_server.relationships_functions.send_notification_to_user') as _mock: client = MongoClient() collection = client[DB]['users'] data = [] for i in range(0, 2): data.append({'email': 'test_{0}@test.com'.format(i), 'full name': ''}) insert_new_user(data[i], collection) status_code = insert_new_friendship_request(data[1]['email'], data[0]['email'], collection) assert status_code == HTTP_CREATED user = collection.find_one({'email': data[0]['email']}) assert len(user['requests']) == 1 # La request la tiene que aceptar el usuario 0, no el 1 result, status_code = respond_to_friendship_request(data[1]['email'], data[0]['email'], collection, accept=False) assert status_code == HTTP_FORBIDDEN assert result == {'Reject_friendship_request': 'La solicitud de amistad que queres responder no existe'} client.close()
def test_reject_friendship_request_successfully(): with patch('app_server.relationships_functions.send_notification_to_user') as _mock: client = MongoClient() collection = client[DB]['users'] data = [] for i in range(0, 2): data.append({'email': 'test_{0}@test.com'.format(i), 'full name': ''}) insert_new_user(data[i], collection) status_code = insert_new_friendship_request(data[1]['email'], data[0]['email'], collection) assert status_code == HTTP_CREATED user = collection.find_one({'email': data[0]['email']}) assert len(user['requests']) == 1 result, status_code = respond_to_friendship_request(data[0]['email'], data[1]['email'], collection, accept=False) assert status_code == HTTP_OK assert result == {'Reject_friendship_request': 'Solicitud de amistad rechazada con éxito'} client.close()
def test_accept_friendship_request_successfully_appends_friends_to_user_in_db(): with patch('app_server.relationships_functions.send_notification_to_user') as _mock: client = MongoClient() collection = client[DB]['users'] data = [] for i in range(0, 2): data.append({'email': 'test_{0}@test.com'.format(i), 'full name': ''}) insert_new_user(data[i], collection) insert_new_friendship_request(data[1]['email'], data[0]['email'], collection) respond_to_friendship_request(data[0]['email'], data[1]['email'], collection, accept=True) user_0 = collection.find_one({'email': data[0]['email']}) assert len(user_0['friends']) == 1 user_1 = collection.find_one({'email': data[1]['email']}) assert len(user_1['friends']) == 1 client.close()
def test_filter_videos_for_specific_user_successfuly_friend_video(): client = MongoClient() collection = client[DB]['videos'] users_collection = client[DB]['users'] user1_email = '*****@*****.**' user2_email = '*****@*****.**' data = { 'title': 'test', 'url': 'test.com', 'user': user2_email, 'isPrivate': True } data2 = { 'title': 'test2', 'url': 'test2.com', 'user': '******', 'isPrivate': True } _id1 = '5edbc9196ab5430010391c79' _id2 = '5edbc9196ab5430010391c78' insert_video_into_db(_id1, data, collection) insert_video_into_db(_id2, data2, collection) data['_id'] = _id1 data2['_id'] = _id2 result = list(collection.find({})) assert len(result) == 2 user = { 'email': user1_email, 'full name': 'Prueba', 'friends': [], 'requests': [] } user2 = { 'email': user2_email, 'full name': 'Test', 'friends': [], 'requests': [] } insert_new_user(user, users_collection) insert_new_user(user2, users_collection) with patch('app_server.relationships_functions.send_notification_to_user' ) as _mock: insert_new_friendship_request(user2_email, user1_email, users_collection) respond_to_friendship_request(user1_email, user2_email, users_collection, accept=True) filtered_videos = filter_videos_for_specific_user([data, data2], '*****@*****.**', users_collection, collection) assert len(filtered_videos) == 1 assert filtered_videos[0] == data client.close()