Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add report download tests #302

Merged
merged 4 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions camayoc/tests/qpc/cli/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
"""Test utilities for quipucords' ``qpc`` tests."""
import re

import pexpect
himmAllRight marked this conversation as resolved.
Show resolved Hide resolved

import pytest

from camayoc.config import get_config
from camayoc.constants import (
BECOME_PASSWORD_INPUT,
CONNECTION_PASSWORD_INPUT,
Expand Down
59 changes: 59 additions & 0 deletions camayoc/tests/qpc/cli/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import pprint
import random
import re
import tarfile

import pytest

Expand All @@ -23,6 +24,7 @@
from .utils import (
config_sources,
report_detail,
report_download,
report_merge,
report_merge_status,
report_summary,
Expand Down Expand Up @@ -452,3 +454,60 @@ def test_merge_report(merge_by, isolated_filesystem, qpc_server_config):

for report_item in report['system_fingerprints']:
assert_json_report_fields(report_item.keys())


@pytest.mark.parametrize('source_option', REPORT_SOURCE_OPTIONS)
def test_download_report(
source_option, isolated_filesystem, qpc_server_config):
"""Ensure a report can be downloaded and has expected information.

:id: a8c8ef8c-fa64-11e8-82bb-8c1645a90ee2
:description: Ensures reports can be downloaded in tar.gz format (ensures
command fails if specified output not tar.gz) by report id, or scanjob
id. Also ensures that package is not automatically extracted after
download.
:steps: Run ``qpc report download (--scan-job <scan-job-id> | --report
<report-id>) --output-file <output-path>``
:expectedresults: The downloaded report must be an un-extracted tar.gz
package and must contain the expected report.
"""
scan = random.choice(_SCANS)
output_path = f'{uuid4()}'
output_pkg = f'{output_path}.tar.gz'
output = report_download({
source_option: scan[source_option],
# output_format: None,
himmAllRight marked this conversation as resolved.
Show resolved Hide resolved
'output-file': output_pkg,
})
# Test that package downloaded
assert 'successfully written to' in output
himmAllRight marked this conversation as resolved.
Show resolved Hide resolved
assert os.path.isfile(output_pkg)
himmAllRight marked this conversation as resolved.
Show resolved Hide resolved

# Test that tar isn't extracted
pkg = tarfile.open(output_pkg)
pkg_contents = pkg.getnames()

pkg_top_contents = list(set(map(os.path.dirname, pkg_contents)))
found_top_contents = list(filter(lambda src: src in os.listdir(),
pkg_top_contents))
assert not found_top_contents
himmAllRight marked this conversation as resolved.
Show resolved Hide resolved

# Test that fails on non-existant path
missing_output_path = f'/no/such/number/{output_pkg})'
with pytest.raises(AssertionError) as no_dir_exception_info:
report_download({
source_option: scan[source_option],
'output-file': missing_output_path,
})
expected_msg = 'directory /no/such/number does not exist'
assert no_dir_exception_info.match(expected_msg)

# Test that non tar.gz files fail
non_tar_file = f'{format(uuid4())}'
with pytest.raises(AssertionError) as tar_exception_info:
himmAllRight marked this conversation as resolved.
Show resolved Hide resolved
report_download({
source_option: scan[source_option],
'output-file': non_tar_file,
})
expected_tar_error = 'extension is required to be tar.gz'
assert tar_exception_info.match(expected_tar_error)
3 changes: 3 additions & 0 deletions camayoc/tests/qpc/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ def report_merge_status(options=None, exitstatus=0):
report_summary = functools.partial(cli_command, 'qpc report summary')
"""Run ``qpc report summary`` with ``options`` and return output."""

report_download = functools.partial(cli_command, 'qpc report download')
"""Run ``qpc report download`` with ``options`` and return output."""


def convert_ip_format(ipaddr):
"""Convert IP strings (for generating expected test results)."""
Expand Down