-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_db_connection.py
45 lines (34 loc) · 1.2 KB
/
test_db_connection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Test file for database methods written in db.py
All test methods must receive client as an argument,
otherwise the database variable won't be configured correctly
"""
from mflix.db import get_movies, get_movie
import pytest
from pymongo import MongoClient
def get_coll_names(config):
"""
Method used in unit tests. Do not alter. You can cheat, but you only defeat
yourself.
"""
db = MongoClient(config['MFLIX_DB_URI'])["mflix"]
return db.list_collection_names()
@pytest.mark.connection
@pytest.mark.usefixtures('config')
def test_atlas_setup(client, config):
result = get_coll_names(config)
assert all(x in result for x in ['users', 'comments', 'movies'])
assert len(result) >= 5
@pytest.mark.connection
def test_basic_movies(client):
(actual, num_found) = get_movies({}, 0, 20)
assert num_found == 45993
assert(len(list(actual))) == 20
@pytest.mark.connection
def test_search_by_movie_id(client):
actual = get_movie("573a13eff29313caabdd82f3")
assert actual['title'] == 'The Martian'
@pytest.mark.connection
def test_simple_text_search(client):
(actual, _) = get_movies({"$text": {"$search": "The Martian"}}, 0, 20)
assert len(list(actual)) >= 4