Context helper improved, avoid 500 instead of 404

* context.has_ctx() helper has been added
* has context check added to teardown to avoid 500 instead of 404

Fixes bug: #1198099

Change-Id: I198e73637fe4b973d2d99873d66cf5ddd49a43e3
Merge "Context helper improved, avoid 500 instead of 404"