Not able to run pytest -m connection and not able to get validation code

_____________________________ test_atlas_setup _______________________________

client = <FlaskClient <Flask ‘mflix.factory’>>
config = <Config {‘DEBUG’: False, ‘TESTING’: False, ‘PROPAGATE_EXCEPTIONS’: True, ‘PRESERVE_CONTEXT_ON_EXCEPTION’: None, ‘SECRE…IX_NS’: ‘sample_mflix’, ‘MFLIX_DB_URI’: ‘your_testing_db_uri (can be the same as Atlas, or a local MongoDB database)’}>

@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:18: in get_coll_names
return db.list_collection_names()
c:\programdata\anaconda3\lib\site-packages\pymongo\database.py:690: in list_collection_names
nameOnly=True)]
c:\programdata\anaconda3\lib\site-packages\pymongo\database.py:674: in list_collections
read_pref) as (sock_info, slave_okay):
c:\programdata\anaconda3\lib\contextlib.py:112: in enter
return next(self.gen)
c:\programdata\anaconda3\lib\site-packages\pymongo\mongo_client.py:1099: in _socket_for_reads
server = topology.select_server(read_preference)
c:\programdata\anaconda3\lib\site-packages\pymongo\topology.py:224: in select_server
address))
c:\programdata\anaconda3\lib\site-packages\pymongo\topology.py:183: in select_servers
selector, server_timeout, address)


self = <pymongo.topology.Topology object at 0x000002008004C188>
selector = Primary(), timeout = 30, address = None

def _select_servers_loop(self, selector, timeout, address):
    """select_servers() guts. Hold the lock when calling this."""
    now = _time()
    end_time = now + timeout
    server_descriptions = self._description.apply_selector(
        selector, address)

    while not server_descriptions:
        # No suitable servers.
        if timeout == 0 or now > end_time:
            raise ServerSelectionTimeoutError(
              self._error_message(selector))

E pymongo.errors.ServerSelectionTimeoutError: your_testing_db_uri (can be the same as atlas:27017: [Errno 11001] getaddrinfo failed, or a local mongodb database):27017: [Errno 11001] getaddrinfo failed

c:\programdata\anaconda3\lib\site-packages\pymongo\topology.py:199: ServerSelectionTimeoutError
______________________________ 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:224: in get_movies
total_num_movies = db.movies.count_documents(query)
c:\programdata\anaconda3\lib\site-packages\pymongo\collection.py:1683: in count_documents
with self._socket_for_reads(session) as (sock_info, slave_ok):
c:\programdata\anaconda3\lib\contextlib.py:112: in enter
return next(self.gen)
c:\programdata\anaconda3\lib\site-packages\pymongo\mongo_client.py:1099: in _socket_for_reads
server = topology.select_server(read_preference)
c:\programdata\anaconda3\lib\site-packages\pymongo\topology.py:224: in select_server
address))
c:\programdata\anaconda3\lib\site-packages\pymongo\topology.py:183: in select_servers
selector, server_timeout, address)


self = <pymongo.topology.Topology object at 0x0000020080040E08>
selector = Primary(), timeout = 30, address = None

def _select_servers_loop(self, selector, timeout, address):
    """select_servers() guts. Hold the lock when calling this."""
    now = _time()
    end_time = now + timeout
    server_descriptions = self._description.apply_selector(
        selector, address)

    while not server_descriptions:
        # No suitable servers.
        if timeout == 0 or now > end_time:
            raise ServerSelectionTimeoutError(
              self._error_message(selector))

E pymongo.errors.ServerSelectionTimeoutError: your_testing_db_uri (can be the same as atlas:27017: [Errno 11001] getaddrinfo failed, or a local mongodb database):27017: [Errno 11001] getaddrinfo failed

c:\programdata\anaconda3\lib\site-packages\pymongo\topology.py:199: ServerSelectionTimeoutError
___________________________ 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:224: in get_movies
total_num_movies = db.movies.count_documents(query)
c:\programdata\anaconda3\lib\site-packages\pymongo\collection.py:1683: in count_documents
with self._socket_for_reads(session) as (sock_info, slave_ok):
c:\programdata\anaconda3\lib\contextlib.py:112: in enter
return next(self.gen)
c:\programdata\anaconda3\lib\site-packages\pymongo\mongo_client.py:1099: in _socket_for_reads
server = topology.select_server(read_preference)
c:\programdata\anaconda3\lib\site-packages\pymongo\topology.py:224: in select_server
address))
c:\programdata\anaconda3\lib\site-packages\pymongo\topology.py:183: in select_servers
selector, server_timeout, address)


self = <pymongo.topology.Topology object at 0x00000200FFFFC748>
selector = Primary(), timeout = 30, address = None

def _select_servers_loop(self, selector, timeout, address):
    """select_servers() guts. Hold the lock when calling this."""
    now = _time()
    end_time = now + timeout
    server_descriptions = self._description.apply_selector(
        selector, address)

    while not server_descriptions:
        # No suitable servers.
        if timeout == 0 or now > end_time:
            raise ServerSelectionTimeoutError(
              self._error_message(selector))

E pymongo.errors.ServerSelectionTimeoutError: your_testing_db_uri (can be the same as atlas:27017: [Errno 11001] getaddrinfo failed, or a local mongodb database):27017: [Errno 11001] getaddrinfo failed

c:\programdata\anaconda3\lib\site-packages\pymongo\topology.py:199: ServerSelectionTimeoutError
============================= 39 tests deselected =============================
================== 4 failed, 39 deselected in 122.01 seconds ==================

Please update the connection uri for in .ini file.

Kanika

mongodb+srv://m220student:m220%40password@mflix-lqqdx.mongodb.net/test?retryWrites=true&w=majority

updated this but still not able to run.

Can you tell me which option to choose from below screenshot to get Srv linkconnection

Thank you

This is correct. What is the error now?

Kanika

I have the same exact problem:
[PROD]
SECRET_KEY = test_seb
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-87dlt.mongodb.net/test?retryWrites=true&w=majority
MFLIX_NS = sample_mflix

What should I change?
I updated the pytest to have the last version.

Thank you in advance

Hi @Sebastien_55867,

Here is contents of my .ini file:

# 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 = super_secret_key_you_should_change
MFLIX_DB_URI = mongodb+srv://m220student:m220password@mflix-xxxx.mongodb.net
MFLIX_NS = sample_mflix

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

You need to have [TEST] key as well.

Kanika

now when i am running python run.py i am getting the following output.

pymongo.errors.ServerSelectionTimeoutError: connection closed,mflix-shard-00-00-lqqdx.mongodb.net:27017: timed out,connection closed
127.0.0.1 - - [20/Nov/2019 10:15:32] “GET /manifest.json HTTP/1.1” 200 -

when i am running pytest -m LAB_UNIT_TEST_NAME

its giving the following output
C:\Users\aaaggarw\Downloads\mflix-python>notepad .ini

C:\Users\aaaggarw\Downloads\mflix-python>pytest -m LAB_UNIT_test_db_connection
============================= test session starts =============================
platform win32 – Python 3.7.4, pytest-3.3.0, py-1.8.0, pluggy-0.6.0
rootdir: C:\Users\aaaggarw\Downloads\mflix-python, inifile:
plugins: remotedata-0.3.2, openfiles-0.4.0, flask-0.10.0, doctestplus-0.4.0, arraydiff-0.3
collected 43 items

============================= 43 tests deselected =============================
======================== 43 deselected in 0.24 seconds ========================

Hi @Aashish_Aggarwal_08706,

You need to run pytest -m connection command to test connection ticket.

Kanika

still the same output and not able to fetch the validation code.

when running the validation code for projection test getting the following output.

Projection: The return from the api was incorrect when searching by country

Are unit test case passing? If yes, please check console messages when running integration test. Its hard for me to understand without looking at the error message or code.

Kanika