)]}'
{"/COMMIT_MSG":[{"author":{"_account_id":7711,"name":"Yuriy Zveryanskyy","email":"yzveryanskyy@mirantis.com","username":"yuriyz"},"change_message_id":"849b7f0c4863fcc9b2b7491f097248f7f6a5beef","unresolved":false,"context_lines":[{"line_number":12,"context_line":""},{"line_number":13,"context_line":"This is done by patching sys.modules to replace the @expose decorator"},{"line_number":14,"context_line":"with a wrapper that records a reference to the exposed method. Then,"},{"line_number":15,"context_line":"all API modules\u0027 (chassis, node, port, etc.) sources are reloaded"},{"line_number":16,"context_line":"within the unit test, causing the test classes own decorator to be"},{"line_number":17,"context_line":"called, and references to every @expose\u0027d method to be recorded in the"},{"line_number":18,"context_line":"test class instance. The test case then iterates over that list of"},{"line_number":19,"context_line":"function references, and inspects the python source of each one to"},{"line_number":20,"context_line":"determine if it contains a call to the policy.authorize and"},{"line_number":21,"context_line":"context.to_policy_values methods. An error is raised if it does not."},{"line_number":22,"context_line":""},{"line_number":23,"context_line":"Note that there is a risk other unit tests are run at the same time, and"},{"line_number":24,"context_line":"encounter our tests @expose decorator. This should be fine: we are"},{"line_number":25,"context_line":"actually calling the real @expose decorator from within. It could result"},{"line_number":26,"context_line":"in a unit test asserting that other @expose\u0027d methods also contain calls"},{"line_number":27,"context_line":"to policy.authorize, which should also be fine."},{"line_number":28,"context_line":""},{"line_number":29,"context_line":"This approach is rather brutish, but without being able to invoke"},{"line_number":30,"context_line":"@authorize as a decorator (*) I have not found a better way than"}],"source_content_type":"text/x-gerrit-commit-message","patch_set":6,"id":"1a6eadb0_2e46d67a","line":27,"range":{"start_line":15,"start_character":0,"end_line":27,"end_character":47},"updated":"2016-12-16 17:28:40.000000000","message":"Outdated info.","commit_id":"1dd706a0cd030d465c1a71b159ca2eead041a333"},{"author":{"_account_id":12356,"name":"Vladyslav Drok","email":"vdrok@mirantis.com","username":"vdrok"},"change_message_id":"fabfc8d11111d928f8ad06d3cfb0eb3fd8e07cd6","unresolved":false,"context_lines":[{"line_number":12,"context_line":""},{"line_number":13,"context_line":"This is done by patching sys.modules to replace the @expose decorator"},{"line_number":14,"context_line":"with a wrapper that records a reference to the exposed method. Then,"},{"line_number":15,"context_line":"all API modules\u0027 (chassis, node, port, etc.) sources are reloaded"},{"line_number":16,"context_line":"within the unit test, causing the test classes own decorator to be"},{"line_number":17,"context_line":"called, and references to every @expose\u0027d method to be recorded in the"},{"line_number":18,"context_line":"test class instance. The test case then iterates over that list of"},{"line_number":19,"context_line":"function references, and inspects the python source of each one to"},{"line_number":20,"context_line":"determine if it contains a call to the policy.authorize and"},{"line_number":21,"context_line":"context.to_policy_values methods. An error is raised if it does not."},{"line_number":22,"context_line":""},{"line_number":23,"context_line":"Note that there is a risk other unit tests are run at the same time, and"},{"line_number":24,"context_line":"encounter our tests @expose decorator. This should be fine: we are"},{"line_number":25,"context_line":"actually calling the real @expose decorator from within. It could result"},{"line_number":26,"context_line":"in a unit test asserting that other @expose\u0027d methods also contain calls"},{"line_number":27,"context_line":"to policy.authorize, which should also be fine."},{"line_number":28,"context_line":""},{"line_number":29,"context_line":"This approach is rather brutish, but without being able to invoke"},{"line_number":30,"context_line":"@authorize as a decorator (*) I have not found a better way than"}],"source_content_type":"text/x-gerrit-commit-message","patch_set":6,"id":"1a6eadb0_31b2b7e5","line":27,"range":{"start_line":15,"start_character":0,"end_line":27,"end_character":47},"in_reply_to":"1a6eadb0_2e46d67a","updated":"2016-12-16 17:47:32.000000000","message":"Only the second paragraph is, will remove it.","commit_id":"1dd706a0cd030d465c1a71b159ca2eead041a333"}],"ironic/tests/unit/api/v1/test_expose.py":[{"author":{"_account_id":6773,"name":"Lucas Alvares Gomes","email":"lucasagomes@gmail.com","username":"lucasagomes"},"change_message_id":"4fe19dd81f3bf4ae68513c4b2f3d8ba4c15521d6","unresolved":false,"context_lines":[{"line_number":40,"context_line":"                return e(f)"},{"line_number":41,"context_line":"            return wrap"},{"line_number":42,"context_line":""},{"line_number":43,"context_line":"        sys.modules[\u0027ironic.api.expose\u0027].expose \u003d expose_and_track"},{"line_number":44,"context_line":"        self.addCleanup(self._restore)"},{"line_number":45,"context_line":""},{"line_number":46,"context_line":"    def _restore(self):"}],"source_content_type":"text/x-python","patch_set":4,"id":"fa7ab95a_94e2d82d","line":43,"updated":"2016-08-29 18:29:20.000000000","message":"So replacing the sys.module will cause a race condition on other tests.\n\nWhat if we mocked the \"wsmeext.pecan.wsexpose\" method ?\n\ne.g\n\nimport wsmeext.pecan as wsme_pecan\n\n @mock.patch.object(wsme_pecan, \u0027wsexpose\u0027)\n class TestExposedAPIMethodsCheckPolicy(test_base.TestCase):\n\n     def test_blah(self, mock_wsexpose):\n         reload(\u003cmodule\u003e)\n         expected \u003d [mock.call(...), mock.call(...), ...]\n         mock_wsexpose.assert_has_calls(expected)\n\nI haven\u0027t tested the above, but it should work like that or along that idea.","commit_id":"50728029410ee6f9a0f562a3dfca4cb5024c22ae"},{"author":{"_account_id":12356,"name":"Vladyslav Drok","email":"vdrok@mirantis.com","username":"vdrok"},"change_message_id":"5a19a9c5b64ada110adbf85ef8d2d2bbf4f4596b","unresolved":false,"context_lines":[{"line_number":40,"context_line":"                return e(f)"},{"line_number":41,"context_line":"            return wrap"},{"line_number":42,"context_line":""},{"line_number":43,"context_line":"        sys.modules[\u0027ironic.api.expose\u0027].expose \u003d expose_and_track"},{"line_number":44,"context_line":"        self.addCleanup(self._restore)"},{"line_number":45,"context_line":""},{"line_number":46,"context_line":"    def _restore(self):"}],"source_content_type":"text/x-python","patch_set":4,"id":"fa7ab95a_df3fe6b1","line":43,"in_reply_to":"fa7ab95a_94e2d82d","updated":"2016-08-30 12:49:14.000000000","message":"But this way we won\u0027t track on which methods the expose decorator are, we still need the expose_and_track.\n\nAnother way would be just to inspect the functions that have _wsme_definition attribute https://github.com/openstack/wsme/blob/a88c83001f2e80fb175a5f346935554baba269ef/wsme/api.py#L94. It\u0027s private, but still, things get easier.","commit_id":"50728029410ee6f9a0f562a3dfca4cb5024c22ae"},{"author":{"_account_id":12356,"name":"Vladyslav Drok","email":"vdrok@mirantis.com","username":"vdrok"},"change_message_id":"546a5a35629f0294c09deff3f0f3260c0e0fa925","unresolved":false,"context_lines":[{"line_number":40,"context_line":"                return e(f)"},{"line_number":41,"context_line":"            return wrap"},{"line_number":42,"context_line":""},{"line_number":43,"context_line":"        sys.modules[\u0027ironic.api.expose\u0027].expose \u003d expose_and_track"},{"line_number":44,"context_line":"        self.addCleanup(self._restore)"},{"line_number":45,"context_line":""},{"line_number":46,"context_line":"    def _restore(self):"}],"source_content_type":"text/x-python","patch_set":4,"id":"1a6eadb0_240b5cd7","line":43,"in_reply_to":"fa7ab95a_df3fe6b1","updated":"2016-12-16 16:15:58.000000000","message":"We could get away with only using inspect on the functions that have .exposed attribute set, but inspect itself on py2 returns only decorator code itself, with no way I was able to find to get the actual function code. So, went further this way.","commit_id":"50728029410ee6f9a0f562a3dfca4cb5024c22ae"},{"author":{"_account_id":7711,"name":"Yuriy Zveryanskyy","email":"yzveryanskyy@mirantis.com","username":"yuriyz"},"change_message_id":"849b7f0c4863fcc9b2b7491f097248f7f6a5beef","unresolved":false,"context_lines":[{"line_number":58,"context_line":"            self.assertTrue(\u0027context.to_policy_values\u0027 in src,"},{"line_number":59,"context_line":"                            \u0027context.to_policy_values call not found in \u0027"},{"line_number":60,"context_line":"                            \u0027exposed method %s\u0027 % func)"},{"line_number":61,"context_line":""},{"line_number":62,"context_line":"    def test_chasis_api_policy(self):"},{"line_number":63,"context_line":"        self._test(\u0027ironic.api.controllers.v1.chassis\u0027)"},{"line_number":64,"context_line":""}],"source_content_type":"text/x-python","patch_set":6,"id":"1a6eadb0_0e6cba06","line":61,"updated":"2016-12-16 17:28:40.000000000","message":"Will be good add some cleanup here: del sys.modules[uuid]","commit_id":"1dd706a0cd030d465c1a71b159ca2eead041a333"},{"author":{"_account_id":12356,"name":"Vladyslav Drok","email":"vdrok@mirantis.com","username":"vdrok"},"change_message_id":"fabfc8d11111d928f8ad06d3cfb0eb3fd8e07cd6","unresolved":false,"context_lines":[{"line_number":58,"context_line":"            self.assertTrue(\u0027context.to_policy_values\u0027 in src,"},{"line_number":59,"context_line":"                            \u0027context.to_policy_values call not found in \u0027"},{"line_number":60,"context_line":"                            \u0027exposed method %s\u0027 % func)"},{"line_number":61,"context_line":""},{"line_number":62,"context_line":"    def test_chasis_api_policy(self):"},{"line_number":63,"context_line":"        self._test(\u0027ironic.api.controllers.v1.chassis\u0027)"},{"line_number":64,"context_line":""}],"source_content_type":"text/x-python","patch_set":6,"id":"1a6eadb0_71a18f93","line":61,"in_reply_to":"1a6eadb0_0e6cba06","updated":"2016-12-16 17:47:32.000000000","message":"I\u0027m not sure about the reason, but the tests fail with that.","commit_id":"1dd706a0cd030d465c1a71b159ca2eead041a333"},{"author":{"_account_id":7711,"name":"Yuriy Zveryanskyy","email":"yzveryanskyy@mirantis.com","username":"yuriyz"},"change_message_id":"310350a4bad46bd2fdd66334b493d03e2981ac8f","unresolved":false,"context_lines":[{"line_number":61,"context_line":""},{"line_number":62,"context_line":"    def test_chasis_api_policy(self):"},{"line_number":63,"context_line":"        self._test(\u0027ironic.api.controllers.v1.chassis\u0027)"},{"line_number":64,"context_line":""},{"line_number":65,"context_line":"    def test_driver_api_policy(self):"},{"line_number":66,"context_line":"        self._test(\u0027ironic.api.controllers.v1.driver\u0027)"},{"line_number":67,"context_line":""}],"source_content_type":"text/x-python","patch_set":7,"id":"1a6eadb0_65dc4875","line":64,"updated":"2016-12-19 04:06:50.000000000","message":"Maybe use something like pkgutil.iter_modules() here? For case if new module will be added.","commit_id":"16d50732f628a6e05d440246e0f4dc400155ad45"},{"author":{"_account_id":10343,"name":"Jim Rollenhagen","email":"jim@jimrollenhagen.com","username":"jimrollenhagen"},"change_message_id":"67873078e6830f49137d4e8ebee20a4bce534e97","unresolved":false,"context_lines":[{"line_number":53,"context_line":"        for func in self.exposed_methods:"},{"line_number":54,"context_line":"            src \u003d inspect.getsource(func)"},{"line_number":55,"context_line":"            self.assertTrue(\u0027policy.authorize\u0027 in src,"},{"line_number":56,"context_line":"                            \u0027policy.authroize call not found in exposed \u0027"},{"line_number":57,"context_line":"                            \u0027method %s\u0027 % func)"},{"line_number":58,"context_line":"            self.assertTrue(\u0027context.to_policy_values\u0027 in src,"},{"line_number":59,"context_line":"                            \u0027context.to_policy_values call not found in \u0027"}],"source_content_type":"text/x-python","patch_set":9,"id":"1a6eadb0_3fe84b10","line":56,"updated":"2016-12-20 13:19:47.000000000","message":"nit: s/authroize/authorize/","commit_id":"90c6130aa13bc06273fec31b1946de2e0324aa81"}]}
