{"action":"created","comment":{"url":"https://api.github.com/repos/pulp/pulp/pulls/comments/24532087","id":24532087,"diff_hunk":"@@ -0,0 +1,186 @@\n+import unittest\n+\n+import mock\n+\n+from base import assert_auth_EXECUTE, assert_auth_READ\n+from pulp.server.exceptions import InvalidValue\n+from pulp.server.webservices.views.permissions import (GrantToRoleView, GrantToUserView,\n+                                                       PermissionView, RevokeFromRoleView,\n+                                                       RevokeFromUserView)\n+\n+\n+class TestPermissionsiew(unittest.TestCase):\n+    \"\"\"\n+    Test permissions view.\n+    \"\"\"\n+\n+    @mock.patch('pulp.server.webservices.controllers.decorators._verify_auth',\n+                new=assert_auth_READ())\n+    @mock.patch(\n+        'pulp.server.webservices.views.permissions.generate_json_response_with_pulp_encoder')\n+    @mock.patch('pulp.server.webservices.views.permissions.factory')\n+    def test_get_all_permissions(self, mock_f, mock_resp):\n+        \"\"\"\n+        Test the permissions retrieval.\n+        \"\"\"\n+        perm = [{'resource': '/v2/some/', 'id': '1234',\n+                'users': [{'username': 'test-user', 'permissions': [0]}]}]\n+\n+        mock_f.permission_query_manager.return_value.find_all.return_value = perm\n+        mock_f.permission_manager.return_value.operation_value_to_name.return_value = 'READ'\n+\n+        request = mock.MagicMock()\n+        request.GET = {}\n+\n+        permission = PermissionView()\n+        response = permission.get(request)\n+        expected_cont = [{'id': '1234', 'resource': '/v2/some/', 'users': {'test-user': ['READ']}}]\n+\n+        mock_resp.assert_called_once_with(expected_cont)\n+        self.assertTrue(response is mock_resp.return_value)\n+\n+    @mock.patch('pulp.server.webservices.controllers.decorators._verify_auth',\n+                new=assert_auth_READ())\n+    @mock.patch(\n+        'pulp.server.webservices.views.permissions.generate_json_response_with_pulp_encoder')\n+    @mock.patch('pulp.server.webservices.views.permissions.factory')\n+    def test_get_resource_permission(self, mock_f, mock_resp):\n+        \"\"\"\n+        Test specific resource permissions retrieval.\n+        \"\"\"\n+        perm = {'resource': '/v2/some/', 'id': '1234',\n+                'users': [{'username': 'test-user', 'permissions': [0]}]}\n+\n+        mock_f.permission_query_manager.return_value.find_by_resource.return_value = perm\n+        mock_f.permission_manager.return_value.operation_value_to_name.return_value = 'READ'\n+\n+        request = mock.MagicMock()\n+        request.GET = {'resource': '/v2/some/'}\n+\n+        permission = PermissionView()\n+        response = permission.get(request)\n+        expected_cont = [{'id': '1234', 'resource': '/v2/some/', 'users': {'test-user': ['READ']}}]\n+\n+        mock_resp.assert_called_once_with(expected_cont)\n+        self.assertTrue(response is mock_resp.return_value)\n+\n+\n+class TestGrantToUserView(unittest.TestCase):\n+    \"\"\"\n+    Test grant permission to user.\n+    \"\"\"\n+    @mock.patch('pulp.server.webservices.controllers.decorators._verify_auth',\n+                new=assert_auth_EXECUTE())\n+    @mock.patch('pulp.server.webservices.views.permissions.generate_json_response')\n+    @mock.patch('pulp.server.webservices.views.permissions.factory')\n+    def test_grant_to_user(self, mock_factory, mock_resp):\n+        \"\"\"\n+        Test grant permissions to user.\n+        \"\"\"\n+        request = mock.MagicMock()\n+        request.body_as_json = {'operations': ['READ'], 'login': 'test', 'resource': '/v2/some/'}\n+        mock_factory.permission_manager.return_value.grant.return_value = None\n+        mock_factory.permission_manager.return_value.operation_names_to_values.return_value = [0]\n+        grant = GrantToUserView()\n+        response = grant.post(request)\n+\n+        mock_resp.assert_called_once_with(None)\n+        self.assertTrue(response is mock_resp.return_value)\n+        mock_factory.permission_manager.return_value.grant.assert_called_once_with(\n+            '/v2/some/', 'test', [0])\n+\n+    @mock.patch('pulp.server.webservices.controllers.decorators._verify_auth',\n+                new=assert_auth_EXECUTE())\n+    def test_grant_to_user_invalid_param(self):\n+        \"\"\"\n+        Test grant permissions to user with invalid params.\n+        \"\"\"\n+        request = mock.MagicMock()\n+        request.body_as_json = {'operations': ['READ'], 'resource': '/v2/some/'}\n+        grant = GrantToUserView()\n+        try:\n+            grant.post(request)\n+        except InvalidValue, response:","path":"server/test/unit/server/webservices/views/test_permissions.py","position":103,"original_position":103,"commit_id":"0785c2d75d112ce925b88d7860c891b6c7fee112","original_commit_id":"0785c2d75d112ce925b88d7860c891b6c7fee112","user":{"login":"bmbouter","id":180319,"avatar_url":"https://avatars.githubusercontent.com/u/180319?v=3","gravatar_id":"","url":"https://api.github.com/users/bmbouter","html_url":"https://github.com/bmbouter","followers_url":"https://api.github.com/users/bmbouter/followers","following_url":"https://api.github.com/users/bmbouter/following{/other_user}","gists_url":"https://api.github.com/users/bmbouter/gists{/gist_id}","starred_url":"https://api.github.com/users/bmbouter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmbouter/subscriptions","organizations_url":"https://api.github.com/users/bmbouter/orgs","repos_url":"https://api.github.com/users/bmbouter/repos","events_url":"https://api.github.com/users/bmbouter/events{/privacy}","received_events_url":"https://api.github.com/users/bmbouter/received_events","type":"User","site_admin":false},"body":"This may be problematic because you won't have a reference to the 'response' object anymore. Perhaps that is why it is written this way. It's up to you how best to fix it (if any).","created_at":"2015-02-11T20:51:54Z","updated_at":"2015-02-11T20:51:54Z","html_url":"https://github.com/pulp/pulp/pull/1635#discussion_r24532087","pull_request_url":"https://api.github.com/repos/pulp/pulp/pulls/1635","_links":{"self":{"href":"https://api.github.com/repos/pulp/pulp/pulls/comments/24532087"},"html":{"href":"https://github.com/pulp/pulp/pull/1635#discussion_r24532087"},"pull_request":{"href":"https://api.github.com/repos/pulp/pulp/pulls/1635"}}},"pull_request":{"url":"https://api.github.com/repos/pulp/pulp/pulls/1635","id":29097852,"html_url":"https://github.com/pulp/pulp/pull/1635","diff_url":"https://github.com/pulp/pulp/pull/1635.diff","patch_url":"https://github.com/pulp/pulp/pull/1635.patch","issue_url":"https://api.github.com/repos/pulp/pulp/issues/1635","number":1635,"state":"open","locked":false,"title":"Introducing permissions view.","user":{"login":"ipanova","id":4253816,"avatar_url":"https://avatars.githubusercontent.com/u/4253816?v=3","gravatar_id":"","url":"https://api.github.com/users/ipanova","html_url":"https://github.com/ipanova","followers_url":"https://api.github.com/users/ipanova/followers","following_url":"https://api.github.com/users/ipanova/following{/other_user}","gists_url":"https://api.github.com/users/ipanova/gists{/gist_id}","starred_url":"https://api.github.com/users/ipanova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ipanova/subscriptions","organizations_url":"https://api.github.com/users/ipanova/orgs","repos_url":"https://api.github.com/users/ipanova/repos","events_url":"https://api.github.com/users/ipanova/events{/privacy}","received_events_url":"https://api.github.com/users/ipanova/received_events","type":"User","site_admin":false},"body":"GET /pulp/api/v2/permissions/ http://fpaste.org/184277/42366756/\r\nGET /pulp/api/v2/permissions for particular resource http://fpaste.org/184276/42366749/\r\nPOST /pulp/api/v2/permissions/actions/grant_to_user/ http://fpaste.org/184289/14236692/\r\nPOST /pulp/api/v2/permissions/actions/grant_to_role/ http://fpaste.org/184292/36693731/\r\nPOST /pulp/api/v2/permissions/actions/revoke_from_role/  http://fpaste.org/184297/69689142/\r\nPOST /pulp/api/v2/permissions/actions/revoke_from_user/ http://fpaste.org/184298/23669796/\r\nPOST invalid params /pulp/api/v2/permissions/actions/revoke_from_user/  http://fpaste.org/184301/23669940/  (rest of the cases are the same)","created_at":"2015-02-11T15:08:16Z","updated_at":"2015-02-11T20:51:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2ec089d772befacd02a5c31c84a6feea5dcdf464","assignee":{"login":"bmbouter","id":180319,"avatar_url":"https://avatars.githubusercontent.com/u/180319?v=3","gravatar_id":"","url":"https://api.github.com/users/bmbouter","html_url":"https://github.com/bmbouter","followers_url":"https://api.github.com/users/bmbouter/followers","following_url":"https://api.github.com/users/bmbouter/following{/other_user}","gists_url":"https://api.github.com/users/bmbouter/gists{/gist_id}","starred_url":"https://api.github.com/users/bmbouter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bmbouter/subscriptions","organizations_url":"https://api.github.com/users/bmbouter/orgs","repos_url":"https://api.github.com/users/bmbouter/repos","events_url":"https://api.github.com/users/bmbouter/events{/privacy}","received_events_url":"https://api.github.com/users/bmbouter/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/pulp/pulp/pulls/1635/commits","review_comments_url":"https://api.github.com/repos/pulp/pulp/pulls/1635/comments","review_comment_url":"https://api.github.com/repos/pulp/pulp/pulls/comments/{number}","comments_url":"https://api.github.com/repos/pulp/pulp/issues/1635/comments","statuses_url":"https://api.github.com/repos/pulp/pulp/statuses/0785c2d75d112ce925b88d7860c891b6c7fee112","head":{"label":"ipanova:permissions-django","ref":"permissions-django","sha":"0785c2d75d112ce925b88d7860c891b6c7fee112","user":{"login":"ipanova","id":4253816,"avatar_url":"https://avatars.githubusercontent.com/u/4253816?v=3","gravatar_id":"","url":"https://api.github.com/users/ipanova","html_url":"https://github.com/ipanova","followers_url":"https://api.github.com/users/ipanova/followers","following_url":"https://api.github.com/users/ipanova/following{/other_user}","gists_url":"https://api.github.com/users/ipanova/gists{/gist_id}","starred_url":"https://api.github.com/users/ipanova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ipanova/subscriptions","organizations_url":"https://api.github.com/users/ipanova/orgs","repos_url":"https://api.github.com/users/ipanova/repos","events_url":"https://api.github.com/users/ipanova/events{/privacy}","received_events_url":"https://api.github.com/users/ipanova/received_events","type":"User","site_admin":false},"repo":{"id":17410078,"name":"pulp","full_name":"ipanova/pulp","owner":{"login":"ipanova","id":4253816,"avatar_url":"https://avatars.githubusercontent.com/u/4253816?v=3","gravatar_id":"","url":"https://api.github.com/users/ipanova","html_url":"https://github.com/ipanova","followers_url":"https://api.github.com/users/ipanova/followers","following_url":"https://api.github.com/users/ipanova/following{/other_user}","gists_url":"https://api.github.com/users/ipanova/gists{/gist_id}","starred_url":"https://api.github.com/users/ipanova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ipanova/subscriptions","organizations_url":"https://api.github.com/users/ipanova/orgs","repos_url":"https://api.github.com/users/ipanova/repos","events_url":"https://api.github.com/users/ipanova/events{/privacy}","received_events_url":"https://api.github.com/users/ipanova/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ipanova/pulp","description":"Repository for Pulp platform code, including the server and base admin and consumer clients","fork":true,"url":"https://api.github.com/repos/ipanova/pulp","forks_url":"https://api.github.com/repos/ipanova/pulp/forks","keys_url":"https://api.github.com/repos/ipanova/pulp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ipanova/pulp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ipanova/pulp/teams","hooks_url":"https://api.github.com/repos/ipanova/pulp/hooks","issue_events_url":"https://api.github.com/repos/ipanova/pulp/issues/events{/number}","events_url":"https://api.github.com/repos/ipanova/pulp/events","assignees_url":"https://api.github.com/repos/ipanova/pulp/assignees{/user}","branches_url":"https://api.github.com/repos/ipanova/pulp/branches{/branch}","tags_url":"https://api.github.com/repos/ipanova/pulp/tags","blobs_url":"https://api.github.com/repos/ipanova/pulp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ipanova/pulp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ipanova/pulp/git/refs{/sha}","trees_url":"https://api.github.com/repos/ipanova/pulp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ipanova/pulp/statuses/{sha}","languages_url":"https://api.github.com/repos/ipanova/pulp/languages","stargazers_url":"https://api.github.com/repos/ipanova/pulp/stargazers","contributors_url":"https://api.github.com/repos/ipanova/pulp/contributors","subscribers_url":"https://api.github.com/repos/ipanova/pulp/subscribers","subscription_url":"https://api.github.com/repos/ipanova/pulp/subscription","commits_url":"https://api.github.com/repos/ipanova/pulp/commits{/sha}","git_commits_url":"https://api.github.com/repos/ipanova/pulp/git/commits{/sha}","comments_url":"https://api.github.com/repos/ipanova/pulp/comments{/number}","issue_comment_url":"https://api.github.com/repos/ipanova/pulp/issues/comments/{number}","contents_url":"https://api.github.com/repos/ipanova/pulp/contents/{+path}","compare_url":"https://api.github.com/repos/ipanova/pulp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ipanova/pulp/merges","archive_url":"https://api.github.com/repos/ipanova/pulp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ipanova/pulp/downloads","issues_url":"https://api.github.com/repos/ipanova/pulp/issues{/number}","pulls_url":"https://api.github.com/repos/ipanova/pulp/pulls{/number}","milestones_url":"https://api.github.com/repos/ipanova/pulp/milestones{/number}","notifications_url":"https://api.github.com/repos/ipanova/pulp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ipanova/pulp/labels{/name}","releases_url":"https://api.github.com/repos/ipanova/pulp/releases{/id}","created_at":"2014-03-04T17:13:28Z","updated_at":"2015-01-06T12:05:33Z","pushed_at":"2015-02-11T16:43:24Z","git_url":"git://github.com/ipanova/pulp.git","ssh_url":"git@github.com:ipanova/pulp.git","clone_url":"https://github.com/ipanova/pulp.git","svn_url":"https://github.com/ipanova/pulp","homepage":"","size":80120,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pulp:master","ref":"master","sha":"e944e64f273811c1f7690e00616a2df2b2e725f0","user":{"login":"pulp","id":2103606,"avatar_url":"https://avatars.githubusercontent.com/u/2103606?v=3","gravatar_id":"","url":"https://api.github.com/users/pulp","html_url":"https://github.com/pulp","followers_url":"https://api.github.com/users/pulp/followers","following_url":"https://api.github.com/users/pulp/following{/other_user}","gists_url":"https://api.github.com/users/pulp/gists{/gist_id}","starred_url":"https://api.github.com/users/pulp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pulp/subscriptions","organizations_url":"https://api.github.com/users/pulp/orgs","repos_url":"https://api.github.com/users/pulp/repos","events_url":"https://api.github.com/users/pulp/events{/privacy}","received_events_url":"https://api.github.com/users/pulp/received_events","type":"Organization","site_admin":false},"repo":{"id":5314652,"name":"pulp","full_name":"pulp/pulp","owner":{"login":"pulp","id":2103606,"avatar_url":"https://avatars.githubusercontent.com/u/2103606?v=3","gravatar_id":"","url":"https://api.github.com/users/pulp","html_url":"https://github.com/pulp","followers_url":"https://api.github.com/users/pulp/followers","following_url":"https://api.github.com/users/pulp/following{/other_user}","gists_url":"https://api.github.com/users/pulp/gists{/gist_id}","starred_url":"https://api.github.com/users/pulp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pulp/subscriptions","organizations_url":"https://api.github.com/users/pulp/orgs","repos_url":"https://api.github.com/users/pulp/repos","events_url":"https://api.github.com/users/pulp/events{/privacy}","received_events_url":"https://api.github.com/users/pulp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pulp/pulp","description":"Repository for Pulp platform code, including the server and base admin and consumer clients","fork":false,"url":"https://api.github.com/repos/pulp/pulp","forks_url":"https://api.github.com/repos/pulp/pulp/forks","keys_url":"https://api.github.com/repos/pulp/pulp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pulp/pulp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pulp/pulp/teams","hooks_url":"https://api.github.com/repos/pulp/pulp/hooks","issue_events_url":"https://api.github.com/repos/pulp/pulp/issues/events{/number}","events_url":"https://api.github.com/repos/pulp/pulp/events","assignees_url":"https://api.github.com/repos/pulp/pulp/assignees{/user}","branches_url":"https://api.github.com/repos/pulp/pulp/branches{/branch}","tags_url":"https://api.github.com/repos/pulp/pulp/tags","blobs_url":"https://api.github.com/repos/pulp/pulp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pulp/pulp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pulp/pulp/git/refs{/sha}","trees_url":"https://api.github.com/repos/pulp/pulp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pulp/pulp/statuses/{sha}","languages_url":"https://api.github.com/repos/pulp/pulp/languages","stargazers_url":"https://api.github.com/repos/pulp/pulp/stargazers","contributors_url":"https://api.github.com/repos/pulp/pulp/contributors","subscribers_url":"https://api.github.com/repos/pulp/pulp/subscribers","subscription_url":"https://api.github.com/repos/pulp/pulp/subscription","commits_url":"https://api.github.com/repos/pulp/pulp/commits{/sha}","git_commits_url":"https://api.github.com/repos/pulp/pulp/git/commits{/sha}","comments_url":"https://api.github.com/repos/pulp/pulp/comments{/number}","issue_comment_url":"https://api.github.com/repos/pulp/pulp/issues/comments/{number}","contents_url":"https://api.github.com/repos/pulp/pulp/contents/{+path}","compare_url":"https://api.github.com/repos/pulp/pulp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pulp/pulp/merges","archive_url":"https://api.github.com/repos/pulp/pulp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pulp/pulp/downloads","issues_url":"https://api.github.com/repos/pulp/pulp/issues{/number}","pulls_url":"https://api.github.com/repos/pulp/pulp/pulls{/number}","milestones_url":"https://api.github.com/repos/pulp/pulp/milestones{/number}","notifications_url":"https://api.github.com/repos/pulp/pulp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pulp/pulp/labels{/name}","releases_url":"https://api.github.com/repos/pulp/pulp/releases{/id}","created_at":"2012-08-06T13:49:20Z","updated_at":"2015-02-11T06:12:26Z","pushed_at":"2015-02-11T06:12:26Z","git_url":"git://github.com/pulp/pulp.git","ssh_url":"git@github.com:pulp/pulp.git","clone_url":"https://github.com/pulp/pulp.git","svn_url":"https://github.com/pulp/pulp","homepage":"","size":201826,"stargazers_count":179,"watchers_count":179,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":77,"mirror_url":null,"open_issues_count":16,"forks":77,"open_issues":16,"watchers":179,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pulp/pulp/pulls/1635"},"html":{"href":"https://github.com/pulp/pulp/pull/1635"},"issue":{"href":"https://api.github.com/repos/pulp/pulp/issues/1635"},"comments":{"href":"https://api.github.com/repos/pulp/pulp/issues/1635/comments"},"review_comments":{"href":"https://api.github.com/repos/pulp/pulp/pulls/1635/comments"},"review_comment":{"href":"https://api.github.com/repos/pulp/pulp/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/pulp/pulp/pulls/1635/commits"},"statuses":{"href":"https://api.github.com/repos/pulp/pulp/statuses/0785c2d75d112ce925b88d7860c891b6c7fee112"}}}}