Unit test connection Errors

pytest -m connection

Ini File dump below

Ticket: Connection

Rename this file to .ini after filling in your MFLIX_DB_URI and your SECRET_KEY

Do not surround the URI with quotes

[PROD]
SECRET_KEY = 1234567890A
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-k2qhh.mongodb.net/test?retryWrites=true&w=majority
MFLIX_NS = sample_mflix

[TEST]
SECRET_KEY = 1234567890A
MFLIX_DB_URI =
MFLIX_NS = sample_mflix


End of Ini File.

Can you please help ?
Thanks in advance

Errors:
(mflix) F:\mongouni\M220P>pytest -m connection
============================= test session starts =============================
platform win32 – Python 3.7.3, pytest-3.3.0, py-1.8.0, pluggy-0.6.0
rootdir: F:\mongouni\M220P, inifile: pytest.ini
plugins: remotedata-0.3.1, openfiles-0.3.2, flask-0.11.0, doctestplus-0.3.0, arr
aydiff-0.3
collected 43 items

tests\test_db_connection.py FFFF [100%]

================================== FAILURES ===================================
______________________________ test_atlas_setup _______________________________

client = <FlaskClient <Flask ‘mflix.factory’>>
config = <Config {‘DEBUG’: False, ‘TESTING’: False, ‘PROPAGATE_EXCEPTIONS’: True
, ‘PRESERVE_CONTEXT_ON_EXCEPTION’: None, ‘SECRE…DER’: <function create_app..add_claims at 0x000000000604E6A8>, ‘MFLIX_NS’: ‘sample_mflix’, ‘MFLIX_DB_U
RI’: ‘’}>

@pytest.mark.connection
@pytest.mark.usefixtures('config')
def test_atlas_setup(client, config):
  result = get_coll_names(config)

tests\test_db_connection.py:24:


tests\test_db_connection.py:17: in get_coll_names
db = MongoClient(config[‘MFLIX_DB_URI’])[“sample_mflix”]
c:\anaconda3\lib\site-packages\pymongo\mongo_client.py:501: in init
seeds.update(uri_parser.split_hosts(entity, port))


hosts = ‘’, default_port = 27017

def split_hosts(hosts, default_port=DEFAULT_PORT):
    """Takes a string of the form host1[:port],host2[:port]... and
    splits it into (host, port) tuples. If [:port] isn't present the
    default_port is used.

    Returns a set of 2-tuples containing the host name (or IP) followed by
    port number.

    :Parameters:
        - `hosts`: A string of the form host1[:port],host2[:port],...
        - `default_port`: The port number to use when one wasn't specified
          for a host.
    """
    nodes = []
    for entity in hosts.split(','):
        if not entity:
          raise ConfigurationError("Empty host "
                                     "(or extra comma in host list).")

E pymongo.errors.ConfigurationError: Empty host (or extra comma in
host list).

c:\anaconda3\lib\site-packages\pymongo\uri_parser.py:254: ConfigurationError
______________________________ test_basic_movies ______________________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.connection
def test_basic_movies(client):
  (actual, num_found) = get_movies({}, 0, 20)

tests\test_db_connection.py:31:


mflix\db.py:220: in get_movies
cursor = db.movies.find(query).sort(sort)
c:\anaconda3\lib\site-packages\werkzeug\local.py:348: in getattr
return getattr(self._get_current_object(), name)
c:\anaconda3\lib\site-packages\werkzeug\local.py:307: in _get_current_object
return self.__local()
mflix\db.py:47: in get_db
MFLIX_DB_URI,
c:\anaconda3\lib\site-packages\pymongo\mongo_client.py:501: in init
seeds.update(uri_parser.split_hosts(entity, port))


hosts = ‘’, default_port = 27017

def split_hosts(hosts, default_port=DEFAULT_PORT):
    """Takes a string of the form host1[:port],host2[:port]... and
    splits it into (host, port) tuples. If [:port] isn't present the
    default_port is used.

    Returns a set of 2-tuples containing the host name (or IP) followed by
    port number.

    :Parameters:
        - `hosts`: A string of the form host1[:port],host2[:port],...
        - `default_port`: The port number to use when one wasn't specified
          for a host.
    """
    nodes = []
    for entity in hosts.split(','):
        if not entity:
          raise ConfigurationError("Empty host "
                                     "(or extra comma in host list).")

E pymongo.errors.ConfigurationError: Empty host (or extra comma in
host list).

c:\anaconda3\lib\site-packages\pymongo\uri_parser.py:254: ConfigurationError
___________________________ test_search_by_movie_id ___________________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.connection
def test_search_by_movie_id(client):
    actual = get_movie("573a13acf29313caabd29647")
  assert actual['title'] == 'King Kong'

E KeyError: ‘title’

tests\test_db_connection.py:39: KeyError
___________________________ test_simple_text_search ___________________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.connection
def test_simple_text_search(client):
  (actual, _) = get_movies({"$text": {"$search": "King Kong"}}, 0, 20)

tests\test_db_connection.py:44:


mflix\db.py:220: in get_movies
cursor = db.movies.find(query).sort(sort)
c:\anaconda3\lib\site-packages\werkzeug\local.py:348: in getattr
return getattr(self._get_current_object(), name)
c:\anaconda3\lib\site-packages\werkzeug\local.py:307: in _get_current_object
return self.__local()
mflix\db.py:47: in get_db
MFLIX_DB_URI,
c:\anaconda3\lib\site-packages\pymongo\mongo_client.py:501: in init
seeds.update(uri_parser.split_hosts(entity, port))


hosts = ‘’, default_port = 27017

def split_hosts(hosts, default_port=DEFAULT_PORT):
    """Takes a string of the form host1[:port],host2[:port]... and
    splits it into (host, port) tuples. If [:port] isn't present the
    default_port is used.

    Returns a set of 2-tuples containing the host name (or IP) followed by
    port number.

    :Parameters:
        - `hosts`: A string of the form host1[:port],host2[:port],...
        - `default_port`: The port number to use when one wasn't specified
          for a host.
    """
    nodes = []
    for entity in hosts.split(','):
        if not entity:
          raise ConfigurationError("Empty host "
                                     "(or extra comma in host list).")

E pymongo.errors.ConfigurationError: Empty host (or extra comma in
host list).

c:\anaconda3\lib\site-packages\pymongo\uri_parser.py:254: ConfigurationError
============================= 39 tests deselected =============================
=================== 4 failed, 39 deselected in 0.78 seconds ===================

You got the error

While you configured

1 Like

MFLIX_DB_URI =
Above line should not be blank. Sorry

Many thanks for your help. Have a nice day!
P.S. I managed to finished the rest of the tickets for Chapter 1 , just in time.
Best regards
A.G.

1 Like