Getting an error when I run the pytest -m connection command!

============================= test session starts =============================
platform win32 – Python 3.8.3, pytest-3.3.0, py-1.8.0, pluggy-0.6.0
rootdir: C:\Users\Rashidov\Desktop\mflix-python, inifile: pytest.ini
plugins: flask-0.11.0
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…>, ‘MFLIX_NS’: ‘sample_mflix’, ‘MFLIX_DB_URI’: ‘mongod
b+srv://m220student:m220password@@mflix.lwyvt.mongodb.net/test’}>

@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”]
…\anaconda3\lib\site-packages\pymongo\mongo_client.py:494: in init
res = uri_parser.parse_uri(entity, port, warn=True)
…\anaconda3\lib\site-packages\pymongo\uri_parser.py:379: in parse_uri
user, passwd = parse_userinfo(userinfo)


userinfo = ‘m220student:m220password@’

def parse_userinfo(userinfo):
    """Validates the format of user information in a MongoDB URI.
    Reserved characters like ':', '/', '+' and '@' must be escaped
    following RFC 3986.

    Returns a 2-tuple containing the unescaped username followed
    by the unescaped password.

    :Paramaters:
        - `userinfo`: A string of the form <username>:<password>

    .. versionchanged:: 2.2
       Now uses `urllib.unquote_plus` so `+` characters must be escaped.
    """
    if '@' in userinfo or userinfo.count(':') > 1:
        if PY3:
            quote_fn = "urllib.parse.quote_plus"
        else:
            quote_fn = "urllib.quote_plus"
      raise InvalidURI("Username and password must be escaped according to "
                         "RFC 3986, use %s()." % quote_fn)

E pymongo.errors.InvalidURI: Username and password must be escaped according to RFC 3986, use urllib.parse.quote_plus().

…\anaconda3\lib\site-packages\pymongo\uri_parser.py:96: InvalidURI
______________________________ 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)
…\anaconda3\lib\site-packages\werkzeug\local.py:348: in getattr
return getattr(self._get_current_object(), name)
…\anaconda3\lib\site-packages\werkzeug\local.py:307: in _get_current_object
return self.__local()
mflix\db.py:46: in get_db
db = g._database = MongoClient(
…\anaconda3\lib\site-packages\pymongo\mongo_client.py:494: in init
res = uri_parser.parse_uri(entity, port, warn=True)
…\anaconda3\lib\site-packages\pymongo\uri_parser.py:379: in parse_uri
user, passwd = parse_userinfo(userinfo)


userinfo = ‘m220student:m220password@’

def parse_userinfo(userinfo):
    """Validates the format of user information in a MongoDB URI.
    Reserved characters like ':', '/', '+' and '@' must be escaped
    following RFC 3986.

    Returns a 2-tuple containing the unescaped username followed
    by the unescaped password.

    :Paramaters:
        - `userinfo`: A string of the form <username>:<password>

    .. versionchanged:: 2.2
       Now uses `urllib.unquote_plus` so `+` characters must be escaped.
    """
    if '@' in userinfo or userinfo.count(':') > 1:
        if PY3:
            quote_fn = "urllib.parse.quote_plus"
        else:
            quote_fn = "urllib.quote_plus"
      raise InvalidURI("Username and password must be escaped according to "
                         "RFC 3986, use %s()." % quote_fn)

E pymongo.errors.InvalidURI: Username and password must be escaped according to RFC 3986, use urllib.parse.quote_plus().

…\anaconda3\lib\site-packages\pymongo\uri_parser.py:96: InvalidURI
___________________________ 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)
…\anaconda3\lib\site-packages\werkzeug\local.py:348: in getattr
return getattr(self._get_current_object(), name)
…\anaconda3\lib\site-packages\werkzeug\local.py:307: in _get_current_object
return self.__local()
mflix\db.py:46: in get_db
db = g._database = MongoClient(
…\anaconda3\lib\site-packages\pymongo\mongo_client.py:494: in init
res = uri_parser.parse_uri(entity, port, warn=True)
…\anaconda3\lib\site-packages\pymongo\uri_parser.py:379: in parse_uri
user, passwd = parse_userinfo(userinfo)


userinfo = ‘m220student:m220password@’

def parse_userinfo(userinfo):
    """Validates the format of user information in a MongoDB URI.
    Reserved characters like ':', '/', '+' and '@' must be escaped
    following RFC 3986.

    Returns a 2-tuple containing the unescaped username followed
    by the unescaped password.

    :Paramaters:
        - `userinfo`: A string of the form <username>:<password>

    .. versionchanged:: 2.2
       Now uses `urllib.unquote_plus` so `+` characters must be escaped.
    """
    if '@' in userinfo or userinfo.count(':') > 1:
        if PY3:
            quote_fn = "urllib.parse.quote_plus"
        else:
            quote_fn = "urllib.quote_plus"
      raise InvalidURI("Username and password must be escaped according to "
                         "RFC 3986, use %s()." % quote_fn)

E pymongo.errors.InvalidURI: Username and password must be escaped according to RFC 3986, use urllib.parse.quote_plus().

…\anaconda3\lib\site-packages\pymongo\uri_parser.py:96: InvalidURI
============================= 39 tests deselected =============================
=================== 4 failed, 39 deselected in 0.34 seconds ===================

(base) C:\Users\Rashidov\Desktop\mflix-python>pytest -m connection
============================= test session starts =============================
platform win32 – Python 3.8.3, pytest-3.3.0, py-1.8.0, pluggy-0.6.0
rootdir: C:\Users\Rashidov\Desktop\mflix-python, inifile: pytest.ini
plugins: flask-0.11.0
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…>, ‘MFLIX_NS’: ‘sample_mflix’, ‘MFLIX_DB_URI’: ‘mongod
b+srv://m220student:m220password@@mflix.lwyvt.mongodb.net/test’}>

@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”]
…\anaconda3\lib\site-packages\pymongo\mongo_client.py:494: in init
res = uri_parser.parse_uri(entity, port, warn=True)
…\anaconda3\lib\site-packages\pymongo\uri_parser.py:379: in parse_uri
user, passwd = parse_userinfo(userinfo)


userinfo = ‘m220student:m220password@’

def parse_userinfo(userinfo):
    """Validates the format of user information in a MongoDB URI.
    Reserved characters like ':', '/', '+' and '@' must be escaped
    following RFC 3986.

    Returns a 2-tuple containing the unescaped username followed
    by the unescaped password.

    :Paramaters:
        - `userinfo`: A string of the form <username>:<password>

    .. versionchanged:: 2.2
       Now uses `urllib.unquote_plus` so `+` characters must be escaped.
    """
    if '@' in userinfo or userinfo.count(':') > 1:
        if PY3:
            quote_fn = "urllib.parse.quote_plus"
        else:
            quote_fn = "urllib.quote_plus"
      raise InvalidURI("Username and password must be escaped according to "
                         "RFC 3986, use %s()." % quote_fn)

E pymongo.errors.InvalidURI: Username and password must be escaped according to RFC 3986, use urllib.parse.quote_plus().

…\anaconda3\lib\site-packages\pymongo\uri_parser.py:96: InvalidURI
______________________________ 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)
…\anaconda3\lib\site-packages\werkzeug\local.py:348: in getattr
return getattr(self._get_current_object(), name)
…\anaconda3\lib\site-packages\werkzeug\local.py:307: in _get_current_object
return self.__local()
mflix\db.py:46: in get_db
db = g._database = MongoClient(
…\anaconda3\lib\site-packages\pymongo\mongo_client.py:494: in init
res = uri_parser.parse_uri(entity, port, warn=True)
…\anaconda3\lib\site-packages\pymongo\uri_parser.py:379: in parse_uri
user, passwd = parse_userinfo(userinfo)


userinfo = ‘m220student:m220password@’

def parse_userinfo(userinfo):
    """Validates the format of user information in a MongoDB URI.
    Reserved characters like ':', '/', '+' and '@' must be escaped
    following RFC 3986.

    Returns a 2-tuple containing the unescaped username followed
    by the unescaped password.

    :Paramaters:
        - `userinfo`: A string of the form <username>:<password>

    .. versionchanged:: 2.2
       Now uses `urllib.unquote_plus` so `+` characters must be escaped.
    """
    if '@' in userinfo or userinfo.count(':') > 1:
        if PY3:
            quote_fn = "urllib.parse.quote_plus"
        else:
            quote_fn = "urllib.quote_plus"
      raise InvalidURI("Username and password must be escaped according to "
                         "RFC 3986, use %s()." % quote_fn)

E pymongo.errors.InvalidURI: Username and password must be escaped according to RFC 3986, use urllib.parse.quote_plus().

…\anaconda3\lib\site-packages\pymongo\uri_parser.py:96: InvalidURI
___________________________ 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)
…\anaconda3\lib\site-packages\werkzeug\local.py:348: in getattr
return getattr(self._get_current_object(), name)
…\anaconda3\lib\site-packages\werkzeug\local.py:307: in _get_current_object
return self.__local()
mflix\db.py:46: in get_db
db = g._database = MongoClient(
…\anaconda3\lib\site-packages\pymongo\mongo_client.py:494: in init
res = uri_parser.parse_uri(entity, port, warn=True)
…\anaconda3\lib\site-packages\pymongo\uri_parser.py:379: in parse_uri
user, passwd = parse_userinfo(userinfo)


userinfo = ‘m220student:m220password@’

def parse_userinfo(userinfo):
    """Validates the format of user information in a MongoDB URI.
    Reserved characters like ':', '/', '+' and '@' must be escaped
    following RFC 3986.

    Returns a 2-tuple containing the unescaped username followed
    by the unescaped password.

    :Paramaters:
        - `userinfo`: A string of the form <username>:<password>

    .. versionchanged:: 2.2
       Now uses `urllib.unquote_plus` so `+` characters must be escaped.
    """
    if '@' in userinfo or userinfo.count(':') > 1:
        if PY3:
            quote_fn = "urllib.parse.quote_plus"
        else:
            quote_fn = "urllib.quote_plus"
      raise InvalidURI("Username and password must be escaped according to "
                         "RFC 3986, use %s()." % quote_fn)

E pymongo.errors.InvalidURI: Username and password must be escaped according to RFC 3986, use urllib.parse.quote_plus().

…\anaconda3\lib\site-packages\pymongo\uri_parser.py:96: InvalidURI
============================= 39 tests deselected =============================
=================== 4 failed, 39 deselected in 0.29 seconds ===================

my .ini file >
[PROD]
SECRET_KEY = super_secret_key_you_should_change
MFLIX_DB_URI = mongodb+srv://m220student:m220password@@mflix.lwyvt.mongodb.net/test
MFLIX_NS = sample_mflix

[TEST]
SECRET_KEY = super_secret_testing_key
MFLIX_DB_URI = mongodb+srv://m220student:m220password@@mflix.lwyvt.mongodb.net/test
MFLIX_NS = sample_mflix

Welcome to the community!

Please check URI in your .ini file

You have used @ twice in the string

1 Like

yeap I fount it and corrected it thanks the validation code is working.
Gresat thanks again!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.