Example #1
0
def test_comment_video_fails_video_does_not_exist():
    client = MongoClient()
    collection = client[DB]['videos']

    video_data = {
        'title': 'test',
        'url': 'test.com',
        'user': '******',
        'isPrivate': True,
        'comments': []
    }

    _id = '5edbc9196ab5430010391c79'
    insert_video_into_db(_id, video_data, collection)

    user = '******'
    text = 'Este es un comentario de prueba'
    __inexistent_id = '5edbc9196ab5430010391c78'
    status_code = insert_comment_into_video(__inexistent_id, user, text,
                                            collection)
    assert status_code == HTTP_INTERNAL_SERVER_ERROR

    this_video = collection.find_one({'_id': ObjectId(_id)})

    assert len(this_video['comments']) == 0
    client.close()
Example #2
0
def test_second_comment_video_comes_first():
    client = MongoClient()
    collection = client[DB]['videos']

    video_data = {
        'title': 'test',
        'url': 'test.com',
        'user': '******',
        'isPrivate': True,
        'comments': []
    }

    _id = '5edbc9196ab5430010391c79'
    insert_video_into_db(_id, video_data, collection)

    user = '******'
    text_01 = 'Este es un comentario de prueba'
    insert_comment_into_video(_id, user, text_01, collection)
    text_02 = 'Este es el segundo comentario'
    status_code = insert_comment_into_video(_id, user, text_02, collection)
    assert status_code == HTTP_CREATED

    this_video = collection.find_one({'_id': ObjectId(_id)})

    assert len(this_video['comments']) == 2
    comment = this_video['comments'][0]

    assert comment['text'] == text_02
    assert comment['user'] == user
    assert 'timestamp' in comment.keys()
    client.close()
Example #3
0
def test_ten_comments_in_order():
    client = MongoClient()
    collection = client[DB]['videos']

    video_data = {
        'title': 'test',
        'url': 'test.com',
        'user': '******',
        'isPrivate': True,
        'comments': []
    }

    _id = '5edbc9196ab5430010391c79'
    insert_video_into_db(_id, video_data, collection)

    user = '******'
    text = 'Este es el comentario numero {0}'
    for i in range(0, 10):
        text = text.format(i)
        insert_comment_into_video(_id, user, text, collection)

    this_video = collection.find_one({'_id': ObjectId(_id)})

    assert len(this_video['comments']) == 10

    for i in range(10, 0):
        comment = this_video['comments'][i]
        assert comment['text'] == text.format(i)

    client.close()
Example #4
0
def test_insert_ten_videos():
    client = MongoClient()
    collection = client[DB]['videos']
    for i in range(0, 10):
        data = {
            'title': 'test_{0}'.format(i),
            'url': 'test.com',
            'user': '******',
            'isPrivate': False
        }

        # Esto se hace porque sino el id es repetido y tira conflicto.
        _id = '5edbc9196ab5430010391c7' + str(i)
        insert_video_into_db(_id, data, collection)

    fifth_video = collection.find_one({'title': 'test_5'})
    assert fifth_video is not None
    assert not fifth_video['is_private']
    eleventh_video = collection.find_one({'title': 'test_11'})
    assert eleventh_video is None

    result = list(collection.find({}))
    client.close()

    assert len(result) == 10
    for counter, document in enumerate(result):
        assert document['title'] == 'test_{0}'.format(counter)
def test_delete_inexistent_dislike_fails():
	client = MongoClient()
	collection = client[DB]['videos']

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

	fake_user = {'email': '*****@*****.**'}
	status_code = delete_like_video(_id, fake_user, collection)
	assert status_code == HTTP_CONFLICT
	client.close()
def test_video_not_found_fails():
	client = MongoClient()
	collection = client[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': '*****@*****.**'}
	status_code = like_video('22222225ef1679ee0acd518e', fake_user, collection)
	assert status_code == HTTP_NOT_FOUND
	client.close()
def test_like_is_successful():
	client = MongoClient()
	collection = client[DB]['videos']

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

	fake_user = {'email': '*****@*****.**'}
	status_code = like_video(_id, fake_user, collection)
	assert status_code == HTTP_CREATED

	video = collection.find_one({'_id': ObjectId(_id)})
	assert fake_user['email'] in video['likes']
	client.close()
Example #8
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()
Example #9
0
def test_insert_duplicate_key_video_fails():
    client = MongoClient()
    collection = client[DB]['videos']

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

    insert_video_into_db('5edbc9196ab5430010391c79', data, collection)
    response = insert_video_into_db('5edbc9196ab5430010391c79', data,
                                    collection)

    client.close()

    assert response == HTTP_INTERNAL_SERVER_ERROR