Ticket: Handling Errors

When a bad movie is passed I am able to print that I am in the exception book.
However test is not passing.

127.0.0.1 - - [30/Oct/2018 14:46:18] “OPTIONS /api/v1/user/make-admin HTTP/1.1” 200 -
get_movie
573a1390f29313caabcd4132
127.0.0.1 - - [30/Oct/2018 14:46:18] “GET /api/v1/movies/id/573a1390f29313caabcd4132 HTTP/1.1” 200 -
127.0.0.1 - - [30/Oct/2018 14:46:18] “GET /api/v1/movies/config-options HTTP/1.1” 200 -
127.0.0.1 - - [30/Oct/2018 14:46:18] “GET /api/v1/movies/config-options HTTP/1.1” 200 -
get_movie
foobar
except

1 Like

I’m seeing the same error. pytest test passes. but status page does not.

4 Likes

Same thing here. Test passes Ok but not the validation from the status page.

1 Like

First, I stress I am using the old edition of code set. Therefore, I do not know which parts of codes the teams updated in new version.

After my first failure, I check the movies.py that imports get_movie() for integration test. The corresponding function is,

def api_get_movie_by_id(id):
    movie = get_movie(id)
    if movie is None or movie == {}:
        return jsonify({
        "status": "fail",
        }), 400
    else:
        updated_type = str(type(movie.get('lastupdated')))
        return jsonify(
            {
                "status": "success",
                "movie": movie,
                "updated_type": updated_type
            }
        ), 200

It looks OK. If the result is None, the function returns HTTP 400 and {"status": "fail"}. However, when I check validation js code, (Don’t call me cheater, reading code is one of my hobbies.) :face_with_raised_eyebrow:There is code

case 3:
   if (r = e.sent, !(o = Object(f.a)(r.status, "success"))) {e.next = 9; break }

If the code jumps to case 9, it will throw error message. So I modified api_get_movie_by_id(id) and set the return status for first condition as success. Now all tests passed.

Giving such verbose explanation is because I don’t know if it is a right way to do it. Or new version code has different functions. I am not a js expert. Maybe there are other integration tests that also check against this ticket. Anyway, to the end, teams will give us the result.

New edit: I downloaded new version code, the issue has been fixed. So if anyone has the same problem, download new handout.

Q Yang

3 Likes

I suspected the same but refrained from changing the code. I have to now as I am left with no other options. :slight_smile:

i was also getting the same issue, here is the updated code

\mflix\api\movies.py

def api_get_movie_by_id(id):
movie = get_movie(id)
if movie is None or movie == {}:
return jsonify({
“status”: “success”
}), 200
else:
updated_type = str(type(movie.get(‘lastupdated’)))
return jsonify(
{
“status”: “success”,
“movie”: movie,
“updated_type”: updated_type
}
), 200

2 Likes

Yep. Everything works now after downloading the updated version of the code.

Exactly,
I’m seeing the same error. pytest test passes. but status page does not.

I have the same problem, pytest works but the status screen shows Red. so I downloaded the new mflix-python.zip and did the diff of the contents of mflix-python directory. I see some changes in the mflix\api directory for utils.py and movies.py

I copied both files into my working directory. Now I see all the old

So My question is when you say “updated version of the code”, does it mean only movies.py or just all files in the api directory or every thing except _ini and db.py , test scipted renamed etc.?

I appreciate if you can elobarate. Thank you

When I downloaded the updated version of mflix, I only used that verison. I only copied the db.py file from the old version to the new version and changed the information in the .ini file to connect the updated mflix server to my database.

Throw away the old version of mflix and use the new one updated version and only copy and paste the db.py from the old to the new file so you don’t lose any of your work.

Thank you. I copied all the new files and overwrote some files. Now it works.

If anyone else is lazy like me to download the whole zip, just changing line 94 in api/movies.py : change 400 to 200 worked for me.

1 Like

Thx mabbas110.
I don’t know if new version has any major differences, but I passed all tickets without any other changes except for this one (the last ticket).