{"action":"created","comment":{"url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls/comments/86139979","pull_request_review_id":6805312,"id":86139979,"diff_hunk":"@@ -0,0 +1,162 @@\n+# -*- coding: utf-8 -*-\n+import pytest\n+from mock import Mock\n+\n+from ansible.module_utils.basic import AnsibleModule\n+\n+from miqclient.api import API\n+import manageiq_custom_attributes\n+\n+\n+MANAGEIQ_HOSTNAME = \"http://miq.example.com\"\n+PROVIDER_NAME = \"openshift01\"\n+PROVIDER_HOSTNAME = \"os01.example.com\"\n+PROVIDER_ID = 266\n+EXISTING_CA = {\"id\": 6226, \"name\": \"ca1\", \"value\": \"value 1\"}\n+NEW_CA = {\"id\": 6227, \"name\": \"ca2\", \"value\": \"value 2\"}\n+UPDATED_CA_VALUE = \"new value\"\n+\n+\n+GET_RETURN_VALUES = {\n+    'no_cas': {},\n+    'ca_exist': {\n+        \"custom_attributes\": [{\n+            \"href\": \"{miq_hostname}/api/providers/{provider_id}/custom_attributes/{ca_id}\".format(miq_hostname=MANAGEIQ_HOSTNAME, provider_id=PROVIDER_ID, ca_id=EXISTING_CA['id']),\n+            \"id\": EXISTING_CA['id'],\n+            \"section\": \"metadata\",\n+            \"name\": EXISTING_CA['name'],\n+            \"value\": EXISTING_CA['value'],\n+            \"resource_type\": \"ExtManagementSystem\",\n+            \"resource_id\": PROVIDER_ID,\n+            \"source\": \"EVM\",\n+            \"serialized_value\": EXISTING_CA['value']\n+        }]\n+    }\n+}\n+POST_RETURN_VALUES = {\n+    'added_ca': {\n+        'results': [{\n+            \"resource_id\": PROVIDER_ID,\n+            \"section\": \"metadata\",\n+            \"name\": NEW_CA['name'],\n+            \"id\": NEW_CA['id'],\n+            \"serialized_value\": NEW_CA['value'],\n+            \"value\": NEW_CA['value'],\n+            \"resource_type\": \"ExtManagementSystem\",\n+            \"source\": \"EVM\"\n+        }]\n+    },\n+    'updated_ca': {\n+        'results': [{\n+            \"resource_id\": PROVIDER_ID,\n+            \"section\": \"metadata\",\n+            \"name\": EXISTING_CA['name'],\n+            \"id\": EXISTING_CA['id'],\n+            \"serialized_value\": UPDATED_CA_VALUE,\n+            \"value\": UPDATED_CA_VALUE,\n+            \"resource_type\": \"ExtManagementSystem\",\n+            \"source\": \"EVM\"\n+        }]\n+    }\n+}\n+\n+\n+@pytest.fixture(autouse=True)\n+def miq_api_class(monkeypatch):\n+    miq_api_class = Mock(spec=API)\n+    monkeypatch.setattr(\"manageiq_custom_attributes.MiqApi\", miq_api_class)\n+    yield miq_api_class\n+\n+\n+@pytest.fixture\n+def the_provider():\n+    the_provider = Mock()\n+    the_provider.name = PROVIDER_NAME\n+    yield the_provider\n+\n+\n+@pytest.fixture\n+def miq_ansible_module():\n+    miq_ansible_module = Mock(spec=AnsibleModule)\n+    yield miq_ansible_module\n+\n+\n+class AnsibleModuleFailed(Exception):\n+    pass\n+\n+\n+@pytest.fixture()\n+def miq(miq_api_class, miq_ansible_module, the_provider):\n+    # miq_ansible_module.params = {'metrics': True}\n+\n+    def fail(msg):\n+        raise AnsibleModuleFailed(msg)\n+\n+    miq_ansible_module.fail_json = fail\n+    miq = manageiq_custom_attributes.ManageIQ(miq_ansible_module, MANAGEIQ_HOSTNAME,\n+                                              \"The username\", \"The password\")\n+\n+    miq_api_class.return_value.collections.providers = [the_provider]\n+\n+    yield miq\n+\n+\n+def test_get_entity_cas(miq, miq_api_class):\n+    miq_api_class.return_value.get.return_value = GET_RETURN_VALUES['ca_exist']\n+    provider_cas = miq.get_entity_cas('provider', PROVIDER_ID)\n+    assert provider_cas == [{\n+      \"href\": \"http://miq.example.com/api/providers/266/custom_attributes/6226\",\n+      \"id\": 6226,\n+      \"section\": \"metadata\",\n+      \"name\": \"ca1\",\n+      \"value\": \"value 1\",\n+      \"resource_type\": \"ExtManagementSystem\",\n+      \"resource_id\": 266,\n+      \"source\": \"EVM\",\n+      \"serialized_value\": \"value 1\"\n+    }]","path":"tests/test_custom_attributes.py","position":117,"original_position":117,"commit_id":"4923a419c63345513c42ac96ad901441108ecdd6","original_commit_id":"4923a419c63345513c42ac96ad901441108ecdd6","user":{"login":"enoodle","id":3123328,"avatar_url":"https://avatars.githubusercontent.com/u/3123328?v=3","gravatar_id":"","url":"https://api.github.com/users/enoodle","html_url":"https://github.com/enoodle","followers_url":"https://api.github.com/users/enoodle/followers","following_url":"https://api.github.com/users/enoodle/following{/other_user}","gists_url":"https://api.github.com/users/enoodle/gists{/gist_id}","starred_url":"https://api.github.com/users/enoodle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enoodle/subscriptions","organizations_url":"https://api.github.com/users/enoodle/orgs","repos_url":"https://api.github.com/users/enoodle/repos","events_url":"https://api.github.com/users/enoodle/events{/privacy}","received_events_url":"https://api.github.com/users/enoodle/received_events","type":"User","site_admin":false},"body":"I might be wrong because I am not used to pytest but won't it be easier and more clear to compare to `GET_RETURN_VALUES['ca_exist']`?","created_at":"2016-11-02T13:28:54Z","updated_at":"2016-11-02T13:30:03Z","html_url":"https://github.com/dkorn/manageiq-ansible-module/pull/27#discussion_r86139979","pull_request_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls/27","_links":{"self":{"href":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls/comments/86139979"},"html":{"href":"https://github.com/dkorn/manageiq-ansible-module/pull/27#discussion_r86139979"},"pull_request":{"href":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls/27"}}},"pull_request":{"url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls/27","id":91514539,"html_url":"https://github.com/dkorn/manageiq-ansible-module/pull/27","diff_url":"https://github.com/dkorn/manageiq-ansible-module/pull/27.diff","patch_url":"https://github.com/dkorn/manageiq-ansible-module/pull/27.patch","issue_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/issues/27","number":27,"state":"open","locked":false,"title":"ManageIQ Custom Attributes module","user":{"login":"dkorn","id":6347577,"avatar_url":"https://avatars.githubusercontent.com/u/6347577?v=3","gravatar_id":"","url":"https://api.github.com/users/dkorn","html_url":"https://github.com/dkorn","followers_url":"https://api.github.com/users/dkorn/followers","following_url":"https://api.github.com/users/dkorn/following{/other_user}","gists_url":"https://api.github.com/users/dkorn/gists{/gist_id}","starred_url":"https://api.github.com/users/dkorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkorn/subscriptions","organizations_url":"https://api.github.com/users/dkorn/orgs","repos_url":"https://api.github.com/users/dkorn/repos","events_url":"https://api.github.com/users/dkorn/events{/privacy}","received_events_url":"https://api.github.com/users/dkorn/received_events","type":"User","site_admin":false},"body":"@cben @enoodle @kwoodson @twiest @jaryn @simon3z please review","created_at":"2016-10-30T08:10:35Z","updated_at":"2016-11-02T13:30:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4458d825dc7f4ddd1d2383e7a6db1ed482ea4216","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls/27/commits","review_comments_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls/27/comments","review_comment_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/issues/27/comments","statuses_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/statuses/4923a419c63345513c42ac96ad901441108ecdd6","head":{"label":"dkorn:manageiq_custom_attributes","ref":"manageiq_custom_attributes","sha":"4923a419c63345513c42ac96ad901441108ecdd6","user":{"login":"dkorn","id":6347577,"avatar_url":"https://avatars.githubusercontent.com/u/6347577?v=3","gravatar_id":"","url":"https://api.github.com/users/dkorn","html_url":"https://github.com/dkorn","followers_url":"https://api.github.com/users/dkorn/followers","following_url":"https://api.github.com/users/dkorn/following{/other_user}","gists_url":"https://api.github.com/users/dkorn/gists{/gist_id}","starred_url":"https://api.github.com/users/dkorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkorn/subscriptions","organizations_url":"https://api.github.com/users/dkorn/orgs","repos_url":"https://api.github.com/users/dkorn/repos","events_url":"https://api.github.com/users/dkorn/events{/privacy}","received_events_url":"https://api.github.com/users/dkorn/received_events","type":"User","site_admin":false},"repo":{"id":66349774,"name":"manageiq-ansible-module","full_name":"dkorn/manageiq-ansible-module","owner":{"login":"dkorn","id":6347577,"avatar_url":"https://avatars.githubusercontent.com/u/6347577?v=3","gravatar_id":"","url":"https://api.github.com/users/dkorn","html_url":"https://github.com/dkorn","followers_url":"https://api.github.com/users/dkorn/followers","following_url":"https://api.github.com/users/dkorn/following{/other_user}","gists_url":"https://api.github.com/users/dkorn/gists{/gist_id}","starred_url":"https://api.github.com/users/dkorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkorn/subscriptions","organizations_url":"https://api.github.com/users/dkorn/orgs","repos_url":"https://api.github.com/users/dkorn/repos","events_url":"https://api.github.com/users/dkorn/events{/privacy}","received_events_url":"https://api.github.com/users/dkorn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dkorn/manageiq-ansible-module","description":"ManageIQ Ansible Module","fork":false,"url":"https://api.github.com/repos/dkorn/manageiq-ansible-module","forks_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/forks","keys_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/teams","hooks_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/hooks","issue_events_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/issues/events{/number}","events_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/events","assignees_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/assignees{/user}","branches_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/branches{/branch}","tags_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/tags","blobs_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/git/refs{/sha}","trees_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/statuses/{sha}","languages_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/languages","stargazers_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/stargazers","contributors_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/contributors","subscribers_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/subscribers","subscription_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/subscription","commits_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/commits{/sha}","git_commits_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/git/commits{/sha}","comments_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/comments{/number}","issue_comment_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/issues/comments{/number}","contents_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/contents/{+path}","compare_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/merges","archive_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/downloads","issues_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/issues{/number}","pulls_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls{/number}","milestones_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/milestones{/number}","notifications_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/labels{/name}","releases_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/releases{/id}","deployments_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/deployments","created_at":"2016-08-23T08:44:20Z","updated_at":"2016-10-10T07:43:33Z","pushed_at":"2016-11-02T12:05:17Z","git_url":"git://github.com/dkorn/manageiq-ansible-module.git","ssh_url":"git@github.com:dkorn/manageiq-ansible-module.git","clone_url":"https://github.com/dkorn/manageiq-ansible-module.git","svn_url":"https://github.com/dkorn/manageiq-ansible-module","homepage":"","size":59,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":9,"forks":5,"open_issues":9,"watchers":5,"default_branch":"master"}},"base":{"label":"dkorn:master","ref":"master","sha":"e66958f3e9cc16e44bff6795c9912fcf1c61b34b","user":{"login":"dkorn","id":6347577,"avatar_url":"https://avatars.githubusercontent.com/u/6347577?v=3","gravatar_id":"","url":"https://api.github.com/users/dkorn","html_url":"https://github.com/dkorn","followers_url":"https://api.github.com/users/dkorn/followers","following_url":"https://api.github.com/users/dkorn/following{/other_user}","gists_url":"https://api.github.com/users/dkorn/gists{/gist_id}","starred_url":"https://api.github.com/users/dkorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkorn/subscriptions","organizations_url":"https://api.github.com/users/dkorn/orgs","repos_url":"https://api.github.com/users/dkorn/repos","events_url":"https://api.github.com/users/dkorn/events{/privacy}","received_events_url":"https://api.github.com/users/dkorn/received_events","type":"User","site_admin":false},"repo":{"id":66349774,"name":"manageiq-ansible-module","full_name":"dkorn/manageiq-ansible-module","owner":{"login":"dkorn","id":6347577,"avatar_url":"https://avatars.githubusercontent.com/u/6347577?v=3","gravatar_id":"","url":"https://api.github.com/users/dkorn","html_url":"https://github.com/dkorn","followers_url":"https://api.github.com/users/dkorn/followers","following_url":"https://api.github.com/users/dkorn/following{/other_user}","gists_url":"https://api.github.com/users/dkorn/gists{/gist_id}","starred_url":"https://api.github.com/users/dkorn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dkorn/subscriptions","organizations_url":"https://api.github.com/users/dkorn/orgs","repos_url":"https://api.github.com/users/dkorn/repos","events_url":"https://api.github.com/users/dkorn/events{/privacy}","received_events_url":"https://api.github.com/users/dkorn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dkorn/manageiq-ansible-module","description":"ManageIQ Ansible Module","fork":false,"url":"https://api.github.com/repos/dkorn/manageiq-ansible-module","forks_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/forks","keys_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/teams","hooks_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/hooks","issue_events_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/issues/events{/number}","events_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/events","assignees_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/assignees{/user}","branches_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/branches{/branch}","tags_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/tags","blobs_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/git/refs{/sha}","trees_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/statuses/{sha}","languages_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/languages","stargazers_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/stargazers","contributors_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/contributors","subscribers_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/subscribers","subscription_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/subscription","commits_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/commits{/sha}","git_commits_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/git/commits{/sha}","comments_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/comments{/number}","issue_comment_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/issues/comments{/number}","contents_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/contents/{+path}","compare_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/merges","archive_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/downloads","issues_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/issues{/number}","pulls_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls{/number}","milestones_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/milestones{/number}","notifications_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/labels{/name}","releases_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/releases{/id}","deployments_url":"https://api.github.com/repos/dkorn/manageiq-ansible-module/deployments","created_at":"2016-08-23T08:44:20Z","updated_at":"2016-10-10T07:43:33Z","pushed_at":"2016-11-02T12:05:17Z","git_url":"git://github.com/dkorn/manageiq-ansible-module.git","ssh_url":"git@github.com:dkorn/manageiq-ansible-module.git","clone_url":"https://github.com/dkorn/manageiq-ansible-module.git","svn_url":"https://github.com/dkorn/manageiq-ansible-module","homepage":"","size":59,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":9,"forks":5,"open_issues":9,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls/27"},"html":{"href":"https://github.com/dkorn/manageiq-ansible-module/pull/27"},"issue":{"href":"https://api.github.com/repos/dkorn/manageiq-ansible-module/issues/27"},"comments":{"href":"https://api.github.com/repos/dkorn/manageiq-ansible-module/issues/27/comments"},"review_comments":{"href":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls/27/comments"},"review_comment":{"href":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dkorn/manageiq-ansible-module/pulls/27/commits"},"statuses":{"href":"https://api.github.com/repos/dkorn/manageiq-ansible-module/statuses/4923a419c63345513c42ac96ad901441108ecdd6"}}}}
{"actor":{"display_login":"enoodle"}}