Test_update_comment not working

Hey guys,

I am completely lost here. Not sure what exactly is going wrong, but here is the test:

@pytest.mark.create_update_comments
def test_update_comment(client):
result = update_comment(comment['id'], user.email, 'foo foo foo', now)
assert result.acknowledged is True

comments = get_movie(movie_id).get('comments')
# print(comments)
assert result.raw_result.get('nModified') == 1
assert comments[0].get('text') == 'foo foo foo'

And here is the code:

def update_comment(comment_id, user_email, text, date):
    """
    Updates the comment in the comment collection. Queries for the comment
    based by both comment _id field as well as the email field to doubly ensure
    the user has permission to edit this comment.
    """
    # TODO: Create/Update Comments
    # Use the user_email and comment_id to select the proper comment, then
    # update the "text" and "date" of the selected comment.
    response = db.comments.update_one({"_id": ObjectId(comment_id), "user_email": user_email}, {"$set": {"text": text, "date": date}})

    return response

Here is the error that I can’t seem to get past:

================================ FAILURES =================================
___________________________ test_update_comment ___________________________

client = <FlaskClient <Flask 'mflix.factory'>>

    @pytest.mark.create_update_comments
    def test_update_comment(client):
        result = update_comment(comment['id'], user.email, 'foo foo foo', now)
        print(result.acknowledged)
        assert result.acknowledged is True
    
        comments = get_movie(movie_id).get('comments')
>       assert result.raw_result.get('nModified') == 1
E       assert 0 == 1
E        +  where 0 = <built-in method get of dict object at 0x7f2d50057630>('nModified')
E        +    where <built-in method get of dict object at 0x7f2d50057630> = {'$clusterTime': {'clusterTime': Timestamp(1548094275, 3), 'signature': {'hash': b'\xc2Q\x0e\xfa;\xa2\x81$"\xe9\x9f\x0...\xf2', 'keyId': 6645162744557338625}}, 'electionId': ObjectId('7fffffff0000000000000001'), 'n': 0, 'nModified': 0, ...}.get
E        +      where {'$clusterTime': {'clusterTime': Timestamp(1548094275, 3), 'signature': {'hash': b'\xc2Q\x0e\xfa;\xa2\x81$"\xe9\x9f\x0...\xf2', 'keyId': 6645162744557338625}}, 'electionId': ObjectId('7fffffff0000000000000001'), 'n': 0, 'nModified': 0, ...} = <pymongo.results.UpdateResult object at 0x7f2d508e3cc8>.raw_result

tests/test_create_update_comments.py:53: AssertionError

Any help would be greatly appreciated. All the other tests have passed except this one, including the delete_comments function. Feel like it’s something minor that i’m missing…

field “user_email” is “email” in comment collection.

2 Likes

I am stuck with an error at the time of running the integration tests. The message reads: “Create/Update Comments: Was able to update a comment that wasn’t owned”. Anyone else having this issue too?

1 Like

that was it. Thanks!

Me too. It passed the tests, but cannot get the code in the status page…

Me too. I have tried everything and it is not working.
really need help here!

I am also getting same error

Same here. The pytest -m create_update_comments work but the tests from the web page show this error.

Please refer to:

I pass the test but I receive the message:
Was able to update a comment that wasn't owned
And do not show the code.

There is an logical error. JS (onto /status page) wants to get error when it try to update someone else’s comment but flask always (in this case) returns 200 http-code.