)]}'
{"openstack_dashboard/api/rest/nova.py":[{"author":{"_account_id":10442,"name":"Masco Kaliyamoorthy","email":"mkaliyam@redhat.com","username":"masco"},"change_message_id":"6fbbec779580932cd5d53ec1f1201ddc3d7a2230","unresolved":false,"context_lines":[{"line_number":93,"context_line":"            keypair \u003d api.nova.keypair_create(request, keypair_name)"},{"line_number":94,"context_line":""},{"line_number":95,"context_line":"        except exceptions.Conflict as e:"},{"line_number":96,"context_line":"            return JSONResponse(e.message, e.http_status)"},{"line_number":97,"context_line":""},{"line_number":98,"context_line":"        except Exception as e:"},{"line_number":99,"context_line":"            message \u003d str(_(\"Unable to create keypair:\")) + \" \" + keypair_name"}],"source_content_type":"text/x-python","patch_set":5,"id":"1a7b0d38_ab416a3b","line":96,"range":{"start_line":96,"start_character":34,"end_line":96,"end_character":41},"updated":"2015-12-23 07:03:05.000000000","message":"we should not use the nova messages directly in horizon. since it can\u0027t translatable.","commit_id":"9e45a6db9fd4e2c4126e574e6a2302ab308c3d58"},{"author":{"_account_id":18508,"name":"Errol Pais","email":"errol.pais@protonmail.com","username":"errol"},"change_message_id":"4afa14ce3f95e9eaaffe21aed466fe6af6df2303","unresolved":false,"context_lines":[{"line_number":93,"context_line":"            keypair \u003d api.nova.keypair_create(request, keypair_name)"},{"line_number":94,"context_line":""},{"line_number":95,"context_line":"        except exceptions.Conflict as e:"},{"line_number":96,"context_line":"            return JSONResponse(e.message, e.http_status)"},{"line_number":97,"context_line":""},{"line_number":98,"context_line":"        except Exception as e:"},{"line_number":99,"context_line":"            message \u003d str(_(\"Unable to create keypair:\")) + \" \" + keypair_name"}],"source_content_type":"text/x-python","patch_set":5,"id":"1a7b0d38_59a52002","line":96,"range":{"start_line":96,"start_character":34,"end_line":96,"end_character":41},"in_reply_to":"1a7b0d38_ab416a3b","updated":"2015-12-23 19:08:56.000000000","message":"I guess the UI should also define its own messages so the messages are not useful to be returned. I changed the implementation to only return the status codes. conflict(409), server error(500) and success(200).","commit_id":"9e45a6db9fd4e2c4126e574e6a2302ab308c3d58"},{"author":{"_account_id":14124,"name":"Matt Borland","email":"matt.borland@hpe.com","username":"mborland"},"change_message_id":"038eccb458a695d4e0444f4c76b83fa403329a6a","unresolved":false,"context_lines":[{"line_number":70,"context_line":"class Keypair(generic.View):"},{"line_number":71,"context_line":"    url_regex \u003d r\u0027nova/keypairs/(?P\u003ckeypair_name\u003e.+)/(?P\u003coptional\u003e.+)/$\u0027"},{"line_number":72,"context_line":""},{"line_number":73,"context_line":"    def get(self, request, keypair_name, optional):"},{"line_number":74,"context_line":"        \"\"\"Creates a new keypair and associates it to the current project."},{"line_number":75,"context_line":""},{"line_number":76,"context_line":"        * Since the response for this endpoint creates a new keypair and"}],"source_content_type":"text/x-python","patch_set":6,"id":"fa69d971_7f886571","line":73,"updated":"2016-01-06 14:24:10.000000000","message":"It seems to me offhand that this would be presented as a POST if it\u0027s creating.  The underlying Nova call is a POST.","commit_id":"6c67f300654f4f2ad4f76358b83509b42b4d95a5"},{"author":{"_account_id":14124,"name":"Matt Borland","email":"matt.borland@hpe.com","username":"mborland"},"change_message_id":"8e7918b48112abd933292f9cc66d00f53e66035b","unresolved":false,"context_lines":[{"line_number":74,"context_line":"        \"\"\"Creates a new keypair and associates it to the current project."},{"line_number":75,"context_line":""},{"line_number":76,"context_line":"        * Since the response for this endpoint creates a new keypair and"},{"line_number":77,"context_line":"          is not idempotent, it normally would be represented by a GET HTTP"},{"line_number":78,"context_line":"          request. However, this solution was adopted as it"},{"line_number":79,"context_line":"          would support automatic file download across browsers."},{"line_number":80,"context_line":""}],"source_content_type":"text/x-python","patch_set":6,"id":"fa69d971_374a1127","line":77,"range":{"start_line":77,"start_character":32,"end_line":77,"end_character":40},"updated":"2016-01-06 15:30:23.000000000","message":"This really speaks to the problem of making the download feature make the Create call.  I really think we should handle this whole process much better on the client side using something more like the data: protocol, where we can have the user elect to download the key pair after creation.","commit_id":"6c67f300654f4f2ad4f76358b83509b42b4d95a5"},{"author":{"_account_id":7665,"name":"Travis Tripp","email":"os.travis.tripp@gmail.com","username":"travis.tripp"},"change_message_id":"f70d396b46c04f23f1583756b058e1a48c6f274f","unresolved":false,"context_lines":[{"line_number":45,"context_line":""},{"line_number":46,"context_line":"    @rest_utils.ajax(data_required\u003dTrue)"},{"line_number":47,"context_line":"    def post(self, request):"},{"line_number":48,"context_line":"        \"\"\"Create a keypair."},{"line_number":49,"context_line":""},{"line_number":50,"context_line":"        Create a keypair using the parameters supplied in the POST"},{"line_number":51,"context_line":"        application/json object. The parameters are:"}],"source_content_type":"text/x-python","patch_set":7,"id":"da6ed579_b39d0868","line":48,"updated":"2016-01-13 23:28:23.000000000","message":"Were you not able to use the accept header here and dynamically negotiate the response?  e.g. if accept is set to application/binary then return the http response like you do below in the GET function?","commit_id":"2307d64dc20c4ac1adc52f4d5a9a3388880d8d40"},{"author":{"_account_id":18508,"name":"Errol Pais","email":"errol.pais@protonmail.com","username":"errol"},"change_message_id":"0609bd9e11e4a3a2cccff60b1c16917ee7e89d5f","unresolved":false,"context_lines":[{"line_number":45,"context_line":""},{"line_number":46,"context_line":"    @rest_utils.ajax(data_required\u003dTrue)"},{"line_number":47,"context_line":"    def post(self, request):"},{"line_number":48,"context_line":"        \"\"\"Create a keypair."},{"line_number":49,"context_line":""},{"line_number":50,"context_line":"        Create a keypair using the parameters supplied in the POST"},{"line_number":51,"context_line":"        application/json object. The parameters are:"}],"source_content_type":"text/x-python","patch_set":7,"id":"da6ed579_a046c778","line":48,"in_reply_to":"da6ed579_b39d0868","updated":"2016-01-14 23:48:57.000000000","message":"We tried a few different things, but the only way we were able to activate an automatic download was through a GET request. In addition to that, we were not able to achieve an automatic download through AJAX so the GET request had to be performed directly to the server from the browser.","commit_id":"2307d64dc20c4ac1adc52f4d5a9a3388880d8d40"},{"author":{"_account_id":7665,"name":"Travis Tripp","email":"os.travis.tripp@gmail.com","username":"travis.tripp"},"change_message_id":"f70d396b46c04f23f1583756b058e1a48c6f274f","unresolved":false,"context_lines":[{"line_number":68,"context_line":""},{"line_number":69,"context_line":"@urls.register"},{"line_number":70,"context_line":"class Keypair(generic.View):"},{"line_number":71,"context_line":"    url_regex \u003d r\u0027nova/keypairs/(?P\u003ckeypair_name\u003e.+)/(?P\u003coptional\u003e.+)/$\u0027"},{"line_number":72,"context_line":""},{"line_number":73,"context_line":"    def get(self, request, keypair_name, optional):"},{"line_number":74,"context_line":"        \"\"\"Creates a new keypair and associates it to the current project."}],"source_content_type":"text/x-python","patch_set":7,"id":"da6ed579_f3438040","line":71,"updated":"2016-01-13 23:28:23.000000000","message":"The param name of optional is quite confusing and not very extensible. What if we need to add more \"optional\" parameters.\n\nWe could have arguments all day on the RESTfulness of this URL, but I really feel like the \"optional\" param in this case should be a query parameter and not part of the base URL.\n\nGiven all of the above, I think the param name should be \"regenerate\", it should be a boolean, and it should be a query param and not part of the resource path.\n\nSo, it would be more like the following:\n\nhttps://github.com/openstack/horizon/blob/master/openstack_dashboard/api/rest/keystone.py#L415\n\ne.g.:\n\nregenerate \u003d request.GET.get(\u0027regenerate\u0027) \u003d\u003d \u0027true\u0027\n\nif regenerate:\n   api.nova.keypair_delete(request, keypair_name)","commit_id":"2307d64dc20c4ac1adc52f4d5a9a3388880d8d40"},{"author":{"_account_id":18508,"name":"Errol Pais","email":"errol.pais@protonmail.com","username":"errol"},"change_message_id":"0609bd9e11e4a3a2cccff60b1c16917ee7e89d5f","unresolved":false,"context_lines":[{"line_number":68,"context_line":""},{"line_number":69,"context_line":"@urls.register"},{"line_number":70,"context_line":"class Keypair(generic.View):"},{"line_number":71,"context_line":"    url_regex \u003d r\u0027nova/keypairs/(?P\u003ckeypair_name\u003e.+)/(?P\u003coptional\u003e.+)/$\u0027"},{"line_number":72,"context_line":""},{"line_number":73,"context_line":"    def get(self, request, keypair_name, optional):"},{"line_number":74,"context_line":"        \"\"\"Creates a new keypair and associates it to the current project."}],"source_content_type":"text/x-python","patch_set":7,"id":"da6ed579_1015aae3","line":71,"in_reply_to":"da6ed579_f3438040","updated":"2016-01-14 23:48:57.000000000","message":"Agreed, this is cleaner.\nDone.","commit_id":"2307d64dc20c4ac1adc52f4d5a9a3388880d8d40"},{"author":{"_account_id":7665,"name":"Travis Tripp","email":"os.travis.tripp@gmail.com","username":"travis.tripp"},"change_message_id":"f70d396b46c04f23f1583756b058e1a48c6f274f","unresolved":false,"context_lines":[{"line_number":74,"context_line":"        \"\"\"Creates a new keypair and associates it to the current project."},{"line_number":75,"context_line":""},{"line_number":76,"context_line":"        * Since the response for this endpoint creates a new keypair and"},{"line_number":77,"context_line":"          is not idempotent, it normally would be represented by a GET HTTP"},{"line_number":78,"context_line":"          request. However, this solution was adopted as it"},{"line_number":79,"context_line":"          would support automatic file download across browsers."},{"line_number":80,"context_line":""}],"source_content_type":"text/x-python","patch_set":7,"id":"da6ed579_330da137","line":77,"updated":"2016-01-13 23:28:23.000000000","message":"Don\u0027t you mean it normally would be a POST? GET typically does none of the things mentioned here.\n\n\nGET still feels really wrong, but your argument seems right.","commit_id":"2307d64dc20c4ac1adc52f4d5a9a3388880d8d40"},{"author":{"_account_id":18508,"name":"Errol Pais","email":"errol.pais@protonmail.com","username":"errol"},"change_message_id":"0609bd9e11e4a3a2cccff60b1c16917ee7e89d5f","unresolved":false,"context_lines":[{"line_number":74,"context_line":"        \"\"\"Creates a new keypair and associates it to the current project."},{"line_number":75,"context_line":""},{"line_number":76,"context_line":"        * Since the response for this endpoint creates a new keypair and"},{"line_number":77,"context_line":"          is not idempotent, it normally would be represented by a GET HTTP"},{"line_number":78,"context_line":"          request. However, this solution was adopted as it"},{"line_number":79,"context_line":"          would support automatic file download across browsers."},{"line_number":80,"context_line":""}],"source_content_type":"text/x-python","patch_set":7,"id":"da6ed579_75089828","line":77,"in_reply_to":"da6ed579_330da137","updated":"2016-01-14 23:48:57.000000000","message":"yup, I meant POST! Updated.","commit_id":"2307d64dc20c4ac1adc52f4d5a9a3388880d8d40"},{"author":{"_account_id":7665,"name":"Travis Tripp","email":"os.travis.tripp@gmail.com","username":"travis.tripp"},"change_message_id":"64f3cf40aaff94a51dd32d060a09022cd828b6ed","unresolved":false,"context_lines":[{"line_number":79,"context_line":"          would support automatic file download across browsers."},{"line_number":80,"context_line":""},{"line_number":81,"context_line":"        :param keypair_name: the name to associate the keypair to"},{"line_number":82,"context_line":"        :param optional: if set to the string \u0027regenerate\u0027, replaces the"},{"line_number":83,"context_line":"                        existing keypair with a new keypair"},{"line_number":84,"context_line":""},{"line_number":85,"context_line":"        This returns the new keypair object on success."}],"source_content_type":"text/x-python","patch_set":8,"id":"da6ed579_febc60bc","line":82,"updated":"2016-01-15 00:51:51.000000000","message":"you forgot renaming the param in the doc here (and putting in the param description that it is optional).","commit_id":"1e2840f275c107b0f5123234b36538c7e9a016b4"},{"author":{"_account_id":18508,"name":"Errol Pais","email":"errol.pais@protonmail.com","username":"errol"},"change_message_id":"5635f50470f4c9655e811d00fecade02a89953fe","unresolved":false,"context_lines":[{"line_number":79,"context_line":"          would support automatic file download across browsers."},{"line_number":80,"context_line":""},{"line_number":81,"context_line":"        :param keypair_name: the name to associate the keypair to"},{"line_number":82,"context_line":"        :param optional: if set to the string \u0027regenerate\u0027, replaces the"},{"line_number":83,"context_line":"                        existing keypair with a new keypair"},{"line_number":84,"context_line":""},{"line_number":85,"context_line":"        This returns the new keypair object on success."}],"source_content_type":"text/x-python","patch_set":8,"id":"da6ed579_74409134","line":82,"in_reply_to":"da6ed579_febc60bc","updated":"2016-01-15 01:38:23.000000000","message":"Done","commit_id":"1e2840f275c107b0f5123234b36538c7e9a016b4"},{"author":{"_account_id":7665,"name":"Travis Tripp","email":"os.travis.tripp@gmail.com","username":"travis.tripp"},"change_message_id":"64f3cf40aaff94a51dd32d060a09022cd828b6ed","unresolved":false,"context_lines":[{"line_number":86,"context_line":"        \"\"\""},{"line_number":87,"context_line":"        try:"},{"line_number":88,"context_line":"            regenerate \u003d request.GET.get(\u0027regenerate\u0027)"},{"line_number":89,"context_line":"            if regenerate \u003d\u003d \u0027true\u0027:"},{"line_number":90,"context_line":"                api.nova.keypair_delete(request, keypair_name)"},{"line_number":91,"context_line":""},{"line_number":92,"context_line":"            keypair \u003d api.nova.keypair_create(request, keypair_name)"}],"source_content_type":"text/x-python","patch_set":8,"id":"da6ed579_fe7f80dd","line":89,"updated":"2016-01-15 00:51:51.000000000","message":"This needs the true check I mentioned in previous review (copied below). Otherwise if regenerate is set to anything it will still evaluate to true.\n\nSee: http://paste.openstack.org/show/483950/\n\n\nSo, it would be more like the following:\nhttps://github.com/openstack/horizon/blob/master/openstack_dashboard/api/rest/keystone.py#L415\n\ne.g.:\n\n\nregenerate \u003d request.GET.get(\u0027regenerate\u0027) \u003d\u003d \u0027true\u0027\nif regenerate:\n   api.nova.keypair_delete(request, keypair_name)","commit_id":"1e2840f275c107b0f5123234b36538c7e9a016b4"},{"author":{"_account_id":7665,"name":"Travis Tripp","email":"os.travis.tripp@gmail.com","username":"travis.tripp"},"change_message_id":"35c62df5737c39659e3f145ae0c75f2ddb626a28","unresolved":false,"context_lines":[{"line_number":86,"context_line":"        \"\"\""},{"line_number":87,"context_line":"        try:"},{"line_number":88,"context_line":"            regenerate \u003d request.GET.get(\u0027regenerate\u0027)"},{"line_number":89,"context_line":"            if regenerate \u003d\u003d \u0027true\u0027:"},{"line_number":90,"context_line":"                api.nova.keypair_delete(request, keypair_name)"},{"line_number":91,"context_line":""},{"line_number":92,"context_line":"            keypair \u003d api.nova.keypair_create(request, keypair_name)"}],"source_content_type":"text/x-python","patch_set":8,"id":"da6ed579_74717175","line":89,"in_reply_to":"da6ed579_d49e1db8","updated":"2016-01-15 01:43:17.000000000","message":"wow, that was brain meltdown on my part.","commit_id":"1e2840f275c107b0f5123234b36538c7e9a016b4"},{"author":{"_account_id":18508,"name":"Errol Pais","email":"errol.pais@protonmail.com","username":"errol"},"change_message_id":"5635f50470f4c9655e811d00fecade02a89953fe","unresolved":false,"context_lines":[{"line_number":86,"context_line":"        \"\"\""},{"line_number":87,"context_line":"        try:"},{"line_number":88,"context_line":"            regenerate \u003d request.GET.get(\u0027regenerate\u0027)"},{"line_number":89,"context_line":"            if regenerate \u003d\u003d \u0027true\u0027:"},{"line_number":90,"context_line":"                api.nova.keypair_delete(request, keypair_name)"},{"line_number":91,"context_line":""},{"line_number":92,"context_line":"            keypair \u003d api.nova.keypair_create(request, keypair_name)"}],"source_content_type":"text/x-python","patch_set":8,"id":"da6ed579_d49e1db8","line":89,"in_reply_to":"da6ed579_fe7f80dd","updated":"2016-01-15 01:38:23.000000000","message":"It does check for true but it does it in line 89. But I did update the code to look more like the suggestion since it may be easier to read.","commit_id":"1e2840f275c107b0f5123234b36538c7e9a016b4"},{"author":{"_account_id":9576,"name":"Thai Tran","email":"tqtran@us.ibm.com","username":"tqtran"},"change_message_id":"600dd8575811085d08fddd201bcfff8e013f6f86","unresolved":false,"context_lines":[{"line_number":85,"context_line":"        This returns the new keypair object on success."},{"line_number":86,"context_line":"        \"\"\""},{"line_number":87,"context_line":"        try:"},{"line_number":88,"context_line":"            regenerate \u003d request.GET.get(\u0027regenerate\u0027) \u003d\u003d \u0027true\u0027"},{"line_number":89,"context_line":"            if regenerate:"},{"line_number":90,"context_line":"                api.nova.keypair_delete(request, keypair_name)"},{"line_number":91,"context_line":""}],"source_content_type":"text/x-python","patch_set":12,"id":"ba63e191_760fae2e","line":88,"updated":"2016-01-19 22:18:21.000000000","message":"I remember asking about this a while back. I think Django\u0027s body parse is smart enough to extract booleans from a JSON. So regenerate can be an actually boolean instead of a string. Can you reverify this? Also, is regenerate a keyword we made up? or is it part of the nova terminology? Would \"overwrite\" or \"replace\" be better?","commit_id":"4365f027594f0c3497ee1cf4738630271a7e819c"},{"author":{"_account_id":7665,"name":"Travis Tripp","email":"os.travis.tripp@gmail.com","username":"travis.tripp"},"change_message_id":"3d8df195fb6acb17da7f5eae2388d3684785befd","unresolved":false,"context_lines":[{"line_number":85,"context_line":"        This returns the new keypair object on success."},{"line_number":86,"context_line":"        \"\"\""},{"line_number":87,"context_line":"        try:"},{"line_number":88,"context_line":"            regenerate \u003d request.GET.get(\u0027regenerate\u0027) \u003d\u003d \u0027true\u0027"},{"line_number":89,"context_line":"            if regenerate:"},{"line_number":90,"context_line":"                api.nova.keypair_delete(request, keypair_name)"},{"line_number":91,"context_line":""}],"source_content_type":"text/x-python","patch_set":12,"id":"ba63e191_7c9f8f50","line":88,"in_reply_to":"ba63e191_517dd41a","updated":"2016-01-19 23:18:50.000000000","message":"regenerate seems like a proper word here since nova is generating the key pair and in this case we are basically regenerating the key pair with this given name.","commit_id":"4365f027594f0c3497ee1cf4738630271a7e819c"},{"author":{"_account_id":18508,"name":"Errol Pais","email":"errol.pais@protonmail.com","username":"errol"},"change_message_id":"a025f03a6b54766702aa2d1074a83be06fb242ee","unresolved":false,"context_lines":[{"line_number":85,"context_line":"        This returns the new keypair object on success."},{"line_number":86,"context_line":"        \"\"\""},{"line_number":87,"context_line":"        try:"},{"line_number":88,"context_line":"            regenerate \u003d request.GET.get(\u0027regenerate\u0027) \u003d\u003d \u0027true\u0027"},{"line_number":89,"context_line":"            if regenerate:"},{"line_number":90,"context_line":"                api.nova.keypair_delete(request, keypair_name)"},{"line_number":91,"context_line":""}],"source_content_type":"text/x-python","patch_set":12,"id":"ba63e191_517dd41a","line":88,"in_reply_to":"ba63e191_760fae2e","updated":"2016-01-19 22:55:07.000000000","message":"This API will be called directly through clicking a link on the UI so we will not be able to pass it any JSON. \n\nI wouldn\u0027t say that regenerate is a word from the nova terminology. Nova only provides the delete and create as part of their API. I reused the word from the existing Django implementation. https://github.com/openstack/horizon/blob/a3254c02ad53843a3543c3e93b4afdf7585b4c90/openstack_dashboard/dashboards/project/access_and_security/keypairs/views.py#L114\n\nI prefer regenerate to overwrite/replace because I feel that it gives more detail as to what\u0027s happening server side (creation + replacement). I don\u0027t have a strong opinion though, so let me know if you still fill it needs to change.","commit_id":"4365f027594f0c3497ee1cf4738630271a7e819c"},{"author":{"_account_id":9576,"name":"Thai Tran","email":"tqtran@us.ibm.com","username":"tqtran"},"change_message_id":"600dd8575811085d08fddd201bcfff8e013f6f86","unresolved":false,"context_lines":[{"line_number":97,"context_line":"        except Exception:"},{"line_number":98,"context_line":"            return HttpResponse(status\u003d500)"},{"line_number":99,"context_line":""},{"line_number":100,"context_line":"        else:"},{"line_number":101,"context_line":"            response \u003d HttpResponse(content_type\u003d\u0027application/binary\u0027)"},{"line_number":102,"context_line":"            response[\u0027Content-Disposition\u0027] \u003d (\u0027attachment; filename\u003d%s.pem\u0027"},{"line_number":103,"context_line":"                                               % slugify(keypair_name))"}],"source_content_type":"text/x-python","patch_set":12,"id":"ba63e191_d65e9ae8","line":100,"updated":"2016-01-19 22:18:21.000000000","message":"Maybe I\u0027m not understanding something, but where is the corresponding If statement for this? is it possible to use try and else together?","commit_id":"4365f027594f0c3497ee1cf4738630271a7e819c"},{"author":{"_account_id":7665,"name":"Travis Tripp","email":"os.travis.tripp@gmail.com","username":"travis.tripp"},"change_message_id":"3d8df195fb6acb17da7f5eae2388d3684785befd","unresolved":false,"context_lines":[{"line_number":97,"context_line":"        except Exception:"},{"line_number":98,"context_line":"            return HttpResponse(status\u003d500)"},{"line_number":99,"context_line":""},{"line_number":100,"context_line":"        else:"},{"line_number":101,"context_line":"            response \u003d HttpResponse(content_type\u003d\u0027application/binary\u0027)"},{"line_number":102,"context_line":"            response[\u0027Content-Disposition\u0027] \u003d (\u0027attachment; filename\u003d%s.pem\u0027"},{"line_number":103,"context_line":"                                               % slugify(keypair_name))"}],"source_content_type":"text/x-python","patch_set":12,"id":"ba63e191_9c5a8382","line":100,"in_reply_to":"ba63e191_718578ab","updated":"2016-01-19 23:18:50.000000000","message":"Thai, FYI: https://docs.python.org/2/tutorial/errors.html (copy pasted relevant section below).\n\nErrol, I don\u0027t particularly see an issue with the else. It works as intended, but just FYI, I\u0027m not really sure about the analogy to finally. For example, the finally I know of in Java executes *regardless* of whether or not exceptions occur.\n\nFrom: link above\n\nThe try ... except statement has an optional else clause, which, when present, must follow all except clauses. It is useful for code that must be executed if the try clause does not raise an exception. For example:\n\nfor arg in sys.argv[1:]:\n    try:\n        f \u003d open(arg, \u0027r\u0027)\n    except IOError:\n        print \u0027cannot open\u0027, arg\n    else:\n        print arg, \u0027has\u0027, len(f.readlines()), \u0027lines\u0027\n        f.close()\nThe use of the else clause is better than adding additional code to the try clause because it avoids accidentally catching an exception that wasn’t raised by the code being protected by the try ... except statement.","commit_id":"4365f027594f0c3497ee1cf4738630271a7e819c"},{"author":{"_account_id":18508,"name":"Errol Pais","email":"errol.pais@protonmail.com","username":"errol"},"change_message_id":"a025f03a6b54766702aa2d1074a83be06fb242ee","unresolved":false,"context_lines":[{"line_number":97,"context_line":"        except Exception:"},{"line_number":98,"context_line":"            return HttpResponse(status\u003d500)"},{"line_number":99,"context_line":""},{"line_number":100,"context_line":"        else:"},{"line_number":101,"context_line":"            response \u003d HttpResponse(content_type\u003d\u0027application/binary\u0027)"},{"line_number":102,"context_line":"            response[\u0027Content-Disposition\u0027] \u003d (\u0027attachment; filename\u003d%s.pem\u0027"},{"line_number":103,"context_line":"                                               % slugify(keypair_name))"}],"source_content_type":"text/x-python","patch_set":12,"id":"ba63e191_718578ab","line":100,"in_reply_to":"ba63e191_d65e9ae8","updated":"2016-01-19 22:55:07.000000000","message":"It is possible to use the try and the else together, but I think this is clearer as to where the exceptions are expected to occur.\n\nThe else statement in this case acts as a \"finally\" and will be executed when the try block does not run into any exceptions.","commit_id":"4365f027594f0c3497ee1cf4738630271a7e819c"}],"openstack_dashboard/test/api_tests/nova_rest_tests.py":[{"author":{"_account_id":7665,"name":"Travis Tripp","email":"os.travis.tripp@gmail.com","username":"travis.tripp"},"change_message_id":"64f3cf40aaff94a51dd32d060a09022cd828b6ed","unresolved":false,"context_lines":[{"line_number":116,"context_line":""},{"line_number":117,"context_line":"    @mock.patch.object(nova.api, \u0027nova\u0027)"},{"line_number":118,"context_line":"    def test_keypair_recreate_and_download(self, nc):"},{"line_number":119,"context_line":"        request \u003d self.mock_rest_request(GET\u003d{\u0027regenerate\u0027: \u0027true\u0027})"},{"line_number":120,"context_line":""},{"line_number":121,"context_line":"        keypair_create_response \u003d mock.Mock()"},{"line_number":122,"context_line":"        keypair_create_response.private_key \u003d \"private key content\""}],"source_content_type":"text/x-python","patch_set":8,"id":"da6ed579_7e015037","line":119,"updated":"2016-01-15 00:51:51.000000000","message":"There isn\u0027t a test to ensure that delete is not called if regenerate is false.","commit_id":"1e2840f275c107b0f5123234b36538c7e9a016b4"},{"author":{"_account_id":7665,"name":"Travis Tripp","email":"os.travis.tripp@gmail.com","username":"travis.tripp"},"change_message_id":"c4ffa02c70b16eb25e992f4153b791d8fc090654","unresolved":false,"context_lines":[{"line_number":79,"context_line":""},{"line_number":80,"context_line":"        with mock.patch.object(settings, \u0027DEBUG\u0027, True):"},{"line_number":81,"context_line":"            response \u003d nova.Keypair().get(request, \"Ni!\")"},{"line_number":82,"context_line":""},{"line_number":83,"context_line":"        nc.keypair_create.assert_called_once_with(request, \u0027Ni!\u0027)"},{"line_number":84,"context_line":"        self.assertStatusCode(response, 200)"},{"line_number":85,"context_line":"        self.assertEqual("}],"source_content_type":"text/x-python","patch_set":9,"id":"da6ed579_a9299d39","line":82,"updated":"2016-01-15 19:36:04.000000000","message":"I see in test_keypair_recreate_and_download that you assert keypair delete is called. But I don\u0027t see any testing that keypair_delete is not called when it shouldn\u0027t.  So, what about adding nc.keypair_delete.assert_not_called here?\n\nSince most of the code is identical between this and test_keypair_recreate_and_download, you could create a common helper function to test them both with the only diff is that when regenerate is true vs false vs not specified the test on delete change (not called vs called once).","commit_id":"6df4183696479c525a4b70850884b5f020b9d37e"},{"author":{"_account_id":18508,"name":"Errol Pais","email":"errol.pais@protonmail.com","username":"errol"},"change_message_id":"7bd558a05184363b38f3dbcafc45b465831e5b22","unresolved":false,"context_lines":[{"line_number":79,"context_line":""},{"line_number":80,"context_line":"        with mock.patch.object(settings, \u0027DEBUG\u0027, True):"},{"line_number":81,"context_line":"            response \u003d nova.Keypair().get(request, \"Ni!\")"},{"line_number":82,"context_line":""},{"line_number":83,"context_line":"        nc.keypair_create.assert_called_once_with(request, \u0027Ni!\u0027)"},{"line_number":84,"context_line":"        self.assertStatusCode(response, 200)"},{"line_number":85,"context_line":"        self.assertEqual("}],"source_content_type":"text/x-python","patch_set":9,"id":"ba63e191_32818d90","line":82,"in_reply_to":"da6ed579_a9299d39","updated":"2016-01-18 20:10:18.000000000","message":"Done","commit_id":"6df4183696479c525a4b70850884b5f020b9d37e"},{"author":{"_account_id":7665,"name":"Travis Tripp","email":"os.travis.tripp@gmail.com","username":"travis.tripp"},"change_message_id":"85c3ac2ac79237b4dcc2694825240ee5a33b92ee","unresolved":false,"context_lines":[{"line_number":70,"context_line":"        nc.keypair_import.assert_called_once_with(request, \u0027Ni!\u0027, \u0027hi\u0027)"},{"line_number":71,"context_line":""},{"line_number":72,"context_line":"    @mock.patch.object(nova.api, \u0027nova\u0027)"},{"line_number":73,"context_line":"    def _test_keypair_create_and_download(self, recreate_keypair, nc):"},{"line_number":74,"context_line":"        params \u003d {}"},{"line_number":75,"context_line":""},{"line_number":76,"context_line":"        if (recreate_keypair is True):"}],"source_content_type":"text/x-python","patch_set":11,"id":"ba63e191_5f940fe1","line":73,"updated":"2016-01-19 17:41:46.000000000","message":"Good refactor, but to follow pattern in this file [0] and in other test files [1], please put the helper function below the tests that call it.\n\n [0] https://github.com/openstack/horizon/blob/master/openstack_dashboard/test/api_tests/nova_rest_tests.py#L73-L80\n [1] https://github.com/openstack/horizon/blob/master/openstack_dashboard/test/api_tests/keystone_rest_tests.py#L154","commit_id":"f99f1d9df6fac7d78482920c83a3076bd2fb56a0"},{"author":{"_account_id":18508,"name":"Errol Pais","email":"errol.pais@protonmail.com","username":"errol"},"change_message_id":"d6fb06257b1623661fca98e6f58865144d820aa2","unresolved":false,"context_lines":[{"line_number":70,"context_line":"        nc.keypair_import.assert_called_once_with(request, \u0027Ni!\u0027, \u0027hi\u0027)"},{"line_number":71,"context_line":""},{"line_number":72,"context_line":"    @mock.patch.object(nova.api, \u0027nova\u0027)"},{"line_number":73,"context_line":"    def _test_keypair_create_and_download(self, recreate_keypair, nc):"},{"line_number":74,"context_line":"        params \u003d {}"},{"line_number":75,"context_line":""},{"line_number":76,"context_line":"        if (recreate_keypair is True):"}],"source_content_type":"text/x-python","patch_set":11,"id":"ba63e191_175bdb2f","line":73,"in_reply_to":"ba63e191_5f940fe1","updated":"2016-01-19 18:18:10.000000000","message":"Done","commit_id":"f99f1d9df6fac7d78482920c83a3076bd2fb56a0"},{"author":{"_account_id":14124,"name":"Matt Borland","email":"matt.borland@hpe.com","username":"mborland"},"change_message_id":"b62d6b1af679bb19b157ad4998a75fec89d0cf70","unresolved":false,"context_lines":[{"line_number":73,"context_line":"    def _test_keypair_create_and_download(self, recreate_keypair, nc):"},{"line_number":74,"context_line":"        params \u003d {}"},{"line_number":75,"context_line":""},{"line_number":76,"context_line":"        if (recreate_keypair is True):"},{"line_number":77,"context_line":"            params \u003d {\u0027regenerate\u0027: \u0027true\u0027}"},{"line_number":78,"context_line":""},{"line_number":79,"context_line":"        request \u003d self.mock_rest_request(GET\u003dparams)"}],"source_content_type":"text/x-python","patch_set":11,"id":"ba63e191_04808e45","line":76,"range":{"start_line":76,"start_character":10,"end_line":76,"end_character":37},"updated":"2016-01-19 17:12:50.000000000","message":"Really should just be:\n\nif recreate_keypair:","commit_id":"f99f1d9df6fac7d78482920c83a3076bd2fb56a0"},{"author":{"_account_id":18508,"name":"Errol Pais","email":"errol.pais@protonmail.com","username":"errol"},"change_message_id":"d6fb06257b1623661fca98e6f58865144d820aa2","unresolved":false,"context_lines":[{"line_number":73,"context_line":"    def _test_keypair_create_and_download(self, recreate_keypair, nc):"},{"line_number":74,"context_line":"        params \u003d {}"},{"line_number":75,"context_line":""},{"line_number":76,"context_line":"        if (recreate_keypair is True):"},{"line_number":77,"context_line":"            params \u003d {\u0027regenerate\u0027: \u0027true\u0027}"},{"line_number":78,"context_line":""},{"line_number":79,"context_line":"        request \u003d self.mock_rest_request(GET\u003dparams)"}],"source_content_type":"text/x-python","patch_set":11,"id":"ba63e191_379cdfbf","line":76,"range":{"start_line":76,"start_character":10,"end_line":76,"end_character":37},"in_reply_to":"ba63e191_04808e45","updated":"2016-01-19 18:18:10.000000000","message":"Done","commit_id":"f99f1d9df6fac7d78482920c83a3076bd2fb56a0"},{"author":{"_account_id":14124,"name":"Matt Borland","email":"matt.borland@hpe.com","username":"mborland"},"change_message_id":"b62d6b1af679bb19b157ad4998a75fec89d0cf70","unresolved":false,"context_lines":[{"line_number":85,"context_line":"        with mock.patch.object(settings, \u0027DEBUG\u0027, True):"},{"line_number":86,"context_line":"            response \u003d nova.Keypair().get(request, \"Ni!\")"},{"line_number":87,"context_line":""},{"line_number":88,"context_line":"        if (recreate_keypair is True):"},{"line_number":89,"context_line":"            nc.keypair_delete.assert_called_once_with(request, \u0027Ni!\u0027)"},{"line_number":90,"context_line":"        else:"},{"line_number":91,"context_line":"            nc.keypair_delete.assert_not_called()"}],"source_content_type":"text/x-python","patch_set":11,"id":"ba63e191_243832a0","line":88,"range":{"start_line":88,"start_character":11,"end_line":88,"end_character":38},"updated":"2016-01-19 17:12:50.000000000","message":"Same as above.  Regardless, parens in python are frowned on in this case (not a c-based language).","commit_id":"f99f1d9df6fac7d78482920c83a3076bd2fb56a0"},{"author":{"_account_id":18508,"name":"Errol Pais","email":"errol.pais@protonmail.com","username":"errol"},"change_message_id":"d6fb06257b1623661fca98e6f58865144d820aa2","unresolved":false,"context_lines":[{"line_number":85,"context_line":"        with mock.patch.object(settings, \u0027DEBUG\u0027, True):"},{"line_number":86,"context_line":"            response \u003d nova.Keypair().get(request, \"Ni!\")"},{"line_number":87,"context_line":""},{"line_number":88,"context_line":"        if (recreate_keypair is True):"},{"line_number":89,"context_line":"            nc.keypair_delete.assert_called_once_with(request, \u0027Ni!\u0027)"},{"line_number":90,"context_line":"        else:"},{"line_number":91,"context_line":"            nc.keypair_delete.assert_not_called()"}],"source_content_type":"text/x-python","patch_set":11,"id":"ba63e191_17a99bdf","line":88,"range":{"start_line":88,"start_character":11,"end_line":88,"end_character":38},"in_reply_to":"ba63e191_243832a0","updated":"2016-01-19 18:18:10.000000000","message":"Done","commit_id":"f99f1d9df6fac7d78482920c83a3076bd2fb56a0"}]}
