For ticket “Create/Update Comments” the unit test and the run.py application pass different data types to update_comment. For parameter comment_id the unit test passes an object ID but the run.py application passes a hex string. Therefore the unit test and the application can never both pass. Below is the dbg output for both cases verifying this course software bug.
- Using the Unit Test
(mflix) C:\test\mongodb\m220p>pytest -m create_update_comments
============================= test session starts =============================
platform win32 – Python 3.6.10, pytest-3.3.0, py-1.8.0, pluggy-0.6.0
rootdir: C:\test\mongodb\m220p, inifile: pytest.ini
plugins: flask-0.11.0
collected 43 items
tests\test_create_update_comments.py .
PDB set_trace (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>
c:\test\mongodb\m220p\mflix\db.py(377)update_comment()
-> response = db.comments.update_one(
(Pdb) l
372 “”"
373 # TODO: Create/Update Comments
374 # Use the user_email and comment_id to select the proper comment, then
375 # update the “text” and “date” of the selected comment.
376 import pdb; pdb.set_trace()
377 -> response = db.comments.update_one(
378 { “_id”: comment_id, “email”: user_email },
379 { “$set”: { “text”: text, “date”: date } }
380 )
381
382 return response
(Pdb) p comment_id
ObjectId(‘5f3a20de7526b648a4d9e7ce’)
…
(Pdb) c
… [100%]
============================= 39 tests deselected =============================
================== 4 passed, 39 deselected in 146.88 seconds ==================
- Running the main application
(mflix) C:\test\mongodb\m220p>python run.py
- Restarting with stat
- Debugger is active!
- Debugger PIN: 166-656-048
- Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [17/Aug/2020 02:20:48] “GET / HTTP/1.1” 200 -
127.0.0.1 - - [17/Aug/2020 02:20:48] “GET /static/css/main.2637239d.chunk.css HTTP/1.1” 200 -
127.0.0.1 - - [17/Aug/2020 02:20:48] “GET /static/js/main.de4ec786.chunk.js HTTP/1.1” 200 -
127.0.0.1 - - [17/Aug/2020 02:20:50] “GET /api/v1/movies/ HTTP/1.1” 200 -
127.0.0.1 - - [17/Aug/2020 02:20:51] “GET /api/v1/movies/facet-search?cast=Denzel%20Washington&page=0 HTTP/1.1” 200 -
127.0.0.1 - - [17/Aug/2020 02:20:51] “GET /api/v1/movies/facet-search?cast=Morgan%20Freeman&page=2 HTTP/1.1” 200 -
127.0.0.1 - - [17/Aug/2020 02:20:52] “GET /static/media/pixelatedLeaf.6c93bd20.svg HTTP/1.1” 200 -
127.0.0.1 - - [17/Aug/2020 02:21:01] “POST /api/v1/user/register HTTP/1.1” 201 -
127.0.0.1 - - [17/Aug/2020 02:21:02] “POST /api/v1/user/register HTTP/1.1” 201 -
127.0.0.1 - - [17/Aug/2020 02:21:02] “POST /api/v1/movies/comment HTTP/1.1” 200 -
c:\test\mongodb\m220p\mflix\db.py(377)update_comment()
-> response = db.comments.update_one(
(Pdb) l
372 “”"
373 # TODO: Create/Update Comments
374 # Use the user_email and comment_id to select the proper comment, then
375 # update the “text” and “date” of the selected comment.
376 import pdb; pdb.set_trace()
377 -> response = db.comments.update_one(
378 { “_id”: comment_id, “email”: user_email },
379 { “$set”: { “text”: text, “date”: date } }
380 )
381
382 return response
(Pdb) p comment_id
‘5f3a21ce7526b64b3c3daf9f’
(Pdb) c
127.0.0.1 - - [17/Aug/2020 02:21:29] “PUT /api/v1/movies/comment HTTP/1.1” 400 -
c:\test\mongodb\m220p\mflix\db.py(377)update_comment()
-> response = db.comments.update_one(
(Pdb) p comment_id
‘5f3a21ce7526b64b3c3daf9f’
(Pdb) c
127.0.0.1 - - [17/Aug/2020 02:21:38] “PUT /api/v1/movies/comment HTTP/1.1” 400 -