Skip to content

Commit

Permalink
Automate quipucords host credential tests
Browse files Browse the repository at this point in the history
Closes #53
  • Loading branch information
elyezer committed Nov 8, 2017
1 parent bbdad03 commit 72a0b1b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 18 deletions.
2 changes: 1 addition & 1 deletion camayoc/qcs_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
84 changes: 67 additions & 17 deletions camayoc/tests/qcs/test_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 72a0b1b

Please sign in to comment.