From 72a0b1b7bbbf67fcca6e9aa6cf18fb917946c5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ely=C3=A9zer=20Rezende?= Date: Wed, 8 Nov 2017 17:04:35 -0200 Subject: [PATCH] Automate quipucords host credential tests Closes #53 --- camayoc/qcs_models.py | 2 +- camayoc/tests/qcs/test_credentials.py | 84 +++++++++++++++++++++------ 2 files changed, 68 insertions(+), 18 deletions(-) diff --git a/camayoc/qcs_models.py b/camayoc/qcs_models.py index 2d818513..2802d3e1 100644 --- a/camayoc/qcs_models.py +++ b/camayoc/qcs_models.py @@ -201,7 +201,7 @@ def equivalent(self, other): diffs = 0 password_matcher = re.compile(MASKED_PASSWORD_OUTPUT) for key, value in self.fields().items(): - if key == 'password': + if key == 'password' and other.get(key) is not None: if not password_matcher.match(other.get(key)): diffs += 1 else: diff --git a/camayoc/tests/qcs/test_credentials.py b/camayoc/tests/qcs/test_credentials.py index 2927bb02..dc6822d5 100644 --- a/camayoc/tests/qcs/test_credentials.py +++ b/camayoc/tests/qcs/test_credentials.py @@ -9,12 +9,13 @@ :testtype: functional :upstream: yes """ +import random +from pathlib import Path import pytest -from uuid import uuid4 - from camayoc.qcs_models import HostCredential +from camayoc.utils import uuid4 from camayoc.tests.qcs.utils import assert_matches_server @@ -26,7 +27,7 @@ def test_create_with_password(shared_client, cleanup): :steps: Send POST with necessary data to documented api endpoint. :expectedresults: A new host credential entry is created with the data. """ - cred = HostCredential(client=shared_client, password=str(uuid4())) + cred = HostCredential(client=shared_client, password=uuid4()) cred.create() # add the credential to the list to destroy after the test is done cleanup.append(cred) @@ -45,20 +46,20 @@ def test_update_username(shared_client, cleanup): 3) Confirm host credential has been updated. :expectedresults: The host credential is updated. """ - cred = HostCredential(shared_client, password=str(uuid4())) + cred = HostCredential(shared_client, password=uuid4()) cred.create() # add the id to the list to destroy after the test is done cleanup.append(cred) assert_matches_server(cred) # give the cred a new username - cred.username = str(uuid4()) + cred.username = uuid4() cred.update() assert_matches_server(cred) -@pytest.mark.skip -def test_update_password_to_sshkeyfile(cleanup): +def test_update_password_to_sshkeyfile( + shared_client, cleanup, isolated_filesystem): """Create a host credential using password and switch it to use sshkey. :id: 6e557092-192b-4f75-babc-abc5774fe965 @@ -71,11 +72,24 @@ def test_update_password_to_sshkeyfile(cleanup): :expectedresults: The host credential is updated. :caseautomation: notautomated """ - pass + cred = HostCredential(shared_client, password=uuid4()) + cred.create() + # add the id to the list to destroy after the test is done + cleanup.append(cred) + assert_matches_server(cred) + sshkeyfile = Path(uuid4()) + sshkeyfile.touch() -@pytest.mark.skip -def test_update_sshkey_to_password(cleanup): + # give the cred a new username + cred.ssh_keyfile = str(sshkeyfile.resolve()) + cred.password = None + cred.update() + assert_matches_server(cred) + + +def test_update_sshkey_to_password( + shared_client, cleanup, isolated_filesystem): """Create a host credential using password and switch it to use sshkey. :id: d24a54b5-3d8c-44e4-a0ae-61584a15b127 @@ -89,7 +103,23 @@ def test_update_sshkey_to_password(cleanup): :expectedresults: The host credential is updated. :caseautomation: notautomated """ - pass + ssh_keyfile = Path(uuid4()) + ssh_keyfile.touch() + + cred = HostCredential( + shared_client, + ssh_keyfile=str(ssh_keyfile.resolve()), + ) + cred.create() + # add the id to the list to destroy after the test is done + cleanup.append(cred) + assert_matches_server(cred) + + # give the cred a new username + cred.password = uuid4() + cred.ssh_keyfile = None + cred.update() + assert_matches_server(cred) @pytest.mark.skip @@ -112,8 +142,8 @@ def test_negative_update_to_invalid(cleanup): pass -@pytest.mark.skip -def test_create_with_sshkey(cleanup): +def test_create_with_sshkey( + shared_client, cleanup, isolated_filesystem): """Create a host credential with username and sshkey. :id: ab6fd574-2e9f-46b8-847d-17b23c19fdd2 @@ -122,7 +152,17 @@ def test_create_with_sshkey(cleanup): :expectedresults: A new host credential entry is created with the data. :caseautomation: notautomated """ - pass + ssh_keyfile = Path(uuid4()) + ssh_keyfile.touch() + + cred = HostCredential( + shared_client, + ssh_keyfile=str(ssh_keyfile.resolve()), + ) + cred.create() + # add the id to the list to destroy after the test is done + cleanup.append(cred) + assert_matches_server(cred) @pytest.mark.skip @@ -170,8 +210,7 @@ def test_negative_create_no_key_or_pass(cleanup): pass -@pytest.mark.skip -def test_read_all(cleanup): +def test_read_all(shared_client, cleanup): """After created, retrieve all host credentials with GET to api. :id: fa05b857-5b01-4388-9226-8dfb5639c815 @@ -185,7 +224,18 @@ def test_read_all(cleanup): :expectedresults: All hosts are present in data returned by API. :caseautomation: notautomated """ - pass + host_credentials = [] + for _ in range(random.randint(2, 5)): + cred = HostCredential(client=shared_client, password=uuid4()) + cred.create() + # add the credential to the list to destroy after the test is done + cleanup.append(cred) + assert_matches_server(cred) + host_credentials.append(cred) + + remote_host_credentials = HostCredential().list().json() + for local, remote in zip(host_credentials, remote_host_credentials): + local.equivalent(remote) @pytest.mark.skip