Add Comments not working

Running the test I am getting the error " IndexError: list index out of range" for the first test method. I am not sure if this could be connected how to retrieve the user.email and user.name, if a special syntax(e.g. quotes) is required. I would appreciate any help to get it working. Tilo

Hi @Tilo1,

I think the problem you comment is located in the line 41 (“comments[0]”). In this case, the “comments” variable in line 40 has not items, i.e., the get_movie query does not return comments.

Execute some query in your database to find comments associated with movie_id = 573a13eff29313caabdd82f3, for example.

Regards

Hi, I’ve the same problem, found that the movie_id indeed has comments, but don’t know why the test fails, this is my method:

def add_comment(movie_id, user, comment, date):
“”"
Inserts a comment into the comments collection, with the following fields:

- "name"
- "email"
- "movie_id"
- "text"
- "date"

Name and email must be retrieved from the "user" object.
"""
# TODO: Create/Update Comments
# Construct the comment document to be inserted into MongoDB.
comment_doc = {"name": user.name, "email": user.email, "movie_id": movie_id, "text": comment, "date": date}
return db.comments.insert_one(comment_doc)

Check the movie_id field and reference what was provided in the pipeline code snippet in our previous assignment/ticket. The ids that are passed have to be compared as object ids.

2 Likes

Indeed! Many thanks!

1 Like

Hi,
Any guess why all unit tests passed but validation code cannot be generated ?
thanks

No clue. Until I fixed the id issue, the code didn’t appeared