def test_modify_user_profile_successfully(client):
    with patch('app_server.decorators.auth_required_decorator.validate_token'
               ) as mock:

        user_requesting = '*****@*****.**'
        mock.return_value = {
            'Message': 'token valido para user {0}'.format(user_requesting)
        }, 200

        with patch('app_server.users.put_auth_server') as mock_put_auth_server:

            serialized_user = {
                'Modify': 'successfully modified user with email [email protected]'
            }

            mock_put_auth_server.return_value.status_code = 200
            mock_put_auth_server.return_value.json.return_value = serialized_user
            with patch('app_server.users.modify_user_in_database'
                       ) as mock_modification_app_server:
                mock_modification_app_server.return_value = 200

                user_to_get_profile = '*****@*****.**'

                token = generate_app_token({'email': user_requesting})

                response = client.put('/api/users/' + user_to_get_profile,
                                      headers={'Authorization': token},
                                      follow_redirects=False)

                assert mock.called
                assert response.status_code == 200
                assert json.loads(response.data) == serialized_user
def test_get_user_profile_successfully(client):
    with patch('app_server.decorators.auth_required_decorator.validate_token'
               ) as mock:

        user_requesting = '*****@*****.**'
        mock.return_value = {
            'Message': 'token valido para user {0}'.format(user_requesting)
        }, 200

        with patch('app_server.users.get_auth_server_request'
                   ) as mock_get_auth_server:

            serialized_user = {
                'email': '*****@*****.**',
                'full name': 'Test',
                'phone number': '1234',
                'profile picture': 'test.jpg'
            }

            mock_get_auth_server.return_value.status_code = 200
            mock_get_auth_server.return_value.json.return_value = serialized_user

            user_to_get_profile = '*****@*****.**'

            token = generate_app_token({'email': user_requesting})

            response = client.get('/api/users/' + user_to_get_profile,
                                  headers={'Authorization': token},
                                  follow_redirects=False)

            assert mock.called
            assert response.status_code == 200
            assert json.loads(response.data) == serialized_user
def test_decode_token_successfully():
	user_data = {'email' : '*****@*****.**'}
	token = token_functions.generate_app_token(user_data)

	_result, status_code = token_functions.validate_token(token)

	assert status_code == 200
Ejemplo n.º 4
0
def test_get_own_videos_successfully(client):
    with patch('app_server.decorators.auth_required_decorator.validate_token'
               ) as mock:

        user_requesting = '*****@*****.**'
        mock.return_value = {
            'Message': 'token valido para user {0}'.format(user_requesting)
        }, 200

        with patch('app_server.videos.get_media_server_request'
                   ) as mock_get_media_server:

            mock_get_media_server.return_value.status_code = 200
            video_info = {'Video': 'video1', 'isPrivate': True}
            video_info2 = {'Video': 'video2', 'isPrivate': False}
            mock_get_media_server.return_value.json.return_value = [
                video_info, video_info2
            ]

            with patch('app_server.videos.append_data_to_videos'
                       ) as mock_append_data:
                mock_append_data.return_value = [video_info, video_info2]

                token = generate_app_token({'email': user_requesting})
                response = client.get(
                    '/api/users/videos/',
                    query_string={'user_id': user_requesting},
                    headers={'Authorization': token},
                    follow_redirects=False)

                assert mock.called
                assert mock_get_media_server.called
                assert response.status_code == 200
                assert len(json.loads(response.data)) == 2
                assert json.loads(response.data)[0] == video_info
def test_like_fails_user_not_found(client):
	client_db = MongoClient()
	collection = client_db[DB]['videos']

	status_code = insert_video_into_db('5df1679ee0acd518e5cfd002', empty_video_01, collection)
	assert status_code == HTTP_CREATED

	result = list(collection.find({}))
	assert len(result) == 1

	fake_user = {'email': '*****@*****.**'}
	token = generate_app_token(fake_user)
	response = client.post('/api/videos/22222225ef1679ee0acd518e/likes',
								headers={'Authorization': token},
								follow_redirects=False)

	assert response.status_code == HTTP_NOT_FOUND
	assert json.loads(response.data) == {'Like_video': 'User not found'}
	client_db.close()
def test_cant_get_user_profile_user_requesting_anohter_profile(client):
    with patch('app_server.decorators.auth_required_decorator.validate_token'
               ) as mock:

        user_requesting = '*****@*****.**'
        mock.return_value = {
            'Message': 'token valido para user {0}'.format(user_requesting)
        }, 200

        user_to_get_profile = '*****@*****.**'

        token = generate_app_token({'email': user_requesting})
        response = client.get('/api/users/' + user_to_get_profile,
                              headers={'Authorization': token},
                              follow_redirects=False)

        assert mock.called
        assert response.status_code == 412
        assert json.loads(response.data) == {
            'Error': 'requesting profile from another user'
        }
Ejemplo n.º 7
0
def test_get_videos_from_specific_user_with_users_being_friends(client):
    with patch('app_server.decorators.auth_required_decorator.validate_token'
               ) as mock:

        user_requesting = '*****@*****.**'
        mock.return_value = {
            'Message': 'token valido para user {0}'.format(user_requesting)
        }, 200

        with patch('app_server.videos.get_media_server_request'
                   ) as mock_get_media_server:

            mock_get_media_server.return_value.status_code = 200
            video_info = {'Video': 'video1', 'latitude': 0, 'longitude': 0}
            mock_get_media_server.return_value.json.return_value = [video_info]

            with patch('app_server.videos.get_user_friends_from_db'
                       ) as mock_get_user_friends:

                mock_get_user_friends.return_value = [{
                    'email': user_requesting,
                    'fullName': 'test'
                }]
                with patch('app_server.videos.append_data_to_videos'
                           ) as mock_append_data:
                    mock_append_data.return_value = [video_info]
                    user_to_get_videos = '*****@*****.**'

                    token = generate_app_token({'email': user_requesting})
                    response = client.get(
                        '/api/users/videos/',
                        query_string={'user_id': user_to_get_videos},
                        headers={'Authorization': token},
                        follow_redirects=False)

                    assert mock.called
                    assert mock_get_media_server.called
                    assert mock_get_user_friends.called
                    assert response.status_code == 200
                    assert json.loads(response.data)[0] == video_info