Ticket: Projection

Hi Everyone,

My pytest -m projection is running successfully as shown below. But when validate on the mflix page I am getting error -

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

Any thoughts on this .

(mflix_venv) (base) Sameers-MacBook-Air:mflix-python sameerlenka$ pytest -m projection

===== test session starts =======

platform darwin – Python 3.8.2, pytest-3.3.0, py-1.8.0, pluggy-0.6.0
rootdir: /Users/sameerlenka/Downloads/mflix-python, inifile: pytest.ini
plugins: flask-0.11.0
collected 43 items

tests/test_projection.py …

==================== 41 tests deselected ===========
========== 2 passed, 41 deselected in 3.20 seconds ===

My changes -
db.py ----

    x = db.movies.find({'countries':{'$in': countries}},{'title':1,'_id':0})
    return list(x)

Console -

127.0.0.1 - - [06/May/2020 11:58:29] “GET /status HTTP/1.1” 200 -

127.0.0.1 - - [06/May/2020 11:58:29] “GET /static/css/main.2637239d.chunk.css HTTP/1.1” 304 -

127.0.0.1 - - [06/May/2020 11:58:29] “GET /static/js/2.dc8c00c7.chunk.js HTTP/1.1” 304 -

127.0.0.1 - - [06/May/2020 11:58:29] “GET /static/js/main.20133101.chunk.js HTTP/1.1” 304 -

127.0.0.1 - - [06/May/2020 11:58:29] “GET /static/media/mongoleaf.0ebc1843.png HTTP/1.1” 304 -

127.0.0.1 - - [06/May/2020 11:58:29] “GET /static/media/pixelatedLeaf.6c93bd20.svg HTTP/1.1” 304 -

127.0.0.1 - - [06/May/2020 11:58:29] “GET /manifest.json HTTP/1.1” 200 -

127.0.0.1 - - [06/May/2020 11:58:29] “GET /favicon.ico HTTP/1.1” 200 -

127.0.0.1 - - [06/May/2020 11:58:38] “GET /api/v1/movies/countries?countries=Australia HTTP/1.1” 200 -

Anyone ,

Please have look, my none of the tickets are working. All are failing in validations even though testing is passed.

Thanks

Hi @sameer_lenka,

The code looks okay to me, have you restarted the application and then go to localhost:5000 -> Status.

You might have done the same, just cross-checking it.

Kanika

Yes I have restarted it several times but each time the same error.

Thanks

This certainly looks to be a setup/configuration issue . I have tried every thing I could
to fix this. No luck.

pip3 list ----

^C(mflix) Sameers-MacBook-Air:mflix-python sameerlenka$ pip3 list
Package Version


appdirs 1.4.3
appnope 0.1.0
attrs 19.1.0
backcall 0.1.0
bcrypt 3.1.7
bleach 3.1.0
certifi 2020.4.5.1
cffi 1.13.1
Click 7.0
decorator 4.4.0
defusedxml 0.6.0
distlib 0.3.0
dnspython 1.15.0
entrypoints 0.3
Faker 0.8.13
filelock 3.0.12
flake8 3.7.8
Flask 0.12.4
Flask-Bcrypt 0.7.1
Flask-Cors 3.0.3
Flask-JWT-Extended 3.7.0
Flask-Login 0.4.0
importlib-metadata 0.23
ipykernel 5.1.3
ipython 7.8.0
ipython-genutils 0.2.0
ipywidgets 7.5.1
itsdangerous 1.1.0
jedi 0.15.1
Jinja2 2.10.3
jsonschema 3.1.1
jupyter 1.0.0
jupyter-client 5.3.1
jupyter-console 6.0.0
jupyter-core 4.4.0
MarkupSafe 1.1.1
mccabe 0.6.1
mistune 0.8.4
more-itertools 7.2.0
nbconvert 5.6.0
nbformat 4.4.0
notebook 6.0.1
pandocfilters 1.4.2
parso 0.5.1
pexpect 4.7.0
pickleshare 0.7.5
pip 20.1
pluggy 0.6.0
prometheus-client 0.7.1
prompt-toolkit 2.0.10
ptyprocess 0.6.0
py 1.8.0
pycodestyle 2.5.0
pycparser 2.19
pyflakes 2.1.1
Pygments 2.4.2
PyJWT 1.7.1
pymongo 3.7.2
pyrsistent 0.15.4
pytest 3.3.0
pytest-flask 0.11.0
python-dateutil 2.8.0
pyzmq 18.1.0
qtconsole 4.5.5
Send2Trash 1.5.0
setuptools 41.2.0
six 1.12.0
terminado 0.8.2
testpath 0.4.2
text-unidecode 1.2
tornado 6.0.3
traitlets 4.3.3
virtualenv 20.0.20
wcwidth 0.1.7
webencodings 0.5.1
Werkzeug 0.16.0
widgetsnbextension 3.5.1
zipp 0.6.0

Even in the console I am seeing a success response -
127.0.0.1 - - [06/May/2020 15:23:13] “GET /api/v1/movies/countries?countries=Australia HTTP/1.1” 200 -

Still the validation is failing. I think jsonify(response_object) sending the proper format.

The task description needs to be more specific -

Task

Implement the get_movies_by_country method in db.py to search movies by country and use projection to return the title field.
in project i was setting {‘title’:1,’_id’:0} wheres the app is also expection _id so I modified the projection to {‘title’:1}. and it worked.

Please have the task description specific to the requirement else it really wastes lot of time.

Thanks @sameer_lenka for the feedback, we will update the ticket :slight_smile:

Kanika

Just one thing, I tried using the same code and unit test failed for me with the following error:

I am a little confused how unit test passed for you. But I will still update the ticket to avoid any issue.

Kanika

Testing the projection. It looks like I get the right result regarding the countries but the length of the array is wrong. Any suggestions?

The error message TypeError: object of … has no len() means that the function does not return an array. Most likely because your code execute bad code. If you look at the test cases you will see that countries is already an array. Also, the way your find() is constructed, the fields title and _id are part of the query part rather than part of a projection.

That didn’t help me at all.