{"action":"created","comment":{"url":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/comments/38875503","id":38875503,"diff_hunk":"@@ -374,13 +374,485 @@ def test_vm_add_lifecycle_event(request, setup_a_provider, rest_api, vm, from_de\n }\n \n \n+@pytest.fixture(scope=\"module\")\n+def users_data():\n+    name = fauxfactory.gen_alphanumeric()\n+    result = [{\n+        \"name\": \"name_{}_{}\".format(index, name),\n+        \"userid\": \"userid_{}_{}\".format(index, name),\n+        \"email\": \"{}_{}@local.com\".format(index, name),\n+    } for index in range(1, 5)]\n+\n+    return result\n+\n+\n+@pytest.fixture(scope=\"module\")\n+def groups_data():\n+    name = fauxfactory.gen_alphanumeric()\n+    result = [{\n+        \"description\": \"description_{}_{}\".format(index, name),\n+        \"miq_user_role_id\": index,\n+    } for index in range(1, 5)]\n+\n+    return result\n+\n+\n+@pytest.fixture(scope=\"module\")\n+def roles_data():\n+    name = fauxfactory.gen_alphanumeric()\n+    result = [{\n+        \"name\": \"name_{}_{}\".format(index, name),\n+        \"settings\": {\n+            \"restrictions\": {\n+                \"vms\": \"user\"\n+            },\n+        },\n+    } for index in range(1, 5)]\n+\n+    return result\n+\n+\n+@pytest.fixture(scope=\"module\", params=[\"users\", \"groups\", \"roles\"])\n+def rest_api_access_control(request, rest_api):\n+    if request.param == 'users':\n+        return (request.getfuncargvalue(\"users_data\"), rest_api.collections.users)\n+    elif request.param == 'groups':\n+        return (request.getfuncargvalue(\"groups_data\"), rest_api.collections.groups)\n+    elif request.param == 'roles':\n+        return (request.getfuncargvalue(\"roles_data\"), rest_api.collections.roles)\n+\n+\n+def test_add_delete_access_control(rest_api_access_control):\n+    \"\"\"Tests creating and deleting access control entity: ['users', 'groups', 'roles'].\n+\n+    Prerequisities:\n+        * An appliance with ``/api`` available.\n+\n+    Steps:\n+        * access_control = ['users', 'groups', 'roles']\n+        * POST /api/{access_control} (method ``add``)\n+                for users: ``name``, ```userid`, ``email``\n+                for groups: ``description``, ``miq_user_role_id``\n+                for roles: ``name``, ``settings``\n+        * DELETE /api/{access_control}/<id> -> delete only one entity\n+        * DELETE /api/{access_control} <- Insert a JSON with list of dicts containing ``href``s to\n+            the entity\n+        * Repeat the DELETE query -> now it should return an ``ActiveRecord::RecordNotFound``.\n+\n+    Metadata:\n+        test_flag: rest\n+    \"\"\"\n+    entities, api = rest_api_access_control\n+    assert \"add\" in api.action and \"delete\" in api.action\n+\n+    for entity in entities:\n+        api.action.add(entity)\n+\n+        wait_for(\n+            lambda: api.find_by(name=entity.get(\"name\")),\n+            num_sec=180,\n+            delay=10,\n+        )\n+\n+    delete_entity = api.find_by(entities[0].get('name'))\n+    delete_entity.action.delete()\n+    wait_for(\n+        lambda: not api.find_by(name=entities[0].get('name')),\n+        num_sec=180,\n+        delay=10,\n+    )\n+\n+    entities = [entity.id for entity in api]\n+    api.delete(entities)\n+    with error.expected(\"ActiveRecord::RecordNotFound\"):\n+        api.action.delete(entities)\n+\n+\n+def test_edit_access_control(rest_api_access_control):\n+    \"\"\"Tests editing a access_control entity: ['user', 'group', 'role'].\n+\n+    Prerequisities:\n+        * An appliance with ``/api`` available.\n+\n+    Steps:\n+        * access_control = ['users', 'groups', 'roles']\n+        * Retrieve list of entities using GET /api/{access_control} , pick the first one\n+        * POST /api/{access_control}/<id> (method ``edit``) with the ``name``\n+\n+    Metadata:\n+        test_flag: rest\n+    \"\"\"\n+    entities, api = rest_api_access_control\n+    assert \"edit\" in api.action\n+\n+    try:\n+        entity = api[0]\n+    except:\n+        api.action.add(entities[0])\n+        entity = api.find_by(name=(entities[0].get('name') or entities[0].get('description')))\n+\n+    new_name = \"name_{}\".format(fauxfactory.gen_alphanumeric())\n+\n+    entity.action.edit(name=new_name)\n+    wait_for(\n+        lambda: api.find_by(name=new_name),\n+        num_sec=180,\n+        delay=10,\n+    )\n+\n+\n+@pytest.fixture(scope=\"module\")\n+def policies_data():\n+    name = fauxfactory.gen_alphanumeric()\n+    result = [{\n+        \"description\": \"description_{}_{}\".format(index, name),\n+        \"mode\": \"compliance\",\n+        \"towhat\": \"Vm\",\n+    } for index in range(1, 5)]\n+\n+    return result","path":"cfme/tests/test_rest.py","position":140,"original_position":140,"commit_id":"83aa9cf7158e43ae0e08cdbce28692f76e4a7445","original_commit_id":"83aa9cf7158e43ae0e08cdbce28692f76e4a7445","user":{"login":"lehinevych","id":4303438,"avatar_url":"https://avatars.githubusercontent.com/u/4303438?v=3","gravatar_id":"","url":"https://api.github.com/users/lehinevych","html_url":"https://github.com/lehinevych","followers_url":"https://api.github.com/users/lehinevych/followers","following_url":"https://api.github.com/users/lehinevych/following{/other_user}","gists_url":"https://api.github.com/users/lehinevych/gists{/gist_id}","starred_url":"https://api.github.com/users/lehinevych/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lehinevych/subscriptions","organizations_url":"https://api.github.com/users/lehinevych/orgs","repos_url":"https://api.github.com/users/lehinevych/repos","events_url":"https://api.github.com/users/lehinevych/events{/privacy}","received_events_url":"https://api.github.com/users/lehinevych/received_events","type":"User","site_admin":false},"body":"Agree, renamed.","created_at":"2015-09-07T17:53:02Z","updated_at":"2015-09-07T17:53:02Z","html_url":"https://github.com/RedHatQE/cfme_tests/pull/2226#discussion_r38875503","pull_request_url":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/2226","_links":{"self":{"href":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/comments/38875503"},"html":{"href":"https://github.com/RedHatQE/cfme_tests/pull/2226#discussion_r38875503"},"pull_request":{"href":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/2226"}}},"pull_request":{"url":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/2226","id":44125976,"html_url":"https://github.com/RedHatQE/cfme_tests/pull/2226","diff_url":"https://github.com/RedHatQE/cfme_tests/pull/2226.diff","patch_url":"https://github.com/RedHatQE/cfme_tests/pull/2226.patch","issue_url":"https://api.github.com/repos/RedHatQE/cfme_tests/issues/2226","number":2226,"state":"open","locked":false,"title":"Add REST API tests","user":{"login":"lehinevych","id":4303438,"avatar_url":"https://avatars.githubusercontent.com/u/4303438?v=3","gravatar_id":"","url":"https://api.github.com/users/lehinevych","html_url":"https://github.com/lehinevych","followers_url":"https://api.github.com/users/lehinevych/followers","following_url":"https://api.github.com/users/lehinevych/following{/other_user}","gists_url":"https://api.github.com/users/lehinevych/gists{/gist_id}","starred_url":"https://api.github.com/users/lehinevych/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lehinevych/subscriptions","organizations_url":"https://api.github.com/users/lehinevych/orgs","repos_url":"https://api.github.com/users/lehinevych/repos","events_url":"https://api.github.com/users/lehinevych/events{/privacy}","received_events_url":"https://api.github.com/users/lehinevych/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-03T16:07:14Z","updated_at":"2015-09-07T17:53:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"65bc582ffb9c85529ba0c8808e65be4bdb6024de","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/2226/commits","review_comments_url":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/2226/comments","review_comment_url":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RedHatQE/cfme_tests/issues/2226/comments","statuses_url":"https://api.github.com/repos/RedHatQE/cfme_tests/statuses/83aa9cf7158e43ae0e08cdbce28692f76e4a7445","head":{"label":"lehinevych:rest_api_tests","ref":"rest_api_tests","sha":"83aa9cf7158e43ae0e08cdbce28692f76e4a7445","user":{"login":"lehinevych","id":4303438,"avatar_url":"https://avatars.githubusercontent.com/u/4303438?v=3","gravatar_id":"","url":"https://api.github.com/users/lehinevych","html_url":"https://github.com/lehinevych","followers_url":"https://api.github.com/users/lehinevych/followers","following_url":"https://api.github.com/users/lehinevych/following{/other_user}","gists_url":"https://api.github.com/users/lehinevych/gists{/gist_id}","starred_url":"https://api.github.com/users/lehinevych/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lehinevych/subscriptions","organizations_url":"https://api.github.com/users/lehinevych/orgs","repos_url":"https://api.github.com/users/lehinevych/repos","events_url":"https://api.github.com/users/lehinevych/events{/privacy}","received_events_url":"https://api.github.com/users/lehinevych/received_events","type":"User","site_admin":false},"repo":{"id":40972158,"name":"cfme_tests","full_name":"lehinevych/cfme_tests","owner":{"login":"lehinevych","id":4303438,"avatar_url":"https://avatars.githubusercontent.com/u/4303438?v=3","gravatar_id":"","url":"https://api.github.com/users/lehinevych","html_url":"https://github.com/lehinevych","followers_url":"https://api.github.com/users/lehinevych/followers","following_url":"https://api.github.com/users/lehinevych/following{/other_user}","gists_url":"https://api.github.com/users/lehinevych/gists{/gist_id}","starred_url":"https://api.github.com/users/lehinevych/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lehinevych/subscriptions","organizations_url":"https://api.github.com/users/lehinevych/orgs","repos_url":"https://api.github.com/users/lehinevych/repos","events_url":"https://api.github.com/users/lehinevych/events{/privacy}","received_events_url":"https://api.github.com/users/lehinevych/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lehinevych/cfme_tests","description":"CloudForms Management Engine - Functional tests","fork":true,"url":"https://api.github.com/repos/lehinevych/cfme_tests","forks_url":"https://api.github.com/repos/lehinevych/cfme_tests/forks","keys_url":"https://api.github.com/repos/lehinevych/cfme_tests/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lehinevych/cfme_tests/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lehinevych/cfme_tests/teams","hooks_url":"https://api.github.com/repos/lehinevych/cfme_tests/hooks","issue_events_url":"https://api.github.com/repos/lehinevych/cfme_tests/issues/events{/number}","events_url":"https://api.github.com/repos/lehinevych/cfme_tests/events","assignees_url":"https://api.github.com/repos/lehinevych/cfme_tests/assignees{/user}","branches_url":"https://api.github.com/repos/lehinevych/cfme_tests/branches{/branch}","tags_url":"https://api.github.com/repos/lehinevych/cfme_tests/tags","blobs_url":"https://api.github.com/repos/lehinevych/cfme_tests/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lehinevych/cfme_tests/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lehinevych/cfme_tests/git/refs{/sha}","trees_url":"https://api.github.com/repos/lehinevych/cfme_tests/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lehinevych/cfme_tests/statuses/{sha}","languages_url":"https://api.github.com/repos/lehinevych/cfme_tests/languages","stargazers_url":"https://api.github.com/repos/lehinevych/cfme_tests/stargazers","contributors_url":"https://api.github.com/repos/lehinevych/cfme_tests/contributors","subscribers_url":"https://api.github.com/repos/lehinevych/cfme_tests/subscribers","subscription_url":"https://api.github.com/repos/lehinevych/cfme_tests/subscription","commits_url":"https://api.github.com/repos/lehinevych/cfme_tests/commits{/sha}","git_commits_url":"https://api.github.com/repos/lehinevych/cfme_tests/git/commits{/sha}","comments_url":"https://api.github.com/repos/lehinevych/cfme_tests/comments{/number}","issue_comment_url":"https://api.github.com/repos/lehinevych/cfme_tests/issues/comments{/number}","contents_url":"https://api.github.com/repos/lehinevych/cfme_tests/contents/{+path}","compare_url":"https://api.github.com/repos/lehinevych/cfme_tests/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lehinevych/cfme_tests/merges","archive_url":"https://api.github.com/repos/lehinevych/cfme_tests/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lehinevych/cfme_tests/downloads","issues_url":"https://api.github.com/repos/lehinevych/cfme_tests/issues{/number}","pulls_url":"https://api.github.com/repos/lehinevych/cfme_tests/pulls{/number}","milestones_url":"https://api.github.com/repos/lehinevych/cfme_tests/milestones{/number}","notifications_url":"https://api.github.com/repos/lehinevych/cfme_tests/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lehinevych/cfme_tests/labels{/name}","releases_url":"https://api.github.com/repos/lehinevych/cfme_tests/releases{/id}","created_at":"2015-08-18T13:00:57Z","updated_at":"2015-08-18T13:01:00Z","pushed_at":"2015-09-07T15:06:32Z","git_url":"git://github.com/lehinevych/cfme_tests.git","ssh_url":"git@github.com:lehinevych/cfme_tests.git","clone_url":"https://github.com/lehinevych/cfme_tests.git","svn_url":"https://github.com/lehinevych/cfme_tests","homepage":"","size":7502,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"RedHatQE:master","ref":"master","sha":"eaccabdfa533944e2e757933ba5898dfaba760b6","user":{"login":"RedHatQE","id":534870,"avatar_url":"https://avatars.githubusercontent.com/u/534870?v=3","gravatar_id":"","url":"https://api.github.com/users/RedHatQE","html_url":"https://github.com/RedHatQE","followers_url":"https://api.github.com/users/RedHatQE/followers","following_url":"https://api.github.com/users/RedHatQE/following{/other_user}","gists_url":"https://api.github.com/users/RedHatQE/gists{/gist_id}","starred_url":"https://api.github.com/users/RedHatQE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RedHatQE/subscriptions","organizations_url":"https://api.github.com/users/RedHatQE/orgs","repos_url":"https://api.github.com/users/RedHatQE/repos","events_url":"https://api.github.com/users/RedHatQE/events{/privacy}","received_events_url":"https://api.github.com/users/RedHatQE/received_events","type":"Organization","site_admin":false},"repo":{"id":8061086,"name":"cfme_tests","full_name":"RedHatQE/cfme_tests","owner":{"login":"RedHatQE","id":534870,"avatar_url":"https://avatars.githubusercontent.com/u/534870?v=3","gravatar_id":"","url":"https://api.github.com/users/RedHatQE","html_url":"https://github.com/RedHatQE","followers_url":"https://api.github.com/users/RedHatQE/followers","following_url":"https://api.github.com/users/RedHatQE/following{/other_user}","gists_url":"https://api.github.com/users/RedHatQE/gists{/gist_id}","starred_url":"https://api.github.com/users/RedHatQE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RedHatQE/subscriptions","organizations_url":"https://api.github.com/users/RedHatQE/orgs","repos_url":"https://api.github.com/users/RedHatQE/repos","events_url":"https://api.github.com/users/RedHatQE/events{/privacy}","received_events_url":"https://api.github.com/users/RedHatQE/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/RedHatQE/cfme_tests","description":"CloudForms Management Engine - Functional tests","fork":false,"url":"https://api.github.com/repos/RedHatQE/cfme_tests","forks_url":"https://api.github.com/repos/RedHatQE/cfme_tests/forks","keys_url":"https://api.github.com/repos/RedHatQE/cfme_tests/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RedHatQE/cfme_tests/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RedHatQE/cfme_tests/teams","hooks_url":"https://api.github.com/repos/RedHatQE/cfme_tests/hooks","issue_events_url":"https://api.github.com/repos/RedHatQE/cfme_tests/issues/events{/number}","events_url":"https://api.github.com/repos/RedHatQE/cfme_tests/events","assignees_url":"https://api.github.com/repos/RedHatQE/cfme_tests/assignees{/user}","branches_url":"https://api.github.com/repos/RedHatQE/cfme_tests/branches{/branch}","tags_url":"https://api.github.com/repos/RedHatQE/cfme_tests/tags","blobs_url":"https://api.github.com/repos/RedHatQE/cfme_tests/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RedHatQE/cfme_tests/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RedHatQE/cfme_tests/git/refs{/sha}","trees_url":"https://api.github.com/repos/RedHatQE/cfme_tests/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RedHatQE/cfme_tests/statuses/{sha}","languages_url":"https://api.github.com/repos/RedHatQE/cfme_tests/languages","stargazers_url":"https://api.github.com/repos/RedHatQE/cfme_tests/stargazers","contributors_url":"https://api.github.com/repos/RedHatQE/cfme_tests/contributors","subscribers_url":"https://api.github.com/repos/RedHatQE/cfme_tests/subscribers","subscription_url":"https://api.github.com/repos/RedHatQE/cfme_tests/subscription","commits_url":"https://api.github.com/repos/RedHatQE/cfme_tests/commits{/sha}","git_commits_url":"https://api.github.com/repos/RedHatQE/cfme_tests/git/commits{/sha}","comments_url":"https://api.github.com/repos/RedHatQE/cfme_tests/comments{/number}","issue_comment_url":"https://api.github.com/repos/RedHatQE/cfme_tests/issues/comments{/number}","contents_url":"https://api.github.com/repos/RedHatQE/cfme_tests/contents/{+path}","compare_url":"https://api.github.com/repos/RedHatQE/cfme_tests/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RedHatQE/cfme_tests/merges","archive_url":"https://api.github.com/repos/RedHatQE/cfme_tests/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RedHatQE/cfme_tests/downloads","issues_url":"https://api.github.com/repos/RedHatQE/cfme_tests/issues{/number}","pulls_url":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls{/number}","milestones_url":"https://api.github.com/repos/RedHatQE/cfme_tests/milestones{/number}","notifications_url":"https://api.github.com/repos/RedHatQE/cfme_tests/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RedHatQE/cfme_tests/labels{/name}","releases_url":"https://api.github.com/repos/RedHatQE/cfme_tests/releases{/id}","created_at":"2013-02-06T21:59:17Z","updated_at":"2015-08-04T18:58:52Z","pushed_at":"2015-09-07T15:06:32Z","git_url":"git://github.com/RedHatQE/cfme_tests.git","ssh_url":"git@github.com:RedHatQE/cfme_tests.git","clone_url":"https://github.com/RedHatQE/cfme_tests.git","svn_url":"https://github.com/RedHatQE/cfme_tests","homepage":"","size":28199,"stargazers_count":12,"watchers_count":12,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":27,"mirror_url":null,"open_issues_count":68,"forks":27,"open_issues":68,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/2226"},"html":{"href":"https://github.com/RedHatQE/cfme_tests/pull/2226"},"issue":{"href":"https://api.github.com/repos/RedHatQE/cfme_tests/issues/2226"},"comments":{"href":"https://api.github.com/repos/RedHatQE/cfme_tests/issues/2226/comments"},"review_comments":{"href":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/2226/comments"},"review_comment":{"href":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RedHatQE/cfme_tests/pulls/2226/commits"},"statuses":{"href":"https://api.github.com/repos/RedHatQE/cfme_tests/statuses/83aa9cf7158e43ae0e08cdbce28692f76e4a7445"}}}}