{"action":"created","comment":{"url":"https://api.github.com/repos/Scalr/revizor-tests/pulls/comments/217061337","pull_request_review_id":154673454,"id":217061337,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNzA2MTMzNw==","diff_hunk":"@@ -0,0 +1,192 @@\n+# coding: utf-8\n+\"\"\"\n+Created on 13.06.18\n+@author: Eugeny Kurkovich\n+\"\"\"\n+\n+import pytest\n+import requests\n+import six\n+\n+from api.utils.helpers import uniq_uuid\n+from api.utils.consts import Platform, BuiltInAutomation, ENV_ID\n+\n+\n+class TestRoles(object):\n+\n+    os_id = \"ubuntu-14-04\"\n+\n+    scope = \"environment\"\n+\n+    env_id = ENV_ID\n+\n+    dev_role_category = 9\n+\n+    @pytest.fixture(autouse=True)\n+    def init_session(self, api):\n+        self.api = api\n+\n+    def create_role(self, os_id, role_category, automation=None):\n+        builtin_automation = automation or BuiltInAutomation.BASE\n+        if isinstance(builtin_automation, six.string_types):\n+            builtin_automation = [builtin_automation]\n+        resp = self.api.create(\n+            \"/api/v1beta0/user/envId/roles/\",\n+            params=dict(envId=self.env_id),\n+            body=dict(\n+                builtinAutomation=builtin_automation,\n+                category={\"id\": role_category},\n+                name=\"tmp-api-%s\" % uniq_uuid(),\n+                os={\"id\": os_id}))\n+        return resp.box_repr.data\n+\n+    def create_role_image(self, role_id, image_id):\n+        resp = self.api.create(\n+            \"/api/v1beta0/user/envId/roles/roleId/images/\",\n+            params=dict(\n+                envId=self.env_id,\n+                roleId=role_id),\n+            body=dict(\n+                image={'id': image_id},\n+                role={'id': role_id}\n+            ))\n+        return resp.box_repr.data\n+\n+    def list_images(self, platform=None, os=None, scope=None, agent_installed=True):\n+        resp = self.api.list(\n+            \"/api/v1beta0/user/envId/images/\",\n+            params=dict(envId=self.env_id),\n+            filters=dict(\n+                cloudPlatform=platform,\n+                os=os,\n+                scalrAgentInstalled=agent_installed,\n+                scope=scope\n+            )\n+        )\n+        return resp.box_repr.data\n+\n+    def list_role_images(self, role_id, image=None, role=None):\n+        resp = self.api.list(\n+            \"/api/v1beta0/user/envId/roles/roleId/images/\",\n+            params=dict(\n+                envId=self.env_id,\n+                roleId=role_id),\n+            filters=dict(\n+                image=image,\n+                role=role)\n+        )\n+        return resp.box_repr.data\n+\n+    def test_create_role_with_image(self):\n+        # Create new role\n+        role = self.create_role(\n+            self.os_id,\n+            self.dev_role_category)\n+        # Find image\n+        images = list(filter(\n+            lambda i:\n+                i.cloudFeatures.virtualization == \"hvm\" and\n+                i.name.startswith(\"mbeh1\") and\n+                i.status == 'active',\n+            self.list_images(\n+                    platform=Platform.EC2,\n+                    os=self.os_id,\n+                    scope=self.scope)))\n+        assert len(images), \"No active images with mbeh1 in name found\"\n+        image_id = images[0].id\n+        # Add image to role\n+        self.create_role_image(role.id, image_id)\n+        # Assert role images\n+        role_images = list(filter(\n+            lambda i:\n+                image_id == i.image.id,\n+            self.list_role_images(role.id)))\n+        assert len(role_images), 'Image was not properly added to role'","path":"api/tests/user/roles/test_roles.py","position":104,"original_position":104,"commit_id":"d1c103966e9bcfc8dac64b2ab903ed49155ee75b","original_commit_id":"d1c103966e9bcfc8dac64b2ab903ed49155ee75b","user":{"login":"gigimon","id":297982,"node_id":"MDQ6VXNlcjI5Nzk4Mg==","avatar_url":"https://avatars2.githubusercontent.com/u/297982?v=4","gravatar_id":"","url":"https://api.github.com/users/gigimon","html_url":"https://github.com/gigimon","followers_url":"https://api.github.com/users/gigimon/followers","following_url":"https://api.github.com/users/gigimon/following{/other_user}","gists_url":"https://api.github.com/users/gigimon/gists{/gist_id}","starred_url":"https://api.github.com/users/gigimon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gigimon/subscriptions","organizations_url":"https://api.github.com/users/gigimon/orgs","repos_url":"https://api.github.com/users/gigimon/repos","events_url":"https://api.github.com/users/gigimon/events{/privacy}","received_events_url":"https://api.github.com/users/gigimon/received_events","type":"User","site_admin":false},"body":"проверки на len должны быть четки, сравнивать с тем количеством, которое должно быть, а не просто, что оно больше 0, либо до/после length сравниваться","created_at":"2018-09-12T14:43:40Z","updated_at":"2018-09-12T14:55:40Z","html_url":"https://github.com/Scalr/revizor-tests/pull/185#discussion_r217061337","pull_request_url":"https://api.github.com/repos/Scalr/revizor-tests/pulls/185","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/Scalr/revizor-tests/pulls/comments/217061337"},"html":{"href":"https://github.com/Scalr/revizor-tests/pull/185#discussion_r217061337"},"pull_request":{"href":"https://api.github.com/repos/Scalr/revizor-tests/pulls/185"}}},"pull_request":{"url":"https://api.github.com/repos/Scalr/revizor-tests/pulls/185","id":193954284,"node_id":"MDExOlB1bGxSZXF1ZXN0MTkzOTU0Mjg0","html_url":"https://github.com/Scalr/revizor-tests/pull/185","diff_url":"https://github.com/Scalr/revizor-tests/pull/185.diff","patch_url":"https://github.com/Scalr/revizor-tests/pull/185.patch","issue_url":"https://api.github.com/repos/Scalr/revizor-tests/issues/185","number":185,"state":"open","locked":false,"title":"REV-407 APIv2 testing framework","user":{"login":"stunko","id":5494706,"node_id":"MDQ6VXNlcjU0OTQ3MDY=","avatar_url":"https://avatars0.githubusercontent.com/u/5494706?v=4","gravatar_id":"","url":"https://api.github.com/users/stunko","html_url":"https://github.com/stunko","followers_url":"https://api.github.com/users/stunko/followers","following_url":"https://api.github.com/users/stunko/following{/other_user}","gists_url":"https://api.github.com/users/stunko/gists{/gist_id}","starred_url":"https://api.github.com/users/stunko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stunko/subscriptions","organizations_url":"https://api.github.com/users/stunko/orgs","repos_url":"https://api.github.com/users/stunko/repos","events_url":"https://api.github.com/users/stunko/events{/privacy}","received_events_url":"https://api.github.com/users/stunko/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-06-11T11:39:41Z","updated_at":"2018-09-12T14:55:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c1f752c2c9dfe8f85ca270a48bb8a31070a8d20b","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Scalr/revizor-tests/pulls/185/commits","review_comments_url":"https://api.github.com/repos/Scalr/revizor-tests/pulls/185/comments","review_comment_url":"https://api.github.com/repos/Scalr/revizor-tests/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Scalr/revizor-tests/issues/185/comments","statuses_url":"https://api.github.com/repos/Scalr/revizor-tests/statuses/d1c103966e9bcfc8dac64b2ab903ed49155ee75b","head":{"label":"Scalr:feature/REV-407","ref":"feature/REV-407","sha":"d1c103966e9bcfc8dac64b2ab903ed49155ee75b","user":{"login":"Scalr","id":899603,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg5OTYwMw==","avatar_url":"https://avatars1.githubusercontent.com/u/899603?v=4","gravatar_id":"","url":"https://api.github.com/users/Scalr","html_url":"https://github.com/Scalr","followers_url":"https://api.github.com/users/Scalr/followers","following_url":"https://api.github.com/users/Scalr/following{/other_user}","gists_url":"https://api.github.com/users/Scalr/gists{/gist_id}","starred_url":"https://api.github.com/users/Scalr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scalr/subscriptions","organizations_url":"https://api.github.com/users/Scalr/orgs","repos_url":"https://api.github.com/users/Scalr/repos","events_url":"https://api.github.com/users/Scalr/events{/privacy}","received_events_url":"https://api.github.com/users/Scalr/received_events","type":"Organization","site_admin":false},"repo":{"id":8455288,"node_id":"MDEwOlJlcG9zaXRvcnk4NDU1Mjg4","name":"revizor-tests","full_name":"Scalr/revizor-tests","owner":{"login":"Scalr","id":899603,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg5OTYwMw==","avatar_url":"https://avatars1.githubusercontent.com/u/899603?v=4","gravatar_id":"","url":"https://api.github.com/users/Scalr","html_url":"https://github.com/Scalr","followers_url":"https://api.github.com/users/Scalr/followers","following_url":"https://api.github.com/users/Scalr/following{/other_user}","gists_url":"https://api.github.com/users/Scalr/gists{/gist_id}","starred_url":"https://api.github.com/users/Scalr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scalr/subscriptions","organizations_url":"https://api.github.com/users/Scalr/orgs","repos_url":"https://api.github.com/users/Scalr/repos","events_url":"https://api.github.com/users/Scalr/events{/privacy}","received_events_url":"https://api.github.com/users/Scalr/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Scalr/revizor-tests","description":null,"fork":false,"url":"https://api.github.com/repos/Scalr/revizor-tests","forks_url":"https://api.github.com/repos/Scalr/revizor-tests/forks","keys_url":"https://api.github.com/repos/Scalr/revizor-tests/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Scalr/revizor-tests/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Scalr/revizor-tests/teams","hooks_url":"https://api.github.com/repos/Scalr/revizor-tests/hooks","issue_events_url":"https://api.github.com/repos/Scalr/revizor-tests/issues/events{/number}","events_url":"https://api.github.com/repos/Scalr/revizor-tests/events","assignees_url":"https://api.github.com/repos/Scalr/revizor-tests/assignees{/user}","branches_url":"https://api.github.com/repos/Scalr/revizor-tests/branches{/branch}","tags_url":"https://api.github.com/repos/Scalr/revizor-tests/tags","blobs_url":"https://api.github.com/repos/Scalr/revizor-tests/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Scalr/revizor-tests/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Scalr/revizor-tests/git/refs{/sha}","trees_url":"https://api.github.com/repos/Scalr/revizor-tests/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Scalr/revizor-tests/statuses/{sha}","languages_url":"https://api.github.com/repos/Scalr/revizor-tests/languages","stargazers_url":"https://api.github.com/repos/Scalr/revizor-tests/stargazers","contributors_url":"https://api.github.com/repos/Scalr/revizor-tests/contributors","subscribers_url":"https://api.github.com/repos/Scalr/revizor-tests/subscribers","subscription_url":"https://api.github.com/repos/Scalr/revizor-tests/subscription","commits_url":"https://api.github.com/repos/Scalr/revizor-tests/commits{/sha}","git_commits_url":"https://api.github.com/repos/Scalr/revizor-tests/git/commits{/sha}","comments_url":"https://api.github.com/repos/Scalr/revizor-tests/comments{/number}","issue_comment_url":"https://api.github.com/repos/Scalr/revizor-tests/issues/comments{/number}","contents_url":"https://api.github.com/repos/Scalr/revizor-tests/contents/{+path}","compare_url":"https://api.github.com/repos/Scalr/revizor-tests/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Scalr/revizor-tests/merges","archive_url":"https://api.github.com/repos/Scalr/revizor-tests/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Scalr/revizor-tests/downloads","issues_url":"https://api.github.com/repos/Scalr/revizor-tests/issues{/number}","pulls_url":"https://api.github.com/repos/Scalr/revizor-tests/pulls{/number}","milestones_url":"https://api.github.com/repos/Scalr/revizor-tests/milestones{/number}","notifications_url":"https://api.github.com/repos/Scalr/revizor-tests/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Scalr/revizor-tests/labels{/name}","releases_url":"https://api.github.com/repos/Scalr/revizor-tests/releases{/id}","deployments_url":"https://api.github.com/repos/Scalr/revizor-tests/deployments","created_at":"2013-02-27T12:15:45Z","updated_at":"2018-08-16T10:46:55Z","pushed_at":"2018-09-12T14:15:23Z","git_url":"git://github.com/Scalr/revizor-tests.git","ssh_url":"git@github.com:Scalr/revizor-tests.git","clone_url":"https://github.com/Scalr/revizor-tests.git","svn_url":"https://github.com/Scalr/revizor-tests","homepage":null,"size":2340,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":6,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":3,"open_issues":6,"watchers":0,"default_branch":"master"}},"base":{"label":"Scalr:master","ref":"master","sha":"52ac578a9c52f1fcfbed690b8a13a27c093a1668","user":{"login":"Scalr","id":899603,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg5OTYwMw==","avatar_url":"https://avatars1.githubusercontent.com/u/899603?v=4","gravatar_id":"","url":"https://api.github.com/users/Scalr","html_url":"https://github.com/Scalr","followers_url":"https://api.github.com/users/Scalr/followers","following_url":"https://api.github.com/users/Scalr/following{/other_user}","gists_url":"https://api.github.com/users/Scalr/gists{/gist_id}","starred_url":"https://api.github.com/users/Scalr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scalr/subscriptions","organizations_url":"https://api.github.com/users/Scalr/orgs","repos_url":"https://api.github.com/users/Scalr/repos","events_url":"https://api.github.com/users/Scalr/events{/privacy}","received_events_url":"https://api.github.com/users/Scalr/received_events","type":"Organization","site_admin":false},"repo":{"id":8455288,"node_id":"MDEwOlJlcG9zaXRvcnk4NDU1Mjg4","name":"revizor-tests","full_name":"Scalr/revizor-tests","owner":{"login":"Scalr","id":899603,"node_id":"MDEyOk9yZ2FuaXphdGlvbjg5OTYwMw==","avatar_url":"https://avatars1.githubusercontent.com/u/899603?v=4","gravatar_id":"","url":"https://api.github.com/users/Scalr","html_url":"https://github.com/Scalr","followers_url":"https://api.github.com/users/Scalr/followers","following_url":"https://api.github.com/users/Scalr/following{/other_user}","gists_url":"https://api.github.com/users/Scalr/gists{/gist_id}","starred_url":"https://api.github.com/users/Scalr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Scalr/subscriptions","organizations_url":"https://api.github.com/users/Scalr/orgs","repos_url":"https://api.github.com/users/Scalr/repos","events_url":"https://api.github.com/users/Scalr/events{/privacy}","received_events_url":"https://api.github.com/users/Scalr/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Scalr/revizor-tests","description":null,"fork":false,"url":"https://api.github.com/repos/Scalr/revizor-tests","forks_url":"https://api.github.com/repos/Scalr/revizor-tests/forks","keys_url":"https://api.github.com/repos/Scalr/revizor-tests/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Scalr/revizor-tests/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Scalr/revizor-tests/teams","hooks_url":"https://api.github.com/repos/Scalr/revizor-tests/hooks","issue_events_url":"https://api.github.com/repos/Scalr/revizor-tests/issues/events{/number}","events_url":"https://api.github.com/repos/Scalr/revizor-tests/events","assignees_url":"https://api.github.com/repos/Scalr/revizor-tests/assignees{/user}","branches_url":"https://api.github.com/repos/Scalr/revizor-tests/branches{/branch}","tags_url":"https://api.github.com/repos/Scalr/revizor-tests/tags","blobs_url":"https://api.github.com/repos/Scalr/revizor-tests/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Scalr/revizor-tests/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Scalr/revizor-tests/git/refs{/sha}","trees_url":"https://api.github.com/repos/Scalr/revizor-tests/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Scalr/revizor-tests/statuses/{sha}","languages_url":"https://api.github.com/repos/Scalr/revizor-tests/languages","stargazers_url":"https://api.github.com/repos/Scalr/revizor-tests/stargazers","contributors_url":"https://api.github.com/repos/Scalr/revizor-tests/contributors","subscribers_url":"https://api.github.com/repos/Scalr/revizor-tests/subscribers","subscription_url":"https://api.github.com/repos/Scalr/revizor-tests/subscription","commits_url":"https://api.github.com/repos/Scalr/revizor-tests/commits{/sha}","git_commits_url":"https://api.github.com/repos/Scalr/revizor-tests/git/commits{/sha}","comments_url":"https://api.github.com/repos/Scalr/revizor-tests/comments{/number}","issue_comment_url":"https://api.github.com/repos/Scalr/revizor-tests/issues/comments{/number}","contents_url":"https://api.github.com/repos/Scalr/revizor-tests/contents/{+path}","compare_url":"https://api.github.com/repos/Scalr/revizor-tests/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Scalr/revizor-tests/merges","archive_url":"https://api.github.com/repos/Scalr/revizor-tests/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Scalr/revizor-tests/downloads","issues_url":"https://api.github.com/repos/Scalr/revizor-tests/issues{/number}","pulls_url":"https://api.github.com/repos/Scalr/revizor-tests/pulls{/number}","milestones_url":"https://api.github.com/repos/Scalr/revizor-tests/milestones{/number}","notifications_url":"https://api.github.com/repos/Scalr/revizor-tests/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Scalr/revizor-tests/labels{/name}","releases_url":"https://api.github.com/repos/Scalr/revizor-tests/releases{/id}","deployments_url":"https://api.github.com/repos/Scalr/revizor-tests/deployments","created_at":"2013-02-27T12:15:45Z","updated_at":"2018-08-16T10:46:55Z","pushed_at":"2018-09-12T14:15:23Z","git_url":"git://github.com/Scalr/revizor-tests.git","ssh_url":"git@github.com:Scalr/revizor-tests.git","clone_url":"https://github.com/Scalr/revizor-tests.git","svn_url":"https://github.com/Scalr/revizor-tests","homepage":null,"size":2340,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"archived":false,"open_issues_count":6,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":3,"open_issues":6,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Scalr/revizor-tests/pulls/185"},"html":{"href":"https://github.com/Scalr/revizor-tests/pull/185"},"issue":{"href":"https://api.github.com/repos/Scalr/revizor-tests/issues/185"},"comments":{"href":"https://api.github.com/repos/Scalr/revizor-tests/issues/185/comments"},"review_comments":{"href":"https://api.github.com/repos/Scalr/revizor-tests/pulls/185/comments"},"review_comment":{"href":"https://api.github.com/repos/Scalr/revizor-tests/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Scalr/revizor-tests/pulls/185/commits"},"statuses":{"href":"https://api.github.com/repos/Scalr/revizor-tests/statuses/d1c103966e9bcfc8dac64b2ab903ed49155ee75b"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"gigimon"}}