def test_get_file_properties_with_non_existing_file(self): # Arrange file_name = self._get_file_reference() file_client = FileClient(self.get_file_url(), share=self.share_name, file_path=file_name, credential=self.settings.STORAGE_ACCOUNT_KEY) # Act with self.assertRaises(ResourceNotFoundError): file_client.get_file_properties()
def test_get_file_metadata_with_snapshot(self): # Arrange file_client = self._create_file() metadata = {"test1": "foo", "test2": "bar"} file_client.set_file_metadata(metadata) share_client = self.fsc.get_share_client(self.share_name) snapshot = share_client.create_snapshot() snapshot_client = FileClient( self.get_file_url(), share=self.share_name, file_path=file_client.file_name, snapshot=snapshot, credential=self.settings.STORAGE_ACCOUNT_KEY) metadata2 = {"test100": "foo100", "test200": "bar200"} file_client.set_file_metadata(metadata2) # Act file_metadata = file_client.get_file_properties().metadata file_snapshot_metadata = snapshot_client.get_file_properties().metadata # Assert self.assertDictEqual(metadata2, file_metadata) self.assertDictEqual(metadata, file_snapshot_metadata)
def test_file_not_exists_with_snapshot(self): # Arrange share_client = self.fsc.get_share_client(self.share_name) snapshot = share_client.create_snapshot() file_client = self._create_file() # Act snapshot_client = FileClient( self.get_file_url(), share=self.share_name, file_path=file_client.file_name, snapshot=snapshot, credential=self.settings.STORAGE_ACCOUNT_KEY) # Assert with self.assertRaises(ResourceNotFoundError): snapshot_client.get_file_properties()
def test_create_file(self): # Arrange file_name = self._get_file_reference() file_client = FileClient(self.get_file_url(), share=self.share_name, file_path=file_name, credential=self.settings.STORAGE_ACCOUNT_KEY) # Act resp = file_client.create_file(1024) # Assert props = file_client.get_file_properties() self.assertIsNotNone(props) self.assertEqual(props.etag, resp['etag']) self.assertEqual(props.last_modified, resp['last_modified'])
def test_file_exists_with_snapshot(self): # Arrange file_client = self._create_file() share_client = self.fsc.get_share_client(self.share_name) snapshot = share_client.create_snapshot() file_client.delete_file() # Act snapshot_client = FileClient( self.get_file_url(), share=self.share_name, file_path=file_client.file_name, snapshot=snapshot, credential=self.settings.STORAGE_ACCOUNT_KEY) props = snapshot_client.get_file_properties() # Assert self.assertTrue(props)
def test_create_file_with_metadata(self): # Arrange metadata = {'hello': 'world', 'number': '42'} file_name = self._get_file_reference() file_client = FileClient(self.get_file_url(), share=self.share_name, file_path=file_name, credential=self.settings.STORAGE_ACCOUNT_KEY) # Act resp = file_client.create_file(1024, metadata=metadata) # Assert props = file_client.get_file_properties() self.assertIsNotNone(props) self.assertEqual(props.etag, resp['etag']) self.assertEqual(props.last_modified, resp['last_modified']) self.assertDictEqual(props.metadata, metadata)