示例#1
0
def test_get_user_token_fails():
    client = MongoClient()
    collection = client[DB]['users']

    data = {'email': '@test.com', 'full name': ''}
    insert_new_user(data, collection)

    result = list(collection.find({}))
    first_user = result[0]

    user_token = get_user_token('@test.com', collection)
    client.close()

    assert len(result) == 1
    assert first_user['email'] == '@test.com'
    assert user_token == ''
示例#2
0
def test_filter_videos_for_specific_user_successfuly_all_own_videos():
    client = MongoClient()
    collection = client[DB]['videos']
    users_collection = client[DB]['users']

    user_filtering = '*****@*****.**'

    data = {
        'title': 'test',
        'url': 'test.com',
        'user': user_filtering,
        'isPrivate': True
    }

    data2 = {
        'title': 'test2',
        'url': 'test2.com',
        'user': user_filtering,
        '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': user_filtering, 'full name': 'Prueba'}
    insert_new_user(user, users_collection)

    filtered_videos = filter_videos_for_specific_user([data, data2],
                                                      user_filtering,
                                                      users_collection,
                                                      collection)
    assert len(filtered_videos) == 2
    assert filtered_videos[0] == data
    assert filtered_videos[1] == data2

    client.close()
示例#3
0
def test_add_notification_token():
    client = MongoClient()
    collection = client[DB]['users']

    data = {'email': '@test.com', 'full name': ''}
    insert_new_user(data, collection)

    status_code = add_notifications_token('@test.com', 'FAKE_TOKEN',
                                          collection)

    result = list(collection.find({}))
    first_user = result[0]
    client.close()

    assert len(result) == 1
    assert first_user['email'] == '@test.com'
    assert first_user['notifications_token'] == 'FAKE_TOKEN'
    assert status_code == HTTP_CREATED
def _register_user():

    data = request.json
    api_register = '/api/register/'
    url = os.environ.get('AUTH_SERVER_URL') + api_register

    data['profile picture'] = DEFAULT_PROFILE_PICTURE

    response = post_auth_server(url, data)
    logger.debug('Finished auth server register request')

    if response.status_code == 201:
        coll = 'users'
        result = insert_new_user(data, client[DB][coll])
        if result != 201:
            return {
                'Registration':
                'User {0} was registered successfully in AuthServer, yet'
                'operation failed in AppServers db'.format(data['email'])
            }, 500

    return response.text, response.status_code
示例#5
0
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()