{"action":"created","comment":{"url":"https://api.github.com/repos/mitodl/lore/pulls/comments/32860835","id":32860835,"diff_hunk":"@@ -0,0 +1,103 @@\n+\"\"\"\n+Test the roles utils\n+\"\"\"\n+\n+from __future__ import unicode_literals\n+\n+from django.contrib.auth.models import Group\n+from django.core.management import call_command\n+from django.utils.text import slugify\n+from guardian.shortcuts import get_perms\n+from mock import patch\n+\n+from learningresources.api import create_repo\n+from learningresources.tests.base import LoreTestCase\n+from roles.permissions import RepoPermission, GroupTypes\n+from roles import utils\n+\n+\n+class TestRoleUtils(LoreTestCase):\n+    \"\"\"\n+    Tests for the roles Utils\n+    \"\"\"\n+    # pylint: disable=too-many-instance-attributes\n+    def __init__(self, *args, **kwargs):\n+        super(TestRoleUtils, self).__init__(*args, **kwargs)\n+        self.repo_name = 'my little+test repo'\n+        self.repo_desc = 'test description'\n+        self.repo_slug = slugify(self.repo_name)\n+\n+        self.group_admin = GroupTypes.REPO_ADMINISTRATOR.format(self.repo_slug)\n+        self.group_curator = GroupTypes.REPO_CURATOR.format(self.repo_slug)\n+        self.group_author = GroupTypes.REPO_AUTHOR.format(self.repo_slug)\n+\n+    def check_group_permission(self, repo, group, expected_permissions):\n+        \"\"\"\n+        helper function\n+        \"\"\"\n+        self.assertListEqual(\n+            sorted(get_perms(group, repo)),\n+            sorted(expected_permissions)\n+        )\n+\n+    def test_sync_permissions(self):\n+        \"\"\"\n+        test the syncpermission\n+        \"\"\"\n+        repo = create_repo(self.repo_name, self.repo_desc, self.user.id)\n+\n+        # permissions before wiping\n+        admin = Group.objects.get(name=self.group_admin)\n+        self.check_group_permission(\n+            repo,\n+            admin,\n+            RepoPermission.administrator_permissions()\n+        )\n+        with patch.object(utils, 'roles_init_new_repo') as mock_method:\n+            mock_method.return_value = None\n+            utils.sync_groups_permissions()\n+        # permissions after wiping\n+        self.check_group_permission(\n+            repo,\n+            admin,\n+            []\n+        )\n+        # restore permissions the first call of sync_groups_permissions\n+        # will not do anything because the permissions have been alredy wiped\n+        utils.sync_groups_permissions()\n+        self.check_group_permission(\n+            repo,\n+            admin,\n+            RepoPermission.administrator_permissions()\n+        )\n+\n+    def test_sync_permissions_command(self):\n+        \"\"\"\n+        tests the syncpermission via manage.py command\n+        \"\"\"\n+        repo = create_repo(self.repo_name, self.repo_desc, self.user.id)\n+\n+        # permissions before wiping\n+        admin = Group.objects.get(name=self.group_admin)\n+        self.check_group_permission(\n+            repo,\n+            admin,\n+            RepoPermission.administrator_permissions()\n+        )\n+        with patch.object(utils, 'roles_init_new_repo') as mock_method:\n+            mock_method.return_value = None\n+            call_command('sync_permissions')\n+        # permissions after wiping\n+        self.check_group_permission(\n+            repo,\n+            admin,\n+            []\n+        )\n+        # restore permissions the first call of sync_groups_permissions\n+        # will not do anything because the permissions have been alredy wiped\n+        call_command('sync_permissions')\n+        self.check_group_permission(\n+            repo,\n+            admin,\n+            RepoPermission.administrator_permissions()\n+        )","path":"roles/tests/test_utils.py","position":54,"original_position":103,"commit_id":"8c943cd3184f6ce996f9e3cff17757626bf0dcbf","original_commit_id":"9a61fd2d79f07bb2ca463f1169757ca843494b77","user":{"login":"carsongee","id":596029,"avatar_url":"https://avatars.githubusercontent.com/u/596029?v=3","gravatar_id":"","url":"https://api.github.com/users/carsongee","html_url":"https://github.com/carsongee","followers_url":"https://api.github.com/users/carsongee/followers","following_url":"https://api.github.com/users/carsongee/following{/other_user}","gists_url":"https://api.github.com/users/carsongee/gists{/gist_id}","starred_url":"https://api.github.com/users/carsongee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carsongee/subscriptions","organizations_url":"https://api.github.com/users/carsongee/orgs","repos_url":"https://api.github.com/users/carsongee/repos","events_url":"https://api.github.com/users/carsongee/events{/privacy}","received_events_url":"https://api.github.com/users/carsongee/received_events","type":"User","site_admin":false},"body":"You've already tested that with `test_sync_permissions` above, so you really just need a unit test, not an integration test here as it can speed tests up a little bit, but not a big deal.  Happy to merge without changing this.","created_at":"2015-06-19T19:24:13Z","updated_at":"2015-06-19T19:24:13Z","html_url":"https://github.com/mitodl/lore/pull/195#discussion_r32860835","pull_request_url":"https://api.github.com/repos/mitodl/lore/pulls/195","_links":{"self":{"href":"https://api.github.com/repos/mitodl/lore/pulls/comments/32860835"},"html":{"href":"https://github.com/mitodl/lore/pull/195#discussion_r32860835"},"pull_request":{"href":"https://api.github.com/repos/mitodl/lore/pulls/195"}}},"pull_request":{"url":"https://api.github.com/repos/mitodl/lore/pulls/195","id":38058839,"html_url":"https://github.com/mitodl/lore/pull/195","diff_url":"https://github.com/mitodl/lore/pull/195.diff","patch_url":"https://github.com/mitodl/lore/pull/195.patch","issue_url":"https://api.github.com/repos/mitodl/lore/issues/195","number":195,"state":"open","locked":false,"title":"members api #1","user":{"login":"giocalitri","id":1005204,"avatar_url":"https://avatars.githubusercontent.com/u/1005204?v=3","gravatar_id":"","url":"https://api.github.com/users/giocalitri","html_url":"https://github.com/giocalitri","followers_url":"https://api.github.com/users/giocalitri/followers","following_url":"https://api.github.com/users/giocalitri/following{/other_user}","gists_url":"https://api.github.com/users/giocalitri/gists{/gist_id}","starred_url":"https://api.github.com/users/giocalitri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giocalitri/subscriptions","organizations_url":"https://api.github.com/users/giocalitri/orgs","repos_url":"https://api.github.com/users/giocalitri/repos","events_url":"https://api.github.com/users/giocalitri/events{/privacy}","received_events_url":"https://api.github.com/users/giocalitri/received_events","type":"User","site_admin":false},"body":"this is the first part to just add a new permission\r\n\r\nit also handle migrations in the right way and adds a Django Command for syncing permissions","created_at":"2015-06-18T22:12:14Z","updated_at":"2015-06-19T19:24:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ddee5d7672ea270c04851f592f19a23bc7a87fcd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mitodl/lore/pulls/195/commits","review_comments_url":"https://api.github.com/repos/mitodl/lore/pulls/195/comments","review_comment_url":"https://api.github.com/repos/mitodl/lore/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mitodl/lore/issues/195/comments","statuses_url":"https://api.github.com/repos/mitodl/lore/statuses/8c943cd3184f6ce996f9e3cff17757626bf0dcbf","head":{"label":"mitodl:feature/gdm/129_members_api_1","ref":"feature/gdm/129_members_api_1","sha":"8c943cd3184f6ce996f9e3cff17757626bf0dcbf","user":{"login":"mitodl","id":7918516,"avatar_url":"https://avatars.githubusercontent.com/u/7918516?v=3","gravatar_id":"","url":"https://api.github.com/users/mitodl","html_url":"https://github.com/mitodl","followers_url":"https://api.github.com/users/mitodl/followers","following_url":"https://api.github.com/users/mitodl/following{/other_user}","gists_url":"https://api.github.com/users/mitodl/gists{/gist_id}","starred_url":"https://api.github.com/users/mitodl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitodl/subscriptions","organizations_url":"https://api.github.com/users/mitodl/orgs","repos_url":"https://api.github.com/users/mitodl/repos","events_url":"https://api.github.com/users/mitodl/events{/privacy}","received_events_url":"https://api.github.com/users/mitodl/received_events","type":"Organization","site_admin":false},"repo":{"id":34909549,"name":"lore","full_name":"mitodl/lore","owner":{"login":"mitodl","id":7918516,"avatar_url":"https://avatars.githubusercontent.com/u/7918516?v=3","gravatar_id":"","url":"https://api.github.com/users/mitodl","html_url":"https://github.com/mitodl","followers_url":"https://api.github.com/users/mitodl/followers","following_url":"https://api.github.com/users/mitodl/following{/other_user}","gists_url":"https://api.github.com/users/mitodl/gists{/gist_id}","starred_url":"https://api.github.com/users/mitodl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitodl/subscriptions","organizations_url":"https://api.github.com/users/mitodl/orgs","repos_url":"https://api.github.com/users/mitodl/repos","events_url":"https://api.github.com/users/mitodl/events{/privacy}","received_events_url":"https://api.github.com/users/mitodl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mitodl/lore","description":"Learning Object Repository for Education","fork":false,"url":"https://api.github.com/repos/mitodl/lore","forks_url":"https://api.github.com/repos/mitodl/lore/forks","keys_url":"https://api.github.com/repos/mitodl/lore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mitodl/lore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mitodl/lore/teams","hooks_url":"https://api.github.com/repos/mitodl/lore/hooks","issue_events_url":"https://api.github.com/repos/mitodl/lore/issues/events{/number}","events_url":"https://api.github.com/repos/mitodl/lore/events","assignees_url":"https://api.github.com/repos/mitodl/lore/assignees{/user}","branches_url":"https://api.github.com/repos/mitodl/lore/branches{/branch}","tags_url":"https://api.github.com/repos/mitodl/lore/tags","blobs_url":"https://api.github.com/repos/mitodl/lore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mitodl/lore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mitodl/lore/git/refs{/sha}","trees_url":"https://api.github.com/repos/mitodl/lore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mitodl/lore/statuses/{sha}","languages_url":"https://api.github.com/repos/mitodl/lore/languages","stargazers_url":"https://api.github.com/repos/mitodl/lore/stargazers","contributors_url":"https://api.github.com/repos/mitodl/lore/contributors","subscribers_url":"https://api.github.com/repos/mitodl/lore/subscribers","subscription_url":"https://api.github.com/repos/mitodl/lore/subscription","commits_url":"https://api.github.com/repos/mitodl/lore/commits{/sha}","git_commits_url":"https://api.github.com/repos/mitodl/lore/git/commits{/sha}","comments_url":"https://api.github.com/repos/mitodl/lore/comments{/number}","issue_comment_url":"https://api.github.com/repos/mitodl/lore/issues/comments{/number}","contents_url":"https://api.github.com/repos/mitodl/lore/contents/{+path}","compare_url":"https://api.github.com/repos/mitodl/lore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mitodl/lore/merges","archive_url":"https://api.github.com/repos/mitodl/lore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mitodl/lore/downloads","issues_url":"https://api.github.com/repos/mitodl/lore/issues{/number}","pulls_url":"https://api.github.com/repos/mitodl/lore/pulls{/number}","milestones_url":"https://api.github.com/repos/mitodl/lore/milestones{/number}","notifications_url":"https://api.github.com/repos/mitodl/lore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mitodl/lore/labels{/name}","releases_url":"https://api.github.com/repos/mitodl/lore/releases{/id}","created_at":"2015-05-01T15:34:34Z","updated_at":"2015-06-17T02:41:03Z","pushed_at":"2015-06-19T19:14:51Z","git_url":"git://github.com/mitodl/lore.git","ssh_url":"git@github.com:mitodl/lore.git","clone_url":"https://github.com/mitodl/lore.git","svn_url":"https://github.com/mitodl/lore","homepage":"https://goo.gl/nDVx4D","size":5138,"stargazers_count":6,"watchers_count":6,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":53,"forks":2,"open_issues":53,"watchers":6,"default_branch":"master"}},"base":{"label":"mitodl:master","ref":"master","sha":"76a109915a2a5c906829f979b39cde9ce0f02956","user":{"login":"mitodl","id":7918516,"avatar_url":"https://avatars.githubusercontent.com/u/7918516?v=3","gravatar_id":"","url":"https://api.github.com/users/mitodl","html_url":"https://github.com/mitodl","followers_url":"https://api.github.com/users/mitodl/followers","following_url":"https://api.github.com/users/mitodl/following{/other_user}","gists_url":"https://api.github.com/users/mitodl/gists{/gist_id}","starred_url":"https://api.github.com/users/mitodl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitodl/subscriptions","organizations_url":"https://api.github.com/users/mitodl/orgs","repos_url":"https://api.github.com/users/mitodl/repos","events_url":"https://api.github.com/users/mitodl/events{/privacy}","received_events_url":"https://api.github.com/users/mitodl/received_events","type":"Organization","site_admin":false},"repo":{"id":34909549,"name":"lore","full_name":"mitodl/lore","owner":{"login":"mitodl","id":7918516,"avatar_url":"https://avatars.githubusercontent.com/u/7918516?v=3","gravatar_id":"","url":"https://api.github.com/users/mitodl","html_url":"https://github.com/mitodl","followers_url":"https://api.github.com/users/mitodl/followers","following_url":"https://api.github.com/users/mitodl/following{/other_user}","gists_url":"https://api.github.com/users/mitodl/gists{/gist_id}","starred_url":"https://api.github.com/users/mitodl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitodl/subscriptions","organizations_url":"https://api.github.com/users/mitodl/orgs","repos_url":"https://api.github.com/users/mitodl/repos","events_url":"https://api.github.com/users/mitodl/events{/privacy}","received_events_url":"https://api.github.com/users/mitodl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mitodl/lore","description":"Learning Object Repository for Education","fork":false,"url":"https://api.github.com/repos/mitodl/lore","forks_url":"https://api.github.com/repos/mitodl/lore/forks","keys_url":"https://api.github.com/repos/mitodl/lore/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mitodl/lore/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mitodl/lore/teams","hooks_url":"https://api.github.com/repos/mitodl/lore/hooks","issue_events_url":"https://api.github.com/repos/mitodl/lore/issues/events{/number}","events_url":"https://api.github.com/repos/mitodl/lore/events","assignees_url":"https://api.github.com/repos/mitodl/lore/assignees{/user}","branches_url":"https://api.github.com/repos/mitodl/lore/branches{/branch}","tags_url":"https://api.github.com/repos/mitodl/lore/tags","blobs_url":"https://api.github.com/repos/mitodl/lore/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mitodl/lore/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mitodl/lore/git/refs{/sha}","trees_url":"https://api.github.com/repos/mitodl/lore/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mitodl/lore/statuses/{sha}","languages_url":"https://api.github.com/repos/mitodl/lore/languages","stargazers_url":"https://api.github.com/repos/mitodl/lore/stargazers","contributors_url":"https://api.github.com/repos/mitodl/lore/contributors","subscribers_url":"https://api.github.com/repos/mitodl/lore/subscribers","subscription_url":"https://api.github.com/repos/mitodl/lore/subscription","commits_url":"https://api.github.com/repos/mitodl/lore/commits{/sha}","git_commits_url":"https://api.github.com/repos/mitodl/lore/git/commits{/sha}","comments_url":"https://api.github.com/repos/mitodl/lore/comments{/number}","issue_comment_url":"https://api.github.com/repos/mitodl/lore/issues/comments{/number}","contents_url":"https://api.github.com/repos/mitodl/lore/contents/{+path}","compare_url":"https://api.github.com/repos/mitodl/lore/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mitodl/lore/merges","archive_url":"https://api.github.com/repos/mitodl/lore/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mitodl/lore/downloads","issues_url":"https://api.github.com/repos/mitodl/lore/issues{/number}","pulls_url":"https://api.github.com/repos/mitodl/lore/pulls{/number}","milestones_url":"https://api.github.com/repos/mitodl/lore/milestones{/number}","notifications_url":"https://api.github.com/repos/mitodl/lore/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mitodl/lore/labels{/name}","releases_url":"https://api.github.com/repos/mitodl/lore/releases{/id}","created_at":"2015-05-01T15:34:34Z","updated_at":"2015-06-17T02:41:03Z","pushed_at":"2015-06-19T19:14:51Z","git_url":"git://github.com/mitodl/lore.git","ssh_url":"git@github.com:mitodl/lore.git","clone_url":"https://github.com/mitodl/lore.git","svn_url":"https://github.com/mitodl/lore","homepage":"https://goo.gl/nDVx4D","size":5138,"stargazers_count":6,"watchers_count":6,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":53,"forks":2,"open_issues":53,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mitodl/lore/pulls/195"},"html":{"href":"https://github.com/mitodl/lore/pull/195"},"issue":{"href":"https://api.github.com/repos/mitodl/lore/issues/195"},"comments":{"href":"https://api.github.com/repos/mitodl/lore/issues/195/comments"},"review_comments":{"href":"https://api.github.com/repos/mitodl/lore/pulls/195/comments"},"review_comment":{"href":"https://api.github.com/repos/mitodl/lore/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mitodl/lore/pulls/195/commits"},"statuses":{"href":"https://api.github.com/repos/mitodl/lore/statuses/8c943cd3184f6ce996f9e3cff17757626bf0dcbf"}}}}