|
| 1 | +from unittest import TestCase |
| 2 | +from unittest.mock import patch |
| 3 | +import pytest |
| 4 | +from pathlib import Path |
| 5 | +from policyengine.utils.google_cloud_bucket import ( |
| 6 | + download_file_from_gcs, |
| 7 | + _clear_client, |
| 8 | +) |
| 9 | + |
| 10 | + |
| 11 | +class TestGoogleCloudBucket(TestCase): |
| 12 | + def setUp(self): |
| 13 | + _clear_client() |
| 14 | + |
| 15 | + @patch( |
| 16 | + "policyengine.utils.google_cloud_bucket.CachingGoogleStorageClient", |
| 17 | + autospec=True, |
| 18 | + ) |
| 19 | + def test_download_uses_storage_client(self, client_class): |
| 20 | + client_instance = client_class.return_value |
| 21 | + download_file_from_gcs( |
| 22 | + "TEST_BUCKET", "TEST/FILE/NAME.TXT", "TARGET/PATH" |
| 23 | + ) |
| 24 | + client_instance.download.assert_called_with( |
| 25 | + "TEST_BUCKET", "TEST/FILE/NAME.TXT", Path("TARGET/PATH") |
| 26 | + ) |
| 27 | + |
| 28 | + @patch( |
| 29 | + "policyengine.utils.google_cloud_bucket.CachingGoogleStorageClient", |
| 30 | + autospec=True, |
| 31 | + ) |
| 32 | + def test_download_only_creates_client_once(self, client_class): |
| 33 | + download_file_from_gcs( |
| 34 | + "TEST_BUCKET", "TEST/FILE/NAME.TXT", "TARGET/PATH" |
| 35 | + ) |
| 36 | + download_file_from_gcs( |
| 37 | + "TEST_BUCKET", "TEST/FILE/NAME.TXT", "ANOTHER/PATH" |
| 38 | + ) |
| 39 | + client_class.assert_called_once() |
0 commit comments