Chapter 2: Ticket: User Preferences throws AttributeError: 'NoneType' object has no attribute 'get'

def update_prefs(email, prefs):

"""
Given a user's email and a dictionary of preferences, update that user's
preferences.
"""
prefs = {} if prefs is None else prefs
try:
    """
    Ticket: User Preferences
    Update the "preferences" field in the corresponding user's document to
    reflect the information in prefs.
    """
    # TODO: User preferences
    # Use the data in "prefs" to update the user's preferences.
    response = db.users.update_one(
        { "email": email },
        { "$set": { "preferences": prefs } }
    )
    if response.matched_count == 0:
        return {'error': 'no user found'}
    else:
        return response
except Exception as e:
    return {'error': str(e)}

=============== ERROR OBTAINED==================
________________________ test_empty_prefs_are_valid __________________________

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

@pytest.mark.user_preferences
def test_empty_prefs_are_valid(client):
    new_prefs = {}
    result = update_prefs("foobaz@bar.com", new_prefs)

    assert result.matched_count == 1
    assert result.modified_count == 1

    user = get_user("foobaz@bar.com")
  assert user.get("preferences") == {}

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

tests\test_user_preferences.py:71: AttributeError
============================= 39 tests deselected =============================
================== 4 failed, 39 deselected in 26.70 seconds ===================