Last active
February 27, 2019 12:42
-
-
Save neilus/365ba5e74f5beaf9ba44a334be0e4974 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Testing Nexus Configuration | |
""" | |
import os | |
import json | |
import requests | |
from requests.auth import HTTPBasicAuth | |
from pytest import mark | |
from testinfra.utils.ansible_runner import AnsibleRunner | |
testinfra_hosts = AnsibleRunner( | |
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') | |
repo_json = None | |
def get_nexus_repos(): | |
global repo_json | |
if not repo_json: | |
repo_json = nexus_get_request('/service/rest/v1/repositories') | |
return repo_json | |
def nexus_ip(): | |
ansible_runner = AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']) | |
nexus = ansible_runner.run('all', 'setup') | |
nexus_address = nexus.get('ansible_facts')\ | |
.get('ansible_default_ipv4')\ | |
.get('address') | |
return nexus_address | |
def nexus_get_request(what): | |
r = requests.get('http://%s:8081%s' % | |
(nexus_ip(), what), | |
auth=HTTPBasicAuth(username='admin', | |
password='admin123')) | |
return r | |
def test_admin_credential_setup(): | |
r = nexus_get_request("/service/rest/v1/script") | |
assert r.status_code == 200 | |
def expected_repo(repo_name, repo_format, repo_type="hosted"): | |
repo_url = 'http://%s:8081/repository/%s' % (nexus_ip(), repo_name) | |
expected_repo = { | |
'url': repo_url, | |
'type': repo_type, | |
'format': repo_format, | |
'name': repo_name | |
} | |
return expected_repo | |
def test_helm_repo_exists(): | |
r = get_nexus_repos() | |
repositories = json.loads(r.content) | |
assert r.status_code == 200 | |
assert expected_repo('boat', 'helm') in repositories | |
@mark.parametrize("repo_name,repo_format,repo_type", [ | |
('barbarian', 'conan', 'hosted'), | |
('conan-center', 'conan', 'proxy'), | |
('bincrafters', 'conan', 'proxy'), | |
('conan-community', 'conan', 'proxy') | |
]) | |
def test_conan_repos_exist(repo_name, repo_format, repo_type): | |
r = get_nexus_repos() | |
repositories = json.loads(r.content) | |
assert r.status_code == 200 | |
assert expected_repo(repo_name, repo_format, repo_type) in repositories | |
@mark.parametrize("repo_name,repo_format,repo_type", [ | |
("maven-central", "maven2", "proxy"), | |
("maven-public", "maven2", "proxy"), | |
("maven-releases", "maven2", "hosted"), | |
("maven-snapshots", "maven2", "hosted"), | |
("nuget-group", "nuget", "group"), | |
("nuget-hosted", "nuget", "hosted"), | |
("nuget.org-proxy", "nuget", "proxy") | |
]) | |
def test_default_repos_dont_exist(repo_name, repo_format, repo_type): | |
r = get_nexus_repos() | |
repositories = json.loads(r.content) | |
assert r.status_code == 200 | |
assert expected_repo(repo_name, repo_format, repo_type) not in repositories |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment