Esempio n. 1
0
 def test_override_settings(self):
     with override_settings(AZURE_CONTAINER='foo1'):
         storage = azure_storage.AzureStorage()
         self.assertEqual(storage.azure_container, 'foo1')
     with override_settings(AZURE_CONTAINER='foo2'):
         storage = azure_storage.AzureStorage()
         self.assertEqual(storage.azure_container, 'foo2')
Esempio n. 2
0
 def test_blob_custom_service_params(self):
     storage = azure_storage.AzureStorage()
     storage.is_emulated = True
     storage.endpoint_suffix = 'foo_suffix'
     storage.account_name = 'foo_name'
     storage.account_key = 'foo_key'
     storage.sas_token = 'foo_token'
     storage.azure_ssl = True
     storage.custom_domain = 'foo_domain'
     storage.custom_connection_string = 'foo_conn'
     storage.token_credential = 'foo_cred'
     with mock.patch(
             'storages.backends.azure_storage.BlockBlobService',
             autospec=True) as c_mocked:
         self.assertIsNotNone(storage.custom_service)
         c_mocked.assert_called_once_with(
             account_name='foo_name',
             account_key='foo_key',
             sas_token='foo_token',
             is_emulated=True,
             protocol='https',
             custom_domain='foo_domain',
             connection_string='foo_conn',
             token_credential='foo_cred',
             endpoint_suffix='foo_suffix')
Esempio n. 3
0
 def setUp(self, *args):
     self.storage = azure_storage.AzureStorage()
     self.storage._service = mock.MagicMock()
     self.storage._custom_service = mock.MagicMock()
     self.storage.overwrite_files = True
     self.container_name = 'test'
     self.storage.azure_container = self.container_name
Esempio n. 4
0
 def test_container_client_default_params(self):
     storage = azure_storage.AzureStorage()
     storage.account_name = self.account_name
     with mock.patch('storages.backends.azure_storage.ContainerClient',
                     autospec=True) as c_mocked:
         self.assertIsNotNone(storage.client)
         c_mocked.assert_called_once_with(
             'https://test.blob.core.windows.net', None, credential=None)
Esempio n. 5
0
 def setUp(self, *args):
     self.storage = azure_storage.AzureStorage()
     self.storage._client = mock.MagicMock()
     self.storage.overwrite_files = True
     self.account_name = 'test'
     self.account_key = 'key'
     self.container_name = 'test'
     self.storage.azure_account = self.account_name
     self.storage.account_key = self.account_key
     self.storage.azure_container = self.container_name
Esempio n. 6
0
 def test_container_client_default_params(self):
     storage = azure_storage.AzureStorage()
     storage.account_name = self.account_name
     with mock.patch('storages.backends.azure_storage.BlobServiceClient',
                     autospec=True) as bsc_mocked:
         client_mock = mock.MagicMock()
         bsc_mocked.return_value.get_container_client.return_value = client_mock
         self.assertEqual(storage.client, client_mock)
         bsc_mocked.assert_called_once_with(
             'https://test.blob.core.windows.net', credential=None)
Esempio n. 7
0
 def setUp(self, *args):
     self.storage = azure_storage.AzureStorage()
     self.storage.is_emulated = True
     self.storage.account_name = "XXX"
     self.storage.account_key = "KXXX"
     self.storage.azure_container = "test"
     self.storage.service.delete_container(
         self.storage.azure_container, fail_not_exist=False)
     self.storage.service.create_container(
         self.storage.azure_container, public_access=False, fail_on_exist=False)
Esempio n. 8
0
 def test_container_client_params_connection_string(self):
     storage = azure_storage.AzureStorage()
     storage.account_name = self.account_name
     storage.connection_string = 'foo_conn'
     with mock.patch(
             'storages.backends.azure_storage.BlobServiceClient.from_connection_string',
             spec=azure_storage.BlobServiceClient.from_connection_string
     ) as bsc_mocked:
         client_mock = mock.MagicMock()
         bsc_mocked.return_value.get_container_client.return_value = client_mock
         self.assertEqual(storage.client, client_mock)
         bsc_mocked.assert_called_once_with('foo_conn')
Esempio n. 9
0
 def test_container_client_params_sas_token(self):
     storage = azure_storage.AzureStorage()
     storage.account_name = 'foo_name'
     storage.azure_ssl = False
     storage.custom_domain = 'foo_domain'
     storage.sas_token = 'foo_token'
     with mock.patch('storages.backends.azure_storage.BlobServiceClient',
                     autospec=True) as bsc_mocked:
         client_mock = mock.MagicMock()
         bsc_mocked.return_value.get_container_client.return_value = client_mock
         self.assertEqual(storage.client, client_mock)
         bsc_mocked.assert_called_once_with('http://foo_domain',
                                            credential='foo_token')
Esempio n. 10
0
 def test_blob_custom_service_default_params(self):
     storage = azure_storage.AzureStorage()
     with mock.patch('storages.backends.azure_storage.BlockBlobService',
                     autospec=True) as c_mocked:
         self.assertIsNotNone(storage.custom_service)
         c_mocked.assert_called_once_with(account_name=None,
                                          account_key=None,
                                          sas_token=None,
                                          is_emulated=False,
                                          protocol='https',
                                          custom_domain=None,
                                          connection_string=None,
                                          token_credential=None,
                                          endpoint_suffix=None)
Esempio n. 11
0
 def test_container_client_params(self):
     storage = azure_storage.AzureStorage()
     storage.account_name = 'foo_name'
     storage.account_key = 'foo_key'
     storage.sas_token = 'foo_token'
     storage.azure_ssl = True
     storage.custom_domain = 'foo_domain'
     storage.connection_string = 'foo_conn'
     storage.token_credential = 'foo_cred'
     with mock.patch('storages.backends.azure_storage.ContainerClient',
                     autospec=True) as c_mocked:
         self.assertIsNotNone(storage.client)
         c_mocked.assert_called_once_with('foo_conn',
                                          None,
                                          credential='foo_key')
Esempio n. 12
0
 def test_blob_custom_service_params_no_emulator(self):
     """Should pass custom domain when emulator is not used"""
     storage = azure_storage.AzureStorage()
     storage.is_emulated = False
     storage.custom_domain = 'foo_domain'
     with mock.patch('storages.backends.azure_storage.BlockBlobService',
                     autospec=True) as c_mocked:
         self.assertIsNotNone(storage.custom_service)
         c_mocked.assert_called_once_with(account_name=None,
                                          account_key=None,
                                          sas_token=None,
                                          is_emulated=False,
                                          protocol='https',
                                          custom_domain='foo_domain',
                                          connection_string=None,
                                          token_credential=None,
                                          endpoint_suffix=None)
Esempio n. 13
0
 def test_override_init_argument(self):
     storage = azure_storage.AzureStorage(azure_container='foo1')
     self.assertEqual(storage.azure_container, 'foo1')
     storage = azure_storage.AzureStorage(azure_container='foo2')
     self.assertEqual(storage.azure_container, 'foo2')
Esempio n. 14
0
 def test_url_custom_endpoint(self):
     storage = azure_storage.AzureStorage()
     storage.is_emulated = True
     storage.custom_domain = 'foobar:123456'
     self.assertTrue(
         storage.url("my_file.txt").startswith('https://foobar:123456/'))
Esempio n. 15
0
 def setUp(self, *args):
     self.storage = azure_storage.AzureStorage()
     self.storage._connection = mock.MagicMock()
     self.container_name = 'test'
     self.storage.azure_container = self.container_name