Updated test_projection, error in test case (SOLVED)

Following is my corrected code

@pytest.mark.projection
def test_basic_country_search_shape_db(client):
    countries = ['Russia', 'Japan']
    result = get_movies_by_country(countries)
    #in actual code it asserts to 2 which is wrong since the countries Russia and japan retruns 
    #2420 movies
    assert len(result) == 2420
    # we should only be returning the _id and title fields
    encountered_keys = {}
    for movie in result:
        for k in movie:
            encountered_keys[k] = encountered_keys.get(k, 0) + 1
   
    #In actual code it asserts to 2420 but as per instruction we are returing only two keys that 
    #are _id and title
    assert len(list(encountered_keys.keys())) == 2
    assert encountered_keys['_id'] == 2420
    assert encountered_keys['title'] == 2420

Hope this helps friends

================================== FAILURES ===================================
________________________ test_basic_country_search_db _________________________

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

@pytest.mark.projection
def test_basic_country_search_db(client):
    countries = ['Kosovo']
    result = get_movies_by_country(countries)
  assert len(result) == 2

E AssertionError: assert 1 == 2
E + where 1 = len([{’_id’: ObjectId(‘573a1390f29313caabcd4132’), ‘cast’: [‘Carmencita’], ‘countries’: [‘USA’], ‘directors’: [‘William K.L. Dickson’], …}])

tests\test_projection.py:15: AssertionError
_____________________ test_basic_country_search_shape_db ______________________

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

@pytest.mark.projection
def test_basic_country_search_shape_db(client):
    countries = ['Russia', 'Japan']
    result = get_movies_by_country(countries)
  assert len(result) == 2420

E AssertionError: assert 1 == 2420
E + where 1 = len([{’_id’: ObjectId(‘573a1390f29313caabcd4132’), ‘cast’: [‘Carmencita’], ‘countries’: [‘USA’], ‘directors’: [‘William K.L. Dickson’], …}])

tests\test_projection.py:22: AssertionError
============================= 41 tests deselected =============================
=================== 2 failed, 41 deselected in 3.59 seconds ===================

while trying your code i got this errors.

Hi @Abhinav_05270,

Please make sure you have all the data in your dataset. The totalCount for movies collection should be 46014.

If not. please restore the data again.

Kanika

Can u please tell me in which file i have to right the code? Your_first_read.ipnyb??? @Kanika

You don’t need to write any code. You need to run the mongorestore command again.

# navigate to mflix-python directory
cd mflix-python

# import data into Atlas
mongorestore --drop --gzip --uri mongodb+srv://m220student:m220password@<YOUR_CLUSTER_URI> data

Kanika

A:\mflix-python>mongorestore --drop --gzip --uri mongodb+srv://m220student:@mflix-iykvz.mongodb.net/test?retryWrites=true&w=majority data
The system cannot find the file specified.
‘w’ is not recognized as an internal or external command,
operable program or batch file.
now getting this error @Kanika

Please try after removing the parameters.

 A:\mflix-python> mongorestore --drop --gzip --uri mongodb+srv://m220student:@mflix-iykvz.mongodb.net data

Kanika

A:\mflix-python> mongorestore --drop --gzip --uri mongodb+srv://m220student:@mflix-iykvz.mongodb.net data
Enter password:
not able to enter the password in the terminal
@Kanika

Hello

i have the same problem
but i have 45993 movie collections and not as you wrote.

The password prompt won’t show the characters you are typing because of security reasons.
You can also pass the password parameter in the connection string itself like this: You need to replace the password

A:\mflix-python> mongorestore --drop --gzip --uri mongodb+srv://m220student:<PASSWORD>@mflix-iykvz.mongodb.net data

Kanika

Please share the screenshot from your error console to help us better understand the issue.

Kanika

Hi I am also getting similar error while executing the “paging” test

pytest -m paging

I even restored again . That didn’t help

Hi @Phanideep_Karnati_28976,

The output shows that the function needs some rework as it is returning all the movies and not considering filter at all.

Please check the code and also you can look at the database for the results.

Kanika

I have a the same error
try to mongorestore as you said but i get this issue
error parsing command line options: error parsing uri (mongodb+srv://m220student:220password@mflix-5cyu7.mongodb.net): lookup mflix-5cyu7.mongodb.net on 127.0.0.53:53: cannot unmarshal DNS message

so i cant continue and get the ticket because i have less amount of data as the test

Hi @Berta_97742,

I am able to connect to the cluster you mentioned. But not using the same username and password, so either:

  • It is a typo in password field, it is written 220password.
  • Make sure firewall is disabled and your system allows for incoming connections.

Kanika