Ticket: user_management - error - SOLVED

Hi,

Could you please help me understand this error?

Error: AttributeError: ‘NoneType’ object has no attribute 'get’

Thank you!

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

@pytest.mark.user_management
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
============== 1 failed, 3 passed, 35 deselected in 8.13 seconds ==============

MY CODE:

def get_user(email):
“”"
Given an email, returns a document from the users collection.
“”"
# TODO: User Management
# Retrieve the user document corresponding with the user’s email.
return db.users.find_one({“email”: email})

def add_user(name, email, hashedpw):
“”"
Given a name, email and password, inserts a document with those credentials
to the users collection.
“”"

"""
Ticket: Durable Writes

Please increase the durability of this method by using a non-default write
concern with ``insert_one``.
"""

try:
    # TODO: User Management
    # Insert a user with the "name", "email", and "password" fields.
    # TODO: Durable Writes
    # Use a more durable Write Concern for this operation.

    db.users.insert_one({"name": name, "email": email, "password": hashedpw})
    db.users.with_options(write_concern=WriteConcern("majority"))
    return {"success": True}
except DuplicateKeyError:
    return {"error": "A user with the given email already exists."}

def login_user(email, jwt):
“”"
Given an email and JWT, logs in a user by updating the JWT corresponding
with that user’s email in the sessions collection.

In `sessions`, each user's email is stored in a field called "user_id".
"""
try:
    # TODO: User Management
    # Use an UPSERT statement to update the "jwt" field in the document,
    # matching the "user_id" field with the email passed to this function.
    db.sessions.update_one({"user_id": email}, {"$set": {"jwt": jwt}}, upsert=True)
    return {"success": True}
except Exception as e:
    return {"error": e}

def logout_user(email):
“”"
Given a user’s email, logs out that user by deleting their corresponding
entry in the sessions collection.

In `sessions`, each user's email is stored in a field called "user_id".
"""
try:
    # TODO: User Management
    # Delete the document in the `sessions` collection matching the email.
    db.sessions.delete_one({"user_id": email})
    return {"success": True}
except Exception as e:
    return {"error": e}
1 Like