Skip to content

Commit

Permalink
Fix tests that removing temp archives (#3445)
Browse files Browse the repository at this point in the history
Signed-off-by: ahitacat <[email protected]>
  • Loading branch information
ahitacat authored Jun 17, 2022
1 parent e90de91 commit 0878bbe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions insights/tests/client/apps/test_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@patch("insights.client.apps.compliance.ComplianceClient._assert_oscap_rpms_exist")
@patch("insights.client.config.InsightsConfig", base_url='localhost/app', systemid='', proxy=None, compressor='gz', obfuscate=False)
@patch("insights.client.archive.atexit", Mock())
def test_oscap_scan(config, assert_rpms):
compliance_client = ComplianceClient(config)
compliance_client._get_inventory_id = lambda: ''
Expand All @@ -27,6 +28,7 @@ def test_oscap_scan(config, assert_rpms):

@patch("insights.client.apps.compliance.ComplianceClient._assert_oscap_rpms_exist")
@patch("insights.client.config.InsightsConfig", base_url='localhost/app', systemid='', proxy=None, compressor='gz', obfuscate=True)
@patch("insights.client.archive.atexit", Mock())
def test_oscap_scan_with_obfuscation(config, assert_rpms, tmpdir):
results_file = tmpdir.mkdir('results').join('result.xml')
results_file.write("""
Expand Down Expand Up @@ -85,6 +87,7 @@ def test_oscap_scan_with_obfuscation(config, assert_rpms, tmpdir):

@patch("insights.client.apps.compliance.ComplianceClient._assert_oscap_rpms_exist")
@patch("insights.client.config.InsightsConfig", base_url='localhost/app', systemid='', proxy=None, compressor='gz', obfuscate=True, obfuscate_hostname=True)
@patch("insights.client.archive.atexit", Mock())
def test_oscap_scan_with_hostname_obfuscation(config, assert_rpms, tmpdir):
results_file = tmpdir.mkdir('results').join('result.xml')
results_file.write("""
Expand Down Expand Up @@ -155,6 +158,7 @@ def test_oscap_scan_with_hostname_obfuscation(config, assert_rpms, tmpdir):

@patch("insights.client.apps.compliance.ComplianceClient._assert_oscap_rpms_exist")
@patch("insights.client.config.InsightsConfig", base_url='localhost/app', systemid='', proxy=None, compressor='gz')
@patch("insights.client.archive.atexit", Mock())
def test_oscap_scan_with_results_repaired(config, assert_rpms, tmpdir):
results_file = tmpdir.mkdir('results').join('result.xml')
results_file.write("""
Expand Down
1 change: 0 additions & 1 deletion insights/tests/client/test_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from unittest import TestCase
from pytest import raises


test_timestamp = '000000'
test_hostname = 'testhostname'
test_archive_name = 'insights-testhostname-000000'
Expand Down
13 changes: 8 additions & 5 deletions insights/tests/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,9 @@ def test_upload_412_write_unregistered_file(_, upload_archive, write_unregistere

@patch('insights.client.archive.InsightsArchive.storing_archive')
@patch('insights.client.archive.tempfile.mkdtemp', Mock())
@patch('insights.client.archive.os.makedirs', Mock())
@patch('insights.client.archive.atexit', Mock())
def test_cleanup_tmp(storing_archive):

config = InsightsConfig(keep_archive=False)
arch = InsightsArchive(config)
arch.tmp_dir = "/test"
Expand All @@ -362,17 +363,19 @@ def test_cleanup_tmp(storing_archive):

@patch('insights.client.archive.InsightsArchive.storing_archive')
@patch('insights.client.archive.tempfile.mkdtemp', Mock())
@patch('insights.client.archive.os.makedirs', Mock())
@patch('insights.client.archive.atexit', Mock())
def test_cleanup_tmp_obfuscation(storing_archive):
config = InsightsConfig(keep_archive=False, obfuscate=True)
arch = InsightsArchive(config)
arch.tmp_dir = "/test"
arch.tar_file = "/test/test.tar.gz"
arch.keep_archive_dir = "/test-keep-archive"
arch.tmp_dir = '/var/tmp/insights-archive-000000'
arch.tar_file = '/var/tmp/insights-archive-test.tar.gz'
arch.keep_archive_dir = '/var/tmp/test-archive'
arch.cleanup_tmp()
assert not os.path.exists(arch.tmp_dir)
storing_archive.assert_not_called()

config.keep_archive = True
arch.config.keep_archive = True
arch.cleanup_tmp()
assert not os.path.exists(arch.tmp_dir)
storing_archive.assert_called_once()
Expand Down

0 comments on commit 0878bbe

Please sign in to comment.