M220P Ticket: User Management - update/upsert issue

I’ve been having a problem with upserts working properly, and I’m thinking there is some kind of dependence problem. For instance, the ticket code for “User Management” is green and passes me, but the pytest still does not work properly. I had a somewhat similar issue when I had accidentally jumped ahead to work on User Preferences.

I’m certain you’re going to want the dump from pytest for this and the code in question. And I’m on Mac OSX 11.3.1. Python 3.8.2. Requirements text were all installed. Using virtual environments since anaconda doesn’t like to communicate on this Mac.

{ “user_id”: email },
{ “$set”: { “jwt”: jwt } },upsert=True
(mflix_venv) (base) Random-MacBook:mflix-python random$ pytest -m user_management
================================================================== test session starts ===================================================================
platform darwin – Python 3.8.2, pytest-3.3.0, py-1.8.0, pluggy-0.6.0
rootdir: /Users/random/Downloads/mflix-python, inifile: pytest.ini
plugins: flask-0.11.0
collected 43 items

tests/test_user_management.py …F. [100%]

======================================================================== FAILURES ========================================================================
_______________________________________________________________________ test_login _______________________________________________________________________

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

def test_login(client):
    result = login_user(test_user.get('email'), test_user.get('jwt'))
    assert result == {'success': True}
    session_result = get_user_session(test_user.get('email'))
  assert session_result.get('user_id') == test_user.get('email')

E AttributeError: ‘NoneType’ object has no attribute ‘get’

tests/test_user_management.py:45: AttributeError
================================================================== 39 tests deselected ===================================================================
=================================================== 1 failed, 3 passed, 39 deselected in 1.81 seconds ====================================================
(mflix_venv) (base) Random-MacBook:mflix-python random$

Apparently, I had “email” set to the field instead of “user_id” in two spots of session, and that was causing things to foobar a bit. I thought the ticket codes would have been smart enough to catch certain errors, but I guess it’s only looking for some minimal correctness, and not total correctness. Weird.

Also, something NOT noted in the classroom notes that should be is that you CAN throw a pdb flag into pytest command. So for instance:

pytest --pdb -m user_management

which will drop into pdb on issues, and you can print ( p(variable) ) and things like that - easy to forget about, until you need it.

Hi @Alexander_Boese

That’s a great tip about the debugger with the pdb flag, we’ll have to include that in the notes when we update the course next.

Kindest regards,

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