aboutsummaryrefslogtreecommitdiffstats
path: root/xtesting/tests/unit/core/test_testcase.py
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2019-11-16 16:21:44 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2019-11-16 16:32:09 +0100
commit697e55eefd2f9101a47ff9a93e125ca6c776fa64 (patch)
treecf7f7e4a9ba297e6e694fa016444c6e69ae4e6f0 /xtesting/tests/unit/core/test_testcase.py
parent62101c9497199b71205cd08635c7c76868139c52 (diff)
Add ContentType when publishing artifacts
The default value 'application/octet-stream' is mostly incorrect and forces downloading all links. https://build.opnfv.org/ci/job/functest-opnfv-functest-healthcheck-hunter-connection_check-run/436/console Change-Id: Ia680654f5e9f67154504264bc380f0a8d6a74d85 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com> (cherry picked from commit e2e7dbe185a552b21315063dbbed8ac4f40f309d)
Diffstat (limited to 'xtesting/tests/unit/core/test_testcase.py')
-rw-r--r--xtesting/tests/unit/core/test_testcase.py40
1 files changed, 37 insertions, 3 deletions
diff --git a/xtesting/tests/unit/core/test_testcase.py b/xtesting/tests/unit/core/test_testcase.py
index 6d18a968..5d34c34d 100644
--- a/xtesting/tests/unit/core/test_testcase.py
+++ b/xtesting/tests/unit/core/test_testcase.py
@@ -359,6 +359,7 @@ class TestCaseTesting(unittest.TestCase):
args[0].assert_called_once_with(
's3', endpoint_url=os.environ['S3_ENDPOINT_URL'])
+ @mock.patch('mimetypes.guess_type', return_value=(None, None))
@mock.patch('boto3.resource')
@mock.patch('os.walk', return_value=[])
def test_publish_artifacts1(self, *args):
@@ -368,6 +369,7 @@ class TestCaseTesting(unittest.TestCase):
args[1].assert_called_once_with(
's3', endpoint_url=os.environ['S3_ENDPOINT_URL'])
+ @mock.patch('mimetypes.guess_type', return_value=(None, None))
@mock.patch('boto3.resource')
@mock.patch('os.walk', return_value=[])
def test_publish_artifacts2(self, *args):
@@ -381,6 +383,7 @@ class TestCaseTesting(unittest.TestCase):
args[1].assert_called_once_with(
's3', endpoint_url=os.environ['S3_ENDPOINT_URL'])
+ @mock.patch('mimetypes.guess_type', return_value=(None, None))
@mock.patch('os.path.exists', return_value=True)
@mock.patch('boto3.resource')
@mock.patch('os.walk',
@@ -396,16 +399,47 @@ class TestCaseTesting(unittest.TestCase):
mock.call().Bucket('xtesting'),
mock.call().Bucket().upload_file(
'/var/lib/xtesting/results/xtesting.log',
- 'prefix/xtesting.log'),
+ 'prefix/xtesting.log',
+ ExtraArgs={'ContentType': 'application/octet-stream'}),
mock.call().Bucket('xtesting'),
mock.call().Bucket().upload_file(
'/var/lib/xtesting/results/xtesting.debug.log',
- 'prefix/xtesting.debug.log'),
+ 'prefix/xtesting.debug.log',
+ ExtraArgs={'ContentType': 'application/octet-stream'}),
mock.call().Bucket('xtesting'),
mock.call().Bucket().upload_file(
- '/var/lib/xtesting/results/bar', 'prefix/bar')]
+ '/var/lib/xtesting/results/bar', 'prefix/bar',
+ ExtraArgs={'ContentType': 'application/octet-stream'})]
self.assertEqual(args[1].mock_calls, expected)
+ @mock.patch('mimetypes.guess_type', return_value=('text/plain', None))
+ @mock.patch('os.path.exists', return_value=True)
+ @mock.patch('boto3.resource')
+ @mock.patch('os.walk',
+ return_value=[
+ (testcase.TestCase.dir_results, ('',), ('bar',))])
+ def test_publish_artifacts4(self, *args):
+ self.assertEqual(self.test.publish_artifacts(),
+ testcase.TestCase.EX_OK)
+ args[0].assert_called_once_with(self.test.res_dir)
+ expected = [
+ mock.call('s3', endpoint_url=os.environ['S3_ENDPOINT_URL']),
+ mock.call().meta.client.head_bucket(Bucket='xtesting'),
+ mock.call().Bucket('xtesting'),
+ mock.call().Bucket().upload_file(
+ '/var/lib/xtesting/results/xtesting.log',
+ 'prefix/xtesting.log',
+ ExtraArgs={'ContentType': 'text/plain'}),
+ mock.call().Bucket('xtesting'),
+ mock.call().Bucket().upload_file(
+ '/var/lib/xtesting/results/xtesting.debug.log',
+ 'prefix/xtesting.debug.log',
+ ExtraArgs={'ContentType': 'text/plain'}),
+ mock.call().Bucket('xtesting'),
+ mock.call().Bucket().upload_file(
+ '/var/lib/xtesting/results/bar', 'prefix/bar',
+ ExtraArgs={'ContentType': 'text/plain'})]
+ self.assertEqual(args[1].mock_calls, expected)
if __name__ == "__main__":
logging.disable(logging.CRITICAL)