|
|
4a6a6ca |
From 4a407ade9f00d9731df1b588d120b1634f07af4c Mon Sep 17 00:00:00 2001
|
|
|
4a6a6ca |
From: Toshio Kuratomi <a.badger@gmail.com>
|
|
|
4a6a6ca |
Date: Tue, 19 Sep 2017 11:51:07 -0700
|
|
|
4a6a6ca |
Subject: [PATCH] Fix jenkins_plugin test for no net situations
|
|
|
4a6a6ca |
|
|
|
4a6a6ca |
Unittests are sometimes run without network connectivity in build
|
|
|
4a6a6ca |
systems. Make that work correctly by mocking out _get_url_data with the
|
|
|
4a6a6ca |
expected return value.
|
|
|
4a6a6ca |
---
|
|
|
4a6a6ca |
.../web_infrastructure/test_jenkins_plugin.py | 127 ++++++++++++++++++++-
|
|
|
4a6a6ca |
1 file changed, 122 insertions(+), 5 deletions(-)
|
|
|
4a6a6ca |
|
|
|
4a6a6ca |
diff --git a/test/units/modules/web_infrastructure/test_jenkins_plugin.py b/test/units/modules/web_infrastructure/test_jenkins_plugin.py
|
|
|
4a6a6ca |
index c7955b684f1d0..ea3adce478745 100644
|
|
|
4a6a6ca |
--- a/test/units/modules/web_infrastructure/test_jenkins_plugin.py
|
|
|
4a6a6ca |
+++ b/test/units/modules/web_infrastructure/test_jenkins_plugin.py
|
|
|
4a6a6ca |
@@ -1,5 +1,5 @@
|
|
|
4a6a6ca |
import collections
|
|
|
4a6a6ca |
-import mock
|
|
|
4a6a6ca |
+from io import BytesIO
|
|
|
4a6a6ca |
|
|
|
4a6a6ca |
from ansible.modules.web_infrastructure.jenkins_plugin import JenkinsPlugin
|
|
|
4a6a6ca |
|
|
|
4a6a6ca |
@@ -8,24 +8,141 @@ def pass_function(*args, **kwargs):
|
|
|
4a6a6ca |
pass
|
|
|
4a6a6ca |
|
|
|
4a6a6ca |
|
|
|
4a6a6ca |
+GITHUB_DATA = {"url": u'https://api.github.com/repos/ansible/ansible',
|
|
|
4a6a6ca |
+ "response": b"""
|
|
|
4a6a6ca |
+{
|
|
|
4a6a6ca |
+ "id": 3638964,
|
|
|
4a6a6ca |
+ "name": "ansible",
|
|
|
4a6a6ca |
+ "full_name": "ansible/ansible",
|
|
|
4a6a6ca |
+ "owner": {
|
|
|
4a6a6ca |
+ "login": "ansible",
|
|
|
4a6a6ca |
+ "id": 1507452,
|
|
|
4a6a6ca |
+ "avatar_url": "https://avatars2.githubusercontent.com/u/1507452?v=4",
|
|
|
4a6a6ca |
+ "gravatar_id": "",
|
|
|
4a6a6ca |
+ "url": "https://api.github.com/users/ansible",
|
|
|
4a6a6ca |
+ "html_url": "https://github.com/ansible",
|
|
|
4a6a6ca |
+ "followers_url": "https://api.github.com/users/ansible/followers",
|
|
|
4a6a6ca |
+ "following_url": "https://api.github.com/users/ansible/following{/other_user}",
|
|
|
4a6a6ca |
+ "gists_url": "https://api.github.com/users/ansible/gists{/gist_id}",
|
|
|
4a6a6ca |
+ "starred_url": "https://api.github.com/users/ansible/starred{/owner}{/repo}",
|
|
|
4a6a6ca |
+ "subscriptions_url": "https://api.github.com/users/ansible/subscriptions",
|
|
|
4a6a6ca |
+ "organizations_url": "https://api.github.com/users/ansible/orgs",
|
|
|
4a6a6ca |
+ "repos_url": "https://api.github.com/users/ansible/repos",
|
|
|
4a6a6ca |
+ "events_url": "https://api.github.com/users/ansible/events{/privacy}",
|
|
|
4a6a6ca |
+ "received_events_url": "https://api.github.com/users/ansible/received_events",
|
|
|
4a6a6ca |
+ "type": "Organization",
|
|
|
4a6a6ca |
+ "site_admin": false
|
|
|
4a6a6ca |
+ },
|
|
|
4a6a6ca |
+ "private": false,
|
|
|
4a6a6ca |
+ "html_url": "https://github.com/ansible/ansible",
|
|
|
4a6a6ca |
+ "description": "Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy.",
|
|
|
4a6a6ca |
+ "fork": false,
|
|
|
4a6a6ca |
+ "url": "https://api.github.com/repos/ansible/ansible",
|
|
|
4a6a6ca |
+ "forks_url": "https://api.github.com/repos/ansible/ansible/forks",
|
|
|
4a6a6ca |
+ "keys_url": "https://api.github.com/repos/ansible/ansible/keys{/key_id}",
|
|
|
4a6a6ca |
+ "collaborators_url": "https://api.github.com/repos/ansible/ansible/collaborators{/collaborator}",
|
|
|
4a6a6ca |
+ "teams_url": "https://api.github.com/repos/ansible/ansible/teams",
|
|
|
4a6a6ca |
+ "hooks_url": "https://api.github.com/repos/ansible/ansible/hooks",
|
|
|
4a6a6ca |
+ "issue_events_url": "https://api.github.com/repos/ansible/ansible/issues/events{/number}",
|
|
|
4a6a6ca |
+ "events_url": "https://api.github.com/repos/ansible/ansible/events",
|
|
|
4a6a6ca |
+ "assignees_url": "https://api.github.com/repos/ansible/ansible/assignees{/user}",
|
|
|
4a6a6ca |
+ "branches_url": "https://api.github.com/repos/ansible/ansible/branches{/branch}",
|
|
|
4a6a6ca |
+ "tags_url": "https://api.github.com/repos/ansible/ansible/tags",
|
|
|
4a6a6ca |
+ "blobs_url": "https://api.github.com/repos/ansible/ansible/git/blobs{/sha}",
|
|
|
4a6a6ca |
+ "git_tags_url": "https://api.github.com/repos/ansible/ansible/git/tags{/sha}",
|
|
|
4a6a6ca |
+ "git_refs_url": "https://api.github.com/repos/ansible/ansible/git/refs{/sha}",
|
|
|
4a6a6ca |
+ "trees_url": "https://api.github.com/repos/ansible/ansible/git/trees{/sha}",
|
|
|
4a6a6ca |
+ "statuses_url": "https://api.github.com/repos/ansible/ansible/statuses/{sha}",
|
|
|
4a6a6ca |
+ "languages_url": "https://api.github.com/repos/ansible/ansible/languages",
|
|
|
4a6a6ca |
+ "stargazers_url": "https://api.github.com/repos/ansible/ansible/stargazers",
|
|
|
4a6a6ca |
+ "contributors_url": "https://api.github.com/repos/ansible/ansible/contributors",
|
|
|
4a6a6ca |
+ "subscribers_url": "https://api.github.com/repos/ansible/ansible/subscribers",
|
|
|
4a6a6ca |
+ "subscription_url": "https://api.github.com/repos/ansible/ansible/subscription",
|
|
|
4a6a6ca |
+ "commits_url": "https://api.github.com/repos/ansible/ansible/commits{/sha}",
|
|
|
4a6a6ca |
+ "git_commits_url": "https://api.github.com/repos/ansible/ansible/git/commits{/sha}",
|
|
|
4a6a6ca |
+ "comments_url": "https://api.github.com/repos/ansible/ansible/comments{/number}",
|
|
|
4a6a6ca |
+ "issue_comment_url": "https://api.github.com/repos/ansible/ansible/issues/comments{/number}",
|
|
|
4a6a6ca |
+ "contents_url": "https://api.github.com/repos/ansible/ansible/contents/{+path}",
|
|
|
4a6a6ca |
+ "compare_url": "https://api.github.com/repos/ansible/ansible/compare/{base}...{head}",
|
|
|
4a6a6ca |
+ "merges_url": "https://api.github.com/repos/ansible/ansible/merges",
|
|
|
4a6a6ca |
+ "archive_url": "https://api.github.com/repos/ansible/ansible/{archive_format}{/ref}",
|
|
|
4a6a6ca |
+ "downloads_url": "https://api.github.com/repos/ansible/ansible/downloads",
|
|
|
4a6a6ca |
+ "issues_url": "https://api.github.com/repos/ansible/ansible/issues{/number}",
|
|
|
4a6a6ca |
+ "pulls_url": "https://api.github.com/repos/ansible/ansible/pulls{/number}",
|
|
|
4a6a6ca |
+ "milestones_url": "https://api.github.com/repos/ansible/ansible/milestones{/number}",
|
|
|
4a6a6ca |
+ "notifications_url": "https://api.github.com/repos/ansible/ansible/notifications{?since,all,participating}",
|
|
|
4a6a6ca |
+ "labels_url": "https://api.github.com/repos/ansible/ansible/labels{/name}",
|
|
|
4a6a6ca |
+ "releases_url": "https://api.github.com/repos/ansible/ansible/releases{/id}",
|
|
|
4a6a6ca |
+ "deployments_url": "https://api.github.com/repos/ansible/ansible/deployments",
|
|
|
4a6a6ca |
+ "created_at": "2012-03-06T14:58:02Z",
|
|
|
4a6a6ca |
+ "updated_at": "2017-09-19T18:10:54Z",
|
|
|
4a6a6ca |
+ "pushed_at": "2017-09-19T18:04:51Z",
|
|
|
4a6a6ca |
+ "git_url": "git://github.com/ansible/ansible.git",
|
|
|
4a6a6ca |
+ "ssh_url": "git@github.com:ansible/ansible.git",
|
|
|
4a6a6ca |
+ "clone_url": "https://github.com/ansible/ansible.git",
|
|
|
4a6a6ca |
+ "svn_url": "https://github.com/ansible/ansible",
|
|
|
4a6a6ca |
+ "homepage": "https://www.ansible.com/",
|
|
|
4a6a6ca |
+ "size": 91174,
|
|
|
4a6a6ca |
+ "stargazers_count": 25552,
|
|
|
4a6a6ca |
+ "watchers_count": 25552,
|
|
|
4a6a6ca |
+ "language": "Python",
|
|
|
4a6a6ca |
+ "has_issues": true,
|
|
|
4a6a6ca |
+ "has_projects": true,
|
|
|
4a6a6ca |
+ "has_downloads": true,
|
|
|
4a6a6ca |
+ "has_wiki": false,
|
|
|
4a6a6ca |
+ "has_pages": false,
|
|
|
4a6a6ca |
+ "forks_count": 8893,
|
|
|
4a6a6ca |
+ "mirror_url": null,
|
|
|
4a6a6ca |
+ "open_issues_count": 4283,
|
|
|
4a6a6ca |
+ "forks": 8893,
|
|
|
4a6a6ca |
+ "open_issues": 4283,
|
|
|
4a6a6ca |
+ "watchers": 25552,
|
|
|
4a6a6ca |
+ "default_branch": "devel",
|
|
|
4a6a6ca |
+ "organization": {
|
|
|
4a6a6ca |
+ "login": "ansible",
|
|
|
4a6a6ca |
+ "id": 1507452,
|
|
|
4a6a6ca |
+ "avatar_url": "https://avatars2.githubusercontent.com/u/1507452?v=4",
|
|
|
4a6a6ca |
+ "gravatar_id": "",
|
|
|
4a6a6ca |
+ "url": "https://api.github.com/users/ansible",
|
|
|
4a6a6ca |
+ "html_url": "https://github.com/ansible",
|
|
|
4a6a6ca |
+ "followers_url": "https://api.github.com/users/ansible/followers",
|
|
|
4a6a6ca |
+ "following_url": "https://api.github.com/users/ansible/following{/other_user}",
|
|
|
4a6a6ca |
+ "gists_url": "https://api.github.com/users/ansible/gists{/gist_id}",
|
|
|
4a6a6ca |
+ "starred_url": "https://api.github.com/users/ansible/starred{/owner}{/repo}",
|
|
|
4a6a6ca |
+ "subscriptions_url": "https://api.github.com/users/ansible/subscriptions",
|
|
|
4a6a6ca |
+ "organizations_url": "https://api.github.com/users/ansible/orgs",
|
|
|
4a6a6ca |
+ "repos_url": "https://api.github.com/users/ansible/repos",
|
|
|
4a6a6ca |
+ "events_url": "https://api.github.com/users/ansible/events{/privacy}",
|
|
|
4a6a6ca |
+ "received_events_url": "https://api.github.com/users/ansible/received_events",
|
|
|
4a6a6ca |
+ "type": "Organization",
|
|
|
4a6a6ca |
+ "site_admin": false
|
|
|
4a6a6ca |
+ },
|
|
|
4a6a6ca |
+ "network_count": 8893,
|
|
|
4a6a6ca |
+ "subscribers_count": 1733
|
|
|
4a6a6ca |
+}
|
|
|
4a6a6ca |
+"""
|
|
|
4a6a6ca |
+ }
|
|
|
4a6a6ca |
+
|
|
|
4a6a6ca |
+
|
|
|
4a6a6ca |
def test__get_json_data(mocker):
|
|
|
4a6a6ca |
"test the json conversion of _get_url_data"
|
|
|
4a6a6ca |
|
|
|
4a6a6ca |
- url = 'https://api.github.com/repos/ansible/ansible'
|
|
|
4a6a6ca |
timeout = 30
|
|
|
4a6a6ca |
params = {
|
|
|
4a6a6ca |
- 'url': url,
|
|
|
4a6a6ca |
+ 'url': GITHUB_DATA['url'],
|
|
|
4a6a6ca |
'timeout': timeout
|
|
|
4a6a6ca |
}
|
|
|
4a6a6ca |
- module = mock.Mock()
|
|
|
4a6a6ca |
+ module = mocker.Mock()
|
|
|
4a6a6ca |
module.params = params
|
|
|
4a6a6ca |
|
|
|
4a6a6ca |
JenkinsPlugin._csrf_enabled = pass_function
|
|
|
4a6a6ca |
JenkinsPlugin._get_installed_plugins = pass_function
|
|
|
4a6a6ca |
+ JenkinsPlugin._get_url_data = mocker.Mock()
|
|
|
4a6a6ca |
+ JenkinsPlugin._get_url_data.return_value = BytesIO(GITHUB_DATA['response'])
|
|
|
4a6a6ca |
jenkins_plugin = JenkinsPlugin(module)
|
|
|
4a6a6ca |
|
|
|
4a6a6ca |
json_data = jenkins_plugin._get_json_data(
|
|
|
4a6a6ca |
- "{url}".format(url=url),
|
|
|
4a6a6ca |
+ "{url}".format(url=GITHUB_DATA['url']),
|
|
|
4a6a6ca |
'CSRF')
|
|
|
4a6a6ca |
|
|
|
4a6a6ca |
assert isinstance(json_data, collections.Mapping)
|