def test_fetch_assets_sucess_fail(self, mocked_fetch_asset_handler): """ Exercise a normal fetch for a success and a fail assets. """ mocked_fetch_asset_handler.return_value.calls = [ { 'name': 'success.tar.gz', 'locations': 'https://localhost/success.tar.gz', 'asset_hash': None, 'algorithm': None, 'expire': None }, { 'name': 'fail.tar.gz', 'locations': 'https://localhost/fail.tar.gz', 'asset_hash': None, 'algorithm': None, 'expire': None }, ] with patch('avocado.plugins.assets.Asset') as mocked_asset: mocked_asset.return_value.fetch.side_effect = [ True, OSError('Failed to fetch fail.tar.gz.') ] success, fail = assets.fetch_assets('test.py') expected_success = ['success.tar.gz'] expected_fail_exception = OSError self.assertEqual(expected_success, success) self.assertTrue(isinstance(fail[0], expected_fail_exception))
def test_fetch_assets_sucess_fail(self, mocked_fetch_asset_handler): """ Exercise a normal fetch for a success and a fail assets. """ mocked_fetch_asset_handler.return_value.calls = [ { "name": "success.tar.gz", "locations": "https://localhost/success.tar.gz", "asset_hash": None, "algorithm": None, "expire": None, }, { "name": "fail.tar.gz", "locations": "https://localhost/fail.tar.gz", "asset_hash": None, "algorithm": None, "expire": None, }, ] with patch("avocado.plugins.assets.Asset") as mocked_asset: mocked_asset.return_value.fetch.side_effect = [ True, OSError("Failed to fetch fail.tar.gz."), ] success, fail = assets.fetch_assets("test.py") expected_success = ["success.tar.gz"] expected_fail_exception = OSError self.assertEqual(expected_success, success) self.assertTrue(isinstance(fail[0], expected_fail_exception))
def test_fetch_assets_empty_calls(self, mocked_fetch_asset_handler): """ Exercise a normal fetch_assets for an empty `calls` variable. """ mocked_fetch_asset_handler.return_value.calls = [] success, fail = assets.fetch_assets('test.py') expected_success = [] expected_fail = [] self.assertEqual(expected_success, success) self.assertEqual(expected_fail, fail)
def test_fetch_assets_sucess(self, mocked_fetch_asset_handler): """ Excersise a normal fetch for a success asset. """ mocked_fetch_asset_handler.return_value.calls = [ {'name': 'success.tar.gz', 'locations': 'https://localhost/success.tar.gz', 'asset_hash': None, 'algorithm': None, 'expire': None}, ] with patch('avocado.plugins.assets.Asset') as mocked_asset: mocked_asset.return_value.fetch.side_effect = [ True] success, fail = assets.fetch_assets('test.py') expected_success = ['success.tar.gz'] expected_fail = [] self.assertEqual(expected_success, success) self.assertEqual(fail, expected_fail)
def test_fetch_assets_sucess(self, mocked_fetch_asset_handler): """ Exercise a normal fetch for a success asset. """ mocked_fetch_asset_handler.return_value.calls = [ { "name": "success.tar.gz", "locations": "https://localhost/success.tar.gz", "asset_hash": None, "algorithm": None, "expire": None, }, ] with patch("avocado.plugins.assets.Asset") as mocked_asset: mocked_asset.return_value.fetch.side_effect = [True] success, fail = assets.fetch_assets("test.py") expected_success = ["success.tar.gz"] expected_fail = [] self.assertEqual(expected_success, success) self.assertEqual(fail, expected_fail)