From 10f4e09187d3e5ca5598f9a35f855dd5c1d6a5d7 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Wed, 17 Jul 2019 15:05:38 -0700 Subject: [PATCH 01/26] Smoke Test Sample for Track 2 libraries Smoke Test for Indentity, Key Vault Secrets, Storage Blobs, Event Hubs and Cosmos DB --- samples/smoketest/CosmosDB.py | 88 ++++++++++++++++++++++++++++ samples/smoketest/EventHubs.py | 52 ++++++++++++++++ samples/smoketest/KeyVaultSecrets.py | 43 ++++++++++++++ samples/smoketest/Program.py | 15 +++++ samples/smoketest/StorageBlobs.py | 47 +++++++++++++++ 5 files changed, 245 insertions(+) create mode 100644 samples/smoketest/CosmosDB.py create mode 100644 samples/smoketest/EventHubs.py create mode 100644 samples/smoketest/KeyVaultSecrets.py create mode 100644 samples/smoketest/Program.py create mode 100644 samples/smoketest/StorageBlobs.py diff --git a/samples/smoketest/CosmosDB.py b/samples/smoketest/CosmosDB.py new file mode 100644 index 000000000000..72285289ca35 --- /dev/null +++ b/samples/smoketest/CosmosDB.py @@ -0,0 +1,88 @@ +import azure.cosmos.cosmos_client as cosmos_client +import azure.cosmos.errors as errors +from azure.cosmos.partition_key import PartitionKey +import os + +class CosmosDB: + def __init__(self): + URL = os.environ["COSMOS_ENDPOINT"] + KEY = os.environ["COSMOS_KEY"] + self.client = cosmos_client.CosmosClient(URL,{'masterKey': KEY}) + + def createDatabase(self): + dbName="pySolarSystem" + print("Creating '{0}' database...".format(dbName)) + return self.client.create_database(dbName) + + def createContainer(self, db): + collectionName = "Planets" + print("Creating '{0}' collection...".format(collectionName)) + partition_key = PartitionKey(path='/id', kind='Hash') + return db.create_container(id="Planets", partition_key=partition_key) + + def createDocuments(self, container): + planets = [] + + # Cosmos will look for an 'id' field in the items, if the 'id' is not specify Cosmos is going to assing a random key. + planets.append({ + 'id' : "Earth", + 'HasRings' : False, + 'Radius' : 3959, + 'Moons' : + [ + { + 'Name' : "Moon" + } + ] + }) + + planets.append({ + "id" : "Mars", + "HasRings" : False, + "Radius" : 2106, + "Moons" : + [ + { + "Name" : "Phobos" + }, + { + "Name" : "Deimos" + } + ] + }) + + print("Inserting items in the collection...") + for planet in planets: + container.create_item(planet) + print("\t'{0}' created".format(planet['id'])) + print("\tdone") + + def deleteDatabase(self): + print("Cleaning up the resource...") + self.client.delete_database("pySolarSystem") + print("\tdone") + + def Run(self): + print() + print("------------------------") + print("Cosmos DB") + print("------------------------") + print("1) Create a Database") + print("2) Create a Container in the database") + print("3) Insert Documents (items) into the Container") + print("4) Delete Database (Clean up the resource)") + print() + + # Ensure that the database does not exists + try: + self.deleteDatabase() + except: + pass + + try: + db = self.createDatabase() + container = self.createContainer(db=db) + self.createDocuments(container=container) + finally: + # if something goes wrong, the resource should be cleaned anyway + self.deleteDatabase() \ No newline at end of file diff --git a/samples/smoketest/EventHubs.py b/samples/smoketest/EventHubs.py new file mode 100644 index 000000000000..652af75d0c7a --- /dev/null +++ b/samples/smoketest/EventHubs.py @@ -0,0 +1,52 @@ +from azure.eventhub import EventHubClient, EventData, EventPosition +from datetime import datetime +import os + +class EventHub: + def __init__(self): + # This test requires a previusly created Event Hub. + # In this example the name is "myeventhub", but it could be change below + connectionString = os.environ["EVENT_HUBS_CONNECTION_STRING"] + eventHubName = 'myeventhub' + self.client = EventHubClient.from_connection_string(connectionString, eventHubName) + + def getPartitionIds(self): + print("Getting partitions id...") + partition_ids = self.client.get_partition_ids() + print("\tdone") + return partition_ids + + def sendAndReceiveEvents(self, partitionID): + consumer = self.client.create_consumer(consumer_group="$default", partition_id=partitionID, event_position=EventPosition(datetime.utcnow())) + + print("Sending events...") + producer = self.client.create_producer(partition_id=partitionID) + event_list = [EventData(b"Test Event 1 in Python"),EventData(b"Test Event 2 in Python"),EventData(b"Test Event 3 in Python")] + producer.send(event_list) + producer.close() + print("\tdone") + + print("Receiving events...") + received = consumer.receive(max_batch_size=len(event_list), timeout=2) + for event_data in received: + print("\tEvent Received: " + event_data.body_as_str()) + consumer.close() + print("\tdone") + + if(len(received) != len(event_list)): + raise Exception("Error, expecting {0} events, but {1} were received.".format(str(len(event_list)),str(len(received)))) + + def Run(self): + print() + print("------------------------") + print("Event Hubs") + print("------------------------") + print("1) Get partition ID") + print("2) Send Events") + print("3) Consume Events") + print() + + partitionID = self.getPartitionIds() + #In this sample the same partition id is going to be used for the producer and consumer, + #It is the first one, but it could be any (is not relevant as long as it is the same in both producer and consumer) + self.sendAndReceiveEvents(partitionID[0]) \ No newline at end of file diff --git a/samples/smoketest/KeyVaultSecrets.py b/samples/smoketest/KeyVaultSecrets.py new file mode 100644 index 000000000000..f9b1c26b1d5a --- /dev/null +++ b/samples/smoketest/KeyVaultSecrets.py @@ -0,0 +1,43 @@ +from azure.identity import DefaultAzureCredential +from azure.keyvault.secrets import SecretClient +import os + +class KeyVault: + def __init__(self): + # DefaultAzureCredential() expects the following environment variables: + # * AZURE_CLIENT_ID + # * AZURE_CLIENT_SECRET + # * AZURE_TENANT_ID + credential = DefaultAzureCredential() + self.secret_client = SecretClient(vault_url=os.environ["AZURE_PROJECT_URL"], credential=credential) + + def setSecret(self): + print("Setting a secret...") + self.secret_client.set_secret("secret-name", "secret-value") + print("\tdone") + + def getSecret(self): + print("Getting a secret...") + secret = self.secret_client.get_secret("secret-name") + print("\tdone: " + secret.name) + + def deleteSecret(self): + print("Deleting a secret...") + deleted_secret = self.secret_client.delete_secret("secret-name") + print("\tdone: " + deleted_secret.name) + + def Run(self): + print() + print("------------------------") + print("Key Vault - Secrets\nIdentity - Credential") + print("------------------------") + print("1) Set a secret") + print("2) Get that secret") + print("3) Delete that secret (Clean up the resource)") + print() + + try: + self.setSecret() + self.getSecret() + finally: + self.deleteSecret() \ No newline at end of file diff --git a/samples/smoketest/Program.py b/samples/smoketest/Program.py new file mode 100644 index 000000000000..f2a4649fa083 --- /dev/null +++ b/samples/smoketest/Program.py @@ -0,0 +1,15 @@ +# from azure.identity import DefaultAzureCredential +# from azure.keyvault.secrets import SecretClient +from KeyVaultSecrets import KeyVault +from StorageBlobs import StorageBlob +from EventHubs import EventHub +from CosmosDB import CosmosDB + +print("==========================================") +print(" AZURE TRACK 2 SDKs SMOKE TEST") +print("==========================================") + +KeyVault().Run() +StorageBlob().Run() +EventHub().Run() +CosmosDB().Run() \ No newline at end of file diff --git a/samples/smoketest/StorageBlobs.py b/samples/smoketest/StorageBlobs.py new file mode 100644 index 000000000000..1a7a246054a1 --- /dev/null +++ b/samples/smoketest/StorageBlobs.py @@ -0,0 +1,47 @@ +from azure.storage.blob import BlobClient +import os + +class StorageBlob: + def __init__(self): + connectionString = os.environ["STORAGE_CONNECTION_STRING"] + self.blob = BlobClient.from_connection_string(connectionString, container="mycontainer", blob="pyTestBlob.txt") + + def uploadBLob(self): + print("uploading blob...") + self.data = "This is a sample data for Python Test" + self.blob.upload_blob(self.data) + print("\tdone") + + def downloadBlob(self): + print("downloading blob...") + with open("./downloadedBlob.txt", "wb+") as my_blob: + my_blob.writelines(self.blob.download_blob()) + + print("\tdone") + + def deleteBlob(self): + print("Cleaning up the resource...") + self.blob.delete_blob() + print("\tdone") + + def Run(self): + print() + print("------------------------") + print("Storage - Blob") + print("------------------------") + print("1) Upload a Blob") + print("2) Download a Blob") + print("3) Delete that Blob (Clean up the resource)") + print() + + #Ensure that the blob does not exists before the tests + try: + self.deleteBlob() + except: + pass + + try: + self.uploadBLob() + self.downloadBlob() + finally: + self.deleteBlob() \ No newline at end of file From d6e763c9ac8f481bfe651031d2a6765bce13a95b Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Wed, 17 Jul 2019 15:32:34 -0700 Subject: [PATCH 02/26] simpleQuery method added --- samples/smoketest/CosmosDB.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/samples/smoketest/CosmosDB.py b/samples/smoketest/CosmosDB.py index 72285289ca35..8e199fb545d6 100644 --- a/samples/smoketest/CosmosDB.py +++ b/samples/smoketest/CosmosDB.py @@ -56,6 +56,14 @@ def createDocuments(self, container): container.create_item(planet) print("\t'{0}' created".format(planet['id'])) print("\tdone") + + def simpleQuery(self, container): + print("Quering the container...") + items = list(container.query_items( + query="SELECT c.id FROM c", + enable_cross_partition_query = True + )) + print("\tdone: {0}".format(items)) def deleteDatabase(self): print("Cleaning up the resource...") @@ -82,7 +90,8 @@ def Run(self): try: db = self.createDatabase() container = self.createContainer(db=db) - self.createDocuments(container=container) + self.createDocuments(container=container) + self.simpleQuery(container=container) finally: # if something goes wrong, the resource should be cleaned anyway self.deleteDatabase() \ No newline at end of file From 45e96997204e937222b02407c603f14ce87bb8e0 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Wed, 17 Jul 2019 15:40:48 -0700 Subject: [PATCH 03/26] Method's names updated --- samples/smoketest/CosmosDB.py | 22 +++++++++++----------- samples/smoketest/EventHubs.py | 8 ++++---- samples/smoketest/KeyVaultSecrets.py | 12 ++++++------ samples/smoketest/StorageBlobs.py | 14 +++++++------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/samples/smoketest/CosmosDB.py b/samples/smoketest/CosmosDB.py index 8e199fb545d6..7bfd7fa9fa64 100644 --- a/samples/smoketest/CosmosDB.py +++ b/samples/smoketest/CosmosDB.py @@ -9,18 +9,18 @@ def __init__(self): KEY = os.environ["COSMOS_KEY"] self.client = cosmos_client.CosmosClient(URL,{'masterKey': KEY}) - def createDatabase(self): + def CreateDatabase(self): dbName="pySolarSystem" print("Creating '{0}' database...".format(dbName)) return self.client.create_database(dbName) - def createContainer(self, db): + def CreateContainer(self, db): collectionName = "Planets" print("Creating '{0}' collection...".format(collectionName)) partition_key = PartitionKey(path='/id', kind='Hash') return db.create_container(id="Planets", partition_key=partition_key) - def createDocuments(self, container): + def CreateDocuments(self, container): planets = [] # Cosmos will look for an 'id' field in the items, if the 'id' is not specify Cosmos is going to assing a random key. @@ -57,7 +57,7 @@ def createDocuments(self, container): print("\t'{0}' created".format(planet['id'])) print("\tdone") - def simpleQuery(self, container): + def SimpleQuery(self, container): print("Quering the container...") items = list(container.query_items( query="SELECT c.id FROM c", @@ -65,7 +65,7 @@ def simpleQuery(self, container): )) print("\tdone: {0}".format(items)) - def deleteDatabase(self): + def DeleteDatabase(self): print("Cleaning up the resource...") self.client.delete_database("pySolarSystem") print("\tdone") @@ -83,15 +83,15 @@ def Run(self): # Ensure that the database does not exists try: - self.deleteDatabase() + self.DeleteDatabase() except: pass try: - db = self.createDatabase() - container = self.createContainer(db=db) - self.createDocuments(container=container) - self.simpleQuery(container=container) + db = self.CreateDatabase() + container = self.CreateContainer(db=db) + self.CreateDocuments(container=container) + self.SimpleQuery(container=container) finally: # if something goes wrong, the resource should be cleaned anyway - self.deleteDatabase() \ No newline at end of file + self.DeleteDatabase() \ No newline at end of file diff --git a/samples/smoketest/EventHubs.py b/samples/smoketest/EventHubs.py index 652af75d0c7a..350866475b85 100644 --- a/samples/smoketest/EventHubs.py +++ b/samples/smoketest/EventHubs.py @@ -10,13 +10,13 @@ def __init__(self): eventHubName = 'myeventhub' self.client = EventHubClient.from_connection_string(connectionString, eventHubName) - def getPartitionIds(self): + def GetPartitionIds(self): print("Getting partitions id...") partition_ids = self.client.get_partition_ids() print("\tdone") return partition_ids - def sendAndReceiveEvents(self, partitionID): + def SendAndReceiveEvents(self, partitionID): consumer = self.client.create_consumer(consumer_group="$default", partition_id=partitionID, event_position=EventPosition(datetime.utcnow())) print("Sending events...") @@ -46,7 +46,7 @@ def Run(self): print("3) Consume Events") print() - partitionID = self.getPartitionIds() + partitionID = self.GetPartitionIds() #In this sample the same partition id is going to be used for the producer and consumer, #It is the first one, but it could be any (is not relevant as long as it is the same in both producer and consumer) - self.sendAndReceiveEvents(partitionID[0]) \ No newline at end of file + self.SendAndReceiveEvents(partitionID[0]) \ No newline at end of file diff --git a/samples/smoketest/KeyVaultSecrets.py b/samples/smoketest/KeyVaultSecrets.py index f9b1c26b1d5a..9579940b8f49 100644 --- a/samples/smoketest/KeyVaultSecrets.py +++ b/samples/smoketest/KeyVaultSecrets.py @@ -11,17 +11,17 @@ def __init__(self): credential = DefaultAzureCredential() self.secret_client = SecretClient(vault_url=os.environ["AZURE_PROJECT_URL"], credential=credential) - def setSecret(self): + def SetSecret(self): print("Setting a secret...") self.secret_client.set_secret("secret-name", "secret-value") print("\tdone") - def getSecret(self): + def GetSecret(self): print("Getting a secret...") secret = self.secret_client.get_secret("secret-name") print("\tdone: " + secret.name) - def deleteSecret(self): + def DeleteSecret(self): print("Deleting a secret...") deleted_secret = self.secret_client.delete_secret("secret-name") print("\tdone: " + deleted_secret.name) @@ -37,7 +37,7 @@ def Run(self): print() try: - self.setSecret() - self.getSecret() + self.SetSecret() + self.GetSecret() finally: - self.deleteSecret() \ No newline at end of file + self.DeleteSecret() \ No newline at end of file diff --git a/samples/smoketest/StorageBlobs.py b/samples/smoketest/StorageBlobs.py index 1a7a246054a1..dd1864885dfc 100644 --- a/samples/smoketest/StorageBlobs.py +++ b/samples/smoketest/StorageBlobs.py @@ -6,20 +6,20 @@ def __init__(self): connectionString = os.environ["STORAGE_CONNECTION_STRING"] self.blob = BlobClient.from_connection_string(connectionString, container="mycontainer", blob="pyTestBlob.txt") - def uploadBLob(self): + def UploadBLob(self): print("uploading blob...") self.data = "This is a sample data for Python Test" self.blob.upload_blob(self.data) print("\tdone") - def downloadBlob(self): + def DownloadBlob(self): print("downloading blob...") with open("./downloadedBlob.txt", "wb+") as my_blob: my_blob.writelines(self.blob.download_blob()) print("\tdone") - def deleteBlob(self): + def DeleteBlob(self): print("Cleaning up the resource...") self.blob.delete_blob() print("\tdone") @@ -36,12 +36,12 @@ def Run(self): #Ensure that the blob does not exists before the tests try: - self.deleteBlob() + self.DeleteBlob() except: pass try: - self.uploadBLob() - self.downloadBlob() + self.UploadBLob() + self.DownloadBlob() finally: - self.deleteBlob() \ No newline at end of file + self.DeleteBlob() \ No newline at end of file From 1b5ef9a009990ddbcf6d29b2d4b06e0719605f48 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Thu, 18 Jul 2019 20:07:11 -0700 Subject: [PATCH 04/26] Create README.md --- samples/README.md | 116 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 samples/README.md diff --git a/samples/README.md b/samples/README.md new file mode 100644 index 000000000000..dff5d1177395 --- /dev/null +++ b/samples/README.md @@ -0,0 +1,116 @@ +# Azure Smoke Tests for Python +This sample code is a smoke test to ensure that Azure Preview for JS work while loaded into the same process by performing 2 or more actions with them. + +Libraries tested: +* keyvault-secrets +* identity +* storage-blob +* event-hubs +* cosmos + +## Getting started +### Setup Azure resources +For this sample, it is necessary to create/have the following resources in the [Azure Portal](https://portal.azure.com/): +* **App registration**: Register a new app or use an existing one. + * Under _Certificates & secrets_ create a new **client secret** and store the value in a safe place. +* **Key Vaults**: Create a new Key Vault resource or use an existing one. + * Under _Access policies_, add the app registrated in the previous step. +* **Storage acounts**: Create a container in a new or existing storage account. The container in this sample is named "mycontainer", if you want to use other name you can change the value in `BlobStorage.ts` file: +`const containerName = "mycontainer";` +* **Event Hubs**: Create an event hub inside a new or existing Event Hubs Namespace. The container in this sample is named "myeventhub", if you want to use other name you can change the value in `EventHubsTest.ts` file: `let eventHubName = "myeventhub";` +* **Azure Cosmos DB**: Create a new account or use an existing one. + +### Azure credentials +The following environment variables are needed: +* From **App Registration**, in the _Overview_ section: + * AZURE_TENANT_ID: The directory tentant ID. + * AZURE_CLIENT_ID: The application ID. + * AZURE_CLIENT_SECRET: The client secret stored previusly when creating the _client secret_. + +* From **Key Vault**, in the _Overview_ section: + * AZURE_PROJECT_URL: The DNS Name + +* From **Event Hubs**, in _Shared access policies_ section: + * EVENT_HUBS_CONNECTION_STRING: Connection string from a policy + +* From **Storage Account**, in the _Access Keys_ section: + * STORAGE_CONNECTION_STRING : A connection strings. + +* From **Azure Cosmos DB**, in the _Keys_ section, select the _Read-Write Keys_ tab: + * COSMOS_ENDPOINT: URI. + * COSMOS_KEY: Primary or secondary key. + +``` +//Bash code to create the environment variables +export AZURE_CLIENT_ID="" +export AZURE_CLIENT_SECRET="" +export AZURE_TENANT_ID="" +export EVENT_HUBS_CONNECTION_STRING="" +export AZURE_PROJECT_URL="" +export STORAGE_CONNECTION_STRING="" +export COSMOS_ENDPOINT="" +export COSMOS_KEY="" +``` + +### Running the console app +[Python](https://nodejs.org/en/) version 3.7.4 was used to run this sample. + +In the \SmokeTest\ directory, run Program.py +``` +python .\Program.py +``` + +## Key Concepts + + +## Examples +All the classes in this sample has a `Run()` method as entry point, and do not depend on each other. + +It is possible to run them individually: +```python +from KeyVaultSecrets import KeyVault + +KeyVault().Run() +``` + +They can be included in other projects by moving the class in it: +```python +from KeyVaultSecrets import KeyVault + +... + +def myTests(): + console.log("Smoke Test imported from other project") + KeyVault().Run() + +myTests() +otherFunction() +... +``` + +The classes can be used as base code and be changed to satisfied specific needs. For example, the method `EventHub().SendAndReceiveEvents()` can be change to only send events from an array given from a parameter: +```python +def SendAndReceiveEvents(self, partitionID, events): + producer = self.client.create_producer(partition_id=partitionID) + producer.send(events) + producer.close() +``` + +**Note:** The methods in the classes are not necessary independent on each other, and the order matters. For example, in order to run `BlobStorage().DeleteBlob();`, the method `BlobStorage().UploadBLob();` must be run before, since in the other way it will fail because there is not going to be a blob to delete. + +## Troubleshooting + +### Authentification +Be sure to set the environment variables and credentials required before running the sample. + +## Next steps +Check the [Azure SDK for Python Repository](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk) for more samples inside the sdk folder. + +## Contributing +This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com. + +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. + +If you'd like to contribute to this library, please read the contributing guide to learn more about how to build and test the code. + +This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments. \ No newline at end of file From aee43e1e2fd6c21a50859c469c3ae5a40a36f50e Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Thu, 18 Jul 2019 20:07:35 -0700 Subject: [PATCH 05/26] Update README.md --- samples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/README.md b/samples/README.md index dff5d1177395..58fb5f098e41 100644 --- a/samples/README.md +++ b/samples/README.md @@ -1,5 +1,5 @@ # Azure Smoke Tests for Python -This sample code is a smoke test to ensure that Azure Preview for JS work while loaded into the same process by performing 2 or more actions with them. +This sample code is a smoke test to ensure that Azure Preview for Python work while loaded into the same process by performing 2 or more actions with them. Libraries tested: * keyvault-secrets From 97e4f603a2a1852292069fd267f6044e1d5a8e69 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Thu, 18 Jul 2019 20:08:13 -0700 Subject: [PATCH 06/26] Commented lines deleted --- samples/smoketest/Program.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/samples/smoketest/Program.py b/samples/smoketest/Program.py index f2a4649fa083..998174240f7a 100644 --- a/samples/smoketest/Program.py +++ b/samples/smoketest/Program.py @@ -1,5 +1,3 @@ -# from azure.identity import DefaultAzureCredential -# from azure.keyvault.secrets import SecretClient from KeyVaultSecrets import KeyVault from StorageBlobs import StorageBlob from EventHubs import EventHub From c587a82fa64455b58da7dd4d4200ec0ffa769398 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Fri, 19 Jul 2019 10:30:19 -0700 Subject: [PATCH 07/26] README.md moved to correct folder --- samples/{ => smoketest}/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename samples/{ => smoketest}/README.md (99%) diff --git a/samples/README.md b/samples/smoketest/README.md similarity index 99% rename from samples/README.md rename to samples/smoketest/README.md index 58fb5f098e41..ebcf2cb31e67 100644 --- a/samples/README.md +++ b/samples/smoketest/README.md @@ -100,7 +100,7 @@ def SendAndReceiveEvents(self, partitionID, events): ## Troubleshooting -### Authentification +### Authentication Be sure to set the environment variables and credentials required before running the sample. ## Next steps From 7909abd5c49786544a2759229bf5f6bd64d96595 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Mon, 22 Jul 2019 11:18:22 -0700 Subject: [PATCH 08/26] Create requirements.txt --- samples/smoketest/requirements.txt | Bin 0 -> 418 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 samples/smoketest/requirements.txt diff --git a/samples/smoketest/requirements.txt b/samples/smoketest/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..9eb5fb61983475430c48d5e36a9e79ae286fe706 GIT binary patch literal 418 zcma)&;R?ba6h_bQphq#bRX=+ew?>WDgj~UT`0CS&KuSUcm2>X>y!V^s%9#@_h6cw` z%Q3LgDp|x`v1HDSlnvIKE5sJm;=hqTR`royMe-Nja#7WRk-c)&(O74Vj_u3nWKDl0 wI*6at$Ergw$KdtS#3_tAhd Date: Mon, 22 Jul 2019 11:18:36 -0700 Subject: [PATCH 09/26] Update README.md --- samples/smoketest/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/smoketest/README.md b/samples/smoketest/README.md index ebcf2cb31e67..c8c56c0fbb58 100644 --- a/samples/smoketest/README.md +++ b/samples/smoketest/README.md @@ -1,4 +1,4 @@ -# Azure Smoke Tests for Python +# Azure Smoke Test for Python This sample code is a smoke test to ensure that Azure Preview for Python work while loaded into the same process by performing 2 or more actions with them. Libraries tested: From 81d389e83bbf885a0171ae9f29159522a8b6bbcb Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 14:17:47 -0700 Subject: [PATCH 10/26] Update README.md --- samples/smoketest/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/smoketest/README.md b/samples/smoketest/README.md index c8c56c0fbb58..145cea66289f 100644 --- a/samples/smoketest/README.md +++ b/samples/smoketest/README.md @@ -53,7 +53,7 @@ export COSMOS_KEY="" ``` ### Running the console app -[Python](https://nodejs.org/en/) version 3.7.4 was used to run this sample. +[Python](https://www.python.org/downloads/) version 3.7.4 was used to run this sample. In the \SmokeTest\ directory, run Program.py ``` From ab8fa9dc8fbca00bc55a3babe9fbebb70fac3325 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 15:00:14 -0700 Subject: [PATCH 11/26] Imports changed --- samples/smoketest/CosmosDB.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/samples/smoketest/CosmosDB.py b/samples/smoketest/CosmosDB.py index 7bfd7fa9fa64..e03574932d42 100644 --- a/samples/smoketest/CosmosDB.py +++ b/samples/smoketest/CosmosDB.py @@ -1,5 +1,4 @@ -import azure.cosmos.cosmos_client as cosmos_client -import azure.cosmos.errors as errors +from azure.cosmos import CosmosClient from azure.cosmos.partition_key import PartitionKey import os @@ -7,7 +6,7 @@ class CosmosDB: def __init__(self): URL = os.environ["COSMOS_ENDPOINT"] KEY = os.environ["COSMOS_KEY"] - self.client = cosmos_client.CosmosClient(URL,{'masterKey': KEY}) + self.client = CosmosClient(URL,{'masterKey': KEY}) def CreateDatabase(self): dbName="pySolarSystem" From e7f7346055ccc0b318ac96caab9b1f0871ff28ba Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 15:13:50 -0700 Subject: [PATCH 12/26] Use of literals instead of append --- samples/smoketest/CosmosDB.py | 37 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/samples/smoketest/CosmosDB.py b/samples/smoketest/CosmosDB.py index e03574932d42..0ee180dd8afd 100644 --- a/samples/smoketest/CosmosDB.py +++ b/samples/smoketest/CosmosDB.py @@ -20,10 +20,9 @@ def CreateContainer(self, db): return db.create_container(id="Planets", partition_key=partition_key) def CreateDocuments(self, container): - planets = [] - # Cosmos will look for an 'id' field in the items, if the 'id' is not specify Cosmos is going to assing a random key. - planets.append({ + planets = [ + { 'id' : "Earth", 'HasRings' : False, 'Radius' : 3959, @@ -33,22 +32,22 @@ def CreateDocuments(self, container): 'Name' : "Moon" } ] - }) - - planets.append({ - "id" : "Mars", - "HasRings" : False, - "Radius" : 2106, - "Moons" : - [ - { - "Name" : "Phobos" - }, - { - "Name" : "Deimos" - } - ] - }) + }, + { + "id" : "Mars", + "HasRings" : False, + "Radius" : 2106, + "Moons" : + [ + { + "Name" : "Phobos" + }, + { + "Name" : "Deimos" + } + ] + } + ] print("Inserting items in the collection...") for planet in planets: From 7066da036ce3087efeb3f0f6fdee718c9e27a956 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 15:16:28 -0700 Subject: [PATCH 13/26] Database Name variable to class level. --- samples/smoketest/CosmosDB.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/smoketest/CosmosDB.py b/samples/smoketest/CosmosDB.py index 0ee180dd8afd..52457652ca29 100644 --- a/samples/smoketest/CosmosDB.py +++ b/samples/smoketest/CosmosDB.py @@ -7,11 +7,11 @@ def __init__(self): URL = os.environ["COSMOS_ENDPOINT"] KEY = os.environ["COSMOS_KEY"] self.client = CosmosClient(URL,{'masterKey': KEY}) + self.dbName="pySolarSystem" def CreateDatabase(self): - dbName="pySolarSystem" - print("Creating '{0}' database...".format(dbName)) - return self.client.create_database(dbName) + print("Creating '{0}' database...".format(self.dbName)) + return self.client.create_database(self.dbName) def CreateContainer(self, db): collectionName = "Planets" @@ -65,7 +65,7 @@ def SimpleQuery(self, container): def DeleteDatabase(self): print("Cleaning up the resource...") - self.client.delete_database("pySolarSystem") + self.client.delete_database(self.dbName) print("\tdone") def Run(self): From 81adc4ca46f67d3a068aeee5e41c4514d63d8758 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 15:27:59 -0700 Subject: [PATCH 14/26] Use of Pythonic with statements --- samples/smoketest/EventHubs.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/samples/smoketest/EventHubs.py b/samples/smoketest/EventHubs.py index 350866475b85..8c8afc547e32 100644 --- a/samples/smoketest/EventHubs.py +++ b/samples/smoketest/EventHubs.py @@ -17,24 +17,25 @@ def GetPartitionIds(self): return partition_ids def SendAndReceiveEvents(self, partitionID): - consumer = self.client.create_consumer(consumer_group="$default", partition_id=partitionID, event_position=EventPosition(datetime.utcnow())) + with self.client.create_consumer(consumer_group="$default", partition_id=partitionID, event_position=EventPosition(datetime.utcnow())) as consumer: - print("Sending events...") - producer = self.client.create_producer(partition_id=partitionID) - event_list = [EventData(b"Test Event 1 in Python"),EventData(b"Test Event 2 in Python"),EventData(b"Test Event 3 in Python")] - producer.send(event_list) - producer.close() - print("\tdone") - - print("Receiving events...") - received = consumer.receive(max_batch_size=len(event_list), timeout=2) - for event_data in received: - print("\tEvent Received: " + event_data.body_as_str()) - consumer.close() - print("\tdone") + print("Sending events...") + with self.client.create_producer(partition_id=partitionID) as producer: + event_list = [ + EventData(b"Test Event 1 in Python"), + EventData(b"Test Event 2 in Python"),EventData(b"Test Event 3 in Python")] + producer.send(event_list) + print("\tdone") + + print("Receiving events...") + received = consumer.receive(max_batch_size=len(event_list), timeout=2) + for event_data in received: + print("\tEvent Received: " + event_data.body_as_str()) + + print("\tdone") - if(len(received) != len(event_list)): - raise Exception("Error, expecting {0} events, but {1} were received.".format(str(len(event_list)),str(len(received)))) + if(len(received) != len(event_list)): + raise Exception("Error, expecting {0} events, but {1} were received.".format(str(len(event_list)),str(len(received)))) def Run(self): print() From 4b79c6a84780f169e15c17d96e5728f32ed419f3 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 15:30:28 -0700 Subject: [PATCH 15/26] Update requirements.txt --- samples/smoketest/requirements.txt | Bin 418 -> 414 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/samples/smoketest/requirements.txt b/samples/smoketest/requirements.txt index 9eb5fb61983475430c48d5e36a9e79ae286fe706..64546b8831c482d7cfbe27dd5c9a5fe8a47a3e02 100644 GIT binary patch delta 7 OcmZ3)Jdb(9JVpQt_5zjw delta 12 TcmbQoyoh Date: Tue, 23 Jul 2019 15:30:40 -0700 Subject: [PATCH 16/26] Revert "Update requirements.txt" This reverts commit 4b79c6a84780f169e15c17d96e5728f32ed419f3. --- samples/smoketest/requirements.txt | Bin 414 -> 418 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/samples/smoketest/requirements.txt b/samples/smoketest/requirements.txt index 64546b8831c482d7cfbe27dd5c9a5fe8a47a3e02..9eb5fb61983475430c48d5e36a9e79ae286fe706 100644 GIT binary patch delta 12 TcmbQoyoh Date: Tue, 23 Jul 2019 15:30:58 -0700 Subject: [PATCH 17/26] Revert "Use of Pythonic with statements" This reverts commit 81adc4ca46f67d3a068aeee5e41c4514d63d8758. --- samples/smoketest/EventHubs.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/samples/smoketest/EventHubs.py b/samples/smoketest/EventHubs.py index 8c8afc547e32..350866475b85 100644 --- a/samples/smoketest/EventHubs.py +++ b/samples/smoketest/EventHubs.py @@ -17,25 +17,24 @@ def GetPartitionIds(self): return partition_ids def SendAndReceiveEvents(self, partitionID): - with self.client.create_consumer(consumer_group="$default", partition_id=partitionID, event_position=EventPosition(datetime.utcnow())) as consumer: + consumer = self.client.create_consumer(consumer_group="$default", partition_id=partitionID, event_position=EventPosition(datetime.utcnow())) - print("Sending events...") - with self.client.create_producer(partition_id=partitionID) as producer: - event_list = [ - EventData(b"Test Event 1 in Python"), - EventData(b"Test Event 2 in Python"),EventData(b"Test Event 3 in Python")] - producer.send(event_list) - print("\tdone") - - print("Receiving events...") - received = consumer.receive(max_batch_size=len(event_list), timeout=2) - for event_data in received: - print("\tEvent Received: " + event_data.body_as_str()) - - print("\tdone") + print("Sending events...") + producer = self.client.create_producer(partition_id=partitionID) + event_list = [EventData(b"Test Event 1 in Python"),EventData(b"Test Event 2 in Python"),EventData(b"Test Event 3 in Python")] + producer.send(event_list) + producer.close() + print("\tdone") + + print("Receiving events...") + received = consumer.receive(max_batch_size=len(event_list), timeout=2) + for event_data in received: + print("\tEvent Received: " + event_data.body_as_str()) + consumer.close() + print("\tdone") - if(len(received) != len(event_list)): - raise Exception("Error, expecting {0} events, but {1} were received.".format(str(len(event_list)),str(len(received)))) + if(len(received) != len(event_list)): + raise Exception("Error, expecting {0} events, but {1} were received.".format(str(len(event_list)),str(len(received)))) def Run(self): print() From 4c2d73def2cd26a3006ab37c98be287cd9414c2f Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 15:31:27 -0700 Subject: [PATCH 18/26] Revert "Revert "Use of Pythonic with statements"" This reverts commit 27b2a2d635ff47880dee2c741bcb5c81c187df7d. --- samples/smoketest/EventHubs.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/samples/smoketest/EventHubs.py b/samples/smoketest/EventHubs.py index 350866475b85..8c8afc547e32 100644 --- a/samples/smoketest/EventHubs.py +++ b/samples/smoketest/EventHubs.py @@ -17,24 +17,25 @@ def GetPartitionIds(self): return partition_ids def SendAndReceiveEvents(self, partitionID): - consumer = self.client.create_consumer(consumer_group="$default", partition_id=partitionID, event_position=EventPosition(datetime.utcnow())) + with self.client.create_consumer(consumer_group="$default", partition_id=partitionID, event_position=EventPosition(datetime.utcnow())) as consumer: - print("Sending events...") - producer = self.client.create_producer(partition_id=partitionID) - event_list = [EventData(b"Test Event 1 in Python"),EventData(b"Test Event 2 in Python"),EventData(b"Test Event 3 in Python")] - producer.send(event_list) - producer.close() - print("\tdone") - - print("Receiving events...") - received = consumer.receive(max_batch_size=len(event_list), timeout=2) - for event_data in received: - print("\tEvent Received: " + event_data.body_as_str()) - consumer.close() - print("\tdone") + print("Sending events...") + with self.client.create_producer(partition_id=partitionID) as producer: + event_list = [ + EventData(b"Test Event 1 in Python"), + EventData(b"Test Event 2 in Python"),EventData(b"Test Event 3 in Python")] + producer.send(event_list) + print("\tdone") + + print("Receiving events...") + received = consumer.receive(max_batch_size=len(event_list), timeout=2) + for event_data in received: + print("\tEvent Received: " + event_data.body_as_str()) + + print("\tdone") - if(len(received) != len(event_list)): - raise Exception("Error, expecting {0} events, but {1} were received.".format(str(len(event_list)),str(len(received)))) + if(len(received) != len(event_list)): + raise Exception("Error, expecting {0} events, but {1} were received.".format(str(len(event_list)),str(len(received)))) def Run(self): print() From 15e025e37a92626c421d9bbfa323d5ed9fb9dfed Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 15:33:36 -0700 Subject: [PATCH 19/26] requiriments.txt encoded as a txt file --- samples/smoketest/requirements.txt | Bin 418 -> 0 bytes samples/smoketest/requiriments.txt | 8 ++++++++ 2 files changed, 8 insertions(+) delete mode 100644 samples/smoketest/requirements.txt create mode 100644 samples/smoketest/requiriments.txt diff --git a/samples/smoketest/requirements.txt b/samples/smoketest/requirements.txt deleted file mode 100644 index 9eb5fb61983475430c48d5e36a9e79ae286fe706..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 418 zcma)&;R?ba6h_bQphq#bRX=+ew?>WDgj~UT`0CS&KuSUcm2>X>y!V^s%9#@_h6cw` z%Q3LgDp|x`v1HDSlnvIKE5sJm;=hqTR`royMe-Nja#7WRk-c)&(O74Vj_u3nWKDl0 wI*6at$Ergw$KdtS#3_tAhd Date: Tue, 23 Jul 2019 15:38:41 -0700 Subject: [PATCH 20/26] requirements.txt as text file --- samples/smoketest/{requiriments.txt => requirements.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename samples/smoketest/{requiriments.txt => requirements.txt} (100%) diff --git a/samples/smoketest/requiriments.txt b/samples/smoketest/requirements.txt similarity index 100% rename from samples/smoketest/requiriments.txt rename to samples/smoketest/requirements.txt From 22927ad48a3cdb29e90d6f47e60574e2f7c435d9 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 15:39:44 -0700 Subject: [PATCH 21/26] Misspelling in "Key concepts" --- samples/smoketest/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/smoketest/README.md b/samples/smoketest/README.md index 145cea66289f..6e0a21c70235 100644 --- a/samples/smoketest/README.md +++ b/samples/smoketest/README.md @@ -60,7 +60,7 @@ In the \SmokeTest\ directory, run Program.py python .\Program.py ``` -## Key Concepts +## Key concepts ## Examples From 17a53cb7f7bc43e9284d4663d53df8d6360425dc Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 15:44:38 -0700 Subject: [PATCH 22/26] Update .docsettings.yml to match the tittle of Smoke Test --- .docsettings.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.docsettings.yml b/.docsettings.yml index 317e26b199cd..a8b9d07e4c40 100644 --- a/.docsettings.yml +++ b/.docsettings.yml @@ -9,7 +9,7 @@ omitted_paths: language: python root_check_enabled: True required_readme_sections: - - "Azure .+ client library for Python" + - ^Azure (.+ client library for Python|Smoke Test for Python) - ^Getting started$ - ^Key concepts$ - ^Examples$ From 35c62232f8e0562087b7f5eb3d4bdf57ea6e502f Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 17:36:23 -0700 Subject: [PATCH 23/26] Went trought Suyog comments --- .vscode/settings.json | 5 ++- samples/smoketest/CosmosDB.py | 64 +++++++++++----------------- samples/smoketest/EventHubs.py | 39 +++++++++++------ samples/smoketest/KeyVaultSecrets.py | 9 ++-- samples/smoketest/Program.py | 2 +- samples/smoketest/StorageBlobs.py | 22 ++++++---- 6 files changed, 75 insertions(+), 66 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 86be745c112b..f98cf3d50a74 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "git.ignoreLimitWarning": true, - "python.unitTest.pyTestArgs": [], - "python.unitTest.pyTestEnabled": true + "python.testing.pytestArgs": [], + "python.testing.pytestEnabled": true, + "python.formatting.provider": "black" } \ No newline at end of file diff --git a/samples/smoketest/CosmosDB.py b/samples/smoketest/CosmosDB.py index 52457652ca29..d1ddc62392e0 100644 --- a/samples/smoketest/CosmosDB.py +++ b/samples/smoketest/CosmosDB.py @@ -1,13 +1,13 @@ +import os from azure.cosmos import CosmosClient from azure.cosmos.partition_key import PartitionKey -import os class CosmosDB: def __init__(self): URL = os.environ["COSMOS_ENDPOINT"] KEY = os.environ["COSMOS_KEY"] - self.client = CosmosClient(URL,{'masterKey': KEY}) - self.dbName="pySolarSystem" + self.client = CosmosClient(URL, {"masterKey": KEY}) + self.dbName = "pySolarSystem" def CreateDatabase(self): print("Creating '{0}' database...".format(self.dbName)) @@ -16,53 +16,41 @@ def CreateDatabase(self): def CreateContainer(self, db): collectionName = "Planets" print("Creating '{0}' collection...".format(collectionName)) - partition_key = PartitionKey(path='/id', kind='Hash') + partition_key = PartitionKey(path="/id", kind="Hash") return db.create_container(id="Planets", partition_key=partition_key) def CreateDocuments(self, container): # Cosmos will look for an 'id' field in the items, if the 'id' is not specify Cosmos is going to assing a random key. planets = [ { - 'id' : "Earth", - 'HasRings' : False, - 'Radius' : 3959, - 'Moons' : - [ - { - 'Name' : "Moon" - } - ] - }, + "id": "Earth", + "HasRings": False, + "Radius": 3959, + "Moons": [{"Name": "Moon"}], + }, { - "id" : "Mars", - "HasRings" : False, - "Radius" : 2106, - "Moons" : - [ - { - "Name" : "Phobos" - }, - { - "Name" : "Deimos" - } - ] - } - ] + "id": "Mars", + "HasRings": False, + "Radius": 2106, + "Moons": [{"Name": "Phobos"}, {"Name": "Deimos"}], + }, + ] print("Inserting items in the collection...") for planet in planets: container.create_item(planet) - print("\t'{0}' created".format(planet['id'])) + print("\t'{0}' created".format(planet["id"])) print("\tdone") def SimpleQuery(self, container): print("Quering the container...") - items = list(container.query_items( - query="SELECT c.id FROM c", - enable_cross_partition_query = True - )) + items = list( + container.query_items( + query="SELECT c.id FROM c", enable_cross_partition_query=True + ) + ) print("\tdone: {0}".format(items)) - + def DeleteDatabase(self): print("Cleaning up the resource...") self.client.delete_database(self.dbName) @@ -78,18 +66,18 @@ def Run(self): print("3) Insert Documents (items) into the Container") print("4) Delete Database (Clean up the resource)") print() - + # Ensure that the database does not exists try: self.DeleteDatabase() except: pass - + try: db = self.CreateDatabase() container = self.CreateContainer(db=db) self.CreateDocuments(container=container) - self.SimpleQuery(container=container) + self.SimpleQuery(container=container) finally: # if something goes wrong, the resource should be cleaned anyway - self.DeleteDatabase() \ No newline at end of file + self.DeleteDatabase() diff --git a/samples/smoketest/EventHubs.py b/samples/smoketest/EventHubs.py index 8c8afc547e32..9a0ed400b5c5 100644 --- a/samples/smoketest/EventHubs.py +++ b/samples/smoketest/EventHubs.py @@ -1,32 +1,41 @@ -from azure.eventhub import EventHubClient, EventData, EventPosition -from datetime import datetime import os +from datetime import datetime +from azure.eventhub import EventHubClient, EventData, EventPosition + class EventHub: def __init__(self): # This test requires a previusly created Event Hub. # In this example the name is "myeventhub", but it could be change below connectionString = os.environ["EVENT_HUBS_CONNECTION_STRING"] - eventHubName = 'myeventhub' - self.client = EventHubClient.from_connection_string(connectionString, eventHubName) + eventHubName = "myeventhub" + self.client = EventHubClient.from_connection_string( + connectionString, eventHubName + ) def GetPartitionIds(self): print("Getting partitions id...") partition_ids = self.client.get_partition_ids() print("\tdone") - return partition_ids + return partition_ids def SendAndReceiveEvents(self, partitionID): - with self.client.create_consumer(consumer_group="$default", partition_id=partitionID, event_position=EventPosition(datetime.utcnow())) as consumer: + with self.client.create_consumer( + consumer_group="$default", + partition_id=partitionID, + event_position=EventPosition(datetime.utcnow()), + ) as consumer: print("Sending events...") with self.client.create_producer(partition_id=partitionID) as producer: event_list = [ EventData(b"Test Event 1 in Python"), - EventData(b"Test Event 2 in Python"),EventData(b"Test Event 3 in Python")] + EventData(b"Test Event 2 in Python"), + EventData(b"Test Event 3 in Python"), + ] producer.send(event_list) print("\tdone") - + print("Receiving events...") received = consumer.receive(max_batch_size=len(event_list), timeout=2) for event_data in received: @@ -34,8 +43,12 @@ def SendAndReceiveEvents(self, partitionID): print("\tdone") - if(len(received) != len(event_list)): - raise Exception("Error, expecting {0} events, but {1} were received.".format(str(len(event_list)),str(len(received)))) + if len(received) != len(event_list): + raise Exception( + "Error, expecting {0} events, but {1} were received.".format( + str(len(event_list)), str(len(received)) + ) + ) def Run(self): print() @@ -48,6 +61,6 @@ def Run(self): print() partitionID = self.GetPartitionIds() - #In this sample the same partition id is going to be used for the producer and consumer, - #It is the first one, but it could be any (is not relevant as long as it is the same in both producer and consumer) - self.SendAndReceiveEvents(partitionID[0]) \ No newline at end of file + # In this sample the same partition id is going to be used for the producer and consumer, + # It is the first one, but it could be any (is not relevant as long as it is the same in both producer and consumer) + self.SendAndReceiveEvents(partitionID[0]) diff --git a/samples/smoketest/KeyVaultSecrets.py b/samples/smoketest/KeyVaultSecrets.py index 9579940b8f49..7f27b02460f1 100644 --- a/samples/smoketest/KeyVaultSecrets.py +++ b/samples/smoketest/KeyVaultSecrets.py @@ -1,6 +1,7 @@ +import os from azure.identity import DefaultAzureCredential from azure.keyvault.secrets import SecretClient -import os + class KeyVault: def __init__(self): @@ -9,7 +10,9 @@ def __init__(self): # * AZURE_CLIENT_SECRET # * AZURE_TENANT_ID credential = DefaultAzureCredential() - self.secret_client = SecretClient(vault_url=os.environ["AZURE_PROJECT_URL"], credential=credential) + self.secret_client = SecretClient( + vault_url=os.environ["AZURE_PROJECT_URL"], credential=credential + ) def SetSecret(self): print("Setting a secret...") @@ -40,4 +43,4 @@ def Run(self): self.SetSecret() self.GetSecret() finally: - self.DeleteSecret() \ No newline at end of file + self.DeleteSecret() diff --git a/samples/smoketest/Program.py b/samples/smoketest/Program.py index 998174240f7a..f63139d9d0d8 100644 --- a/samples/smoketest/Program.py +++ b/samples/smoketest/Program.py @@ -10,4 +10,4 @@ KeyVault().Run() StorageBlob().Run() EventHub().Run() -CosmosDB().Run() \ No newline at end of file +CosmosDB().Run() diff --git a/samples/smoketest/StorageBlobs.py b/samples/smoketest/StorageBlobs.py index dd1864885dfc..48fe3bc17546 100644 --- a/samples/smoketest/StorageBlobs.py +++ b/samples/smoketest/StorageBlobs.py @@ -1,15 +1,19 @@ -from azure.storage.blob import BlobClient import os +from azure.storage.blob import BlobClient +from azure.core import exceptions + class StorageBlob: def __init__(self): connectionString = os.environ["STORAGE_CONNECTION_STRING"] - self.blob = BlobClient.from_connection_string(connectionString, container="mycontainer", blob="pyTestBlob.txt") + self.blob = BlobClient.from_connection_string( + connectionString, container="mycontainer", blob="pyTestBlob.txt" + ) def UploadBLob(self): print("uploading blob...") - self.data = "This is a sample data for Python Test" - self.blob.upload_blob(self.data) + data = "This is a sample data for Python Test" + self.blob.upload_blob(data) print("\tdone") def DownloadBlob(self): @@ -33,15 +37,15 @@ def Run(self): print("2) Download a Blob") print("3) Delete that Blob (Clean up the resource)") print() - - #Ensure that the blob does not exists before the tests + + # Ensure that the blob does not exists before the tests try: self.DeleteBlob() - except: + except exceptions.AzureError: pass - + try: self.UploadBLob() self.DownloadBlob() finally: - self.DeleteBlob() \ No newline at end of file + self.DeleteBlob() From ada5a74b80531d2399872b175001383fcd14050b Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 17:36:56 -0700 Subject: [PATCH 24/26] Revert "Went trought Suyog comments" This reverts commit 35c62232f8e0562087b7f5eb3d4bdf57ea6e502f. --- .vscode/settings.json | 5 +-- samples/smoketest/CosmosDB.py | 64 +++++++++++++++++----------- samples/smoketest/EventHubs.py | 39 ++++++----------- samples/smoketest/KeyVaultSecrets.py | 9 ++-- samples/smoketest/Program.py | 2 +- samples/smoketest/StorageBlobs.py | 22 ++++------ 6 files changed, 66 insertions(+), 75 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index f98cf3d50a74..86be745c112b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,5 @@ { "git.ignoreLimitWarning": true, - "python.testing.pytestArgs": [], - "python.testing.pytestEnabled": true, - "python.formatting.provider": "black" + "python.unitTest.pyTestArgs": [], + "python.unitTest.pyTestEnabled": true } \ No newline at end of file diff --git a/samples/smoketest/CosmosDB.py b/samples/smoketest/CosmosDB.py index d1ddc62392e0..52457652ca29 100644 --- a/samples/smoketest/CosmosDB.py +++ b/samples/smoketest/CosmosDB.py @@ -1,13 +1,13 @@ -import os from azure.cosmos import CosmosClient from azure.cosmos.partition_key import PartitionKey +import os class CosmosDB: def __init__(self): URL = os.environ["COSMOS_ENDPOINT"] KEY = os.environ["COSMOS_KEY"] - self.client = CosmosClient(URL, {"masterKey": KEY}) - self.dbName = "pySolarSystem" + self.client = CosmosClient(URL,{'masterKey': KEY}) + self.dbName="pySolarSystem" def CreateDatabase(self): print("Creating '{0}' database...".format(self.dbName)) @@ -16,41 +16,53 @@ def CreateDatabase(self): def CreateContainer(self, db): collectionName = "Planets" print("Creating '{0}' collection...".format(collectionName)) - partition_key = PartitionKey(path="/id", kind="Hash") + partition_key = PartitionKey(path='/id', kind='Hash') return db.create_container(id="Planets", partition_key=partition_key) def CreateDocuments(self, container): # Cosmos will look for an 'id' field in the items, if the 'id' is not specify Cosmos is going to assing a random key. planets = [ { - "id": "Earth", - "HasRings": False, - "Radius": 3959, - "Moons": [{"Name": "Moon"}], - }, + 'id' : "Earth", + 'HasRings' : False, + 'Radius' : 3959, + 'Moons' : + [ + { + 'Name' : "Moon" + } + ] + }, { - "id": "Mars", - "HasRings": False, - "Radius": 2106, - "Moons": [{"Name": "Phobos"}, {"Name": "Deimos"}], - }, - ] + "id" : "Mars", + "HasRings" : False, + "Radius" : 2106, + "Moons" : + [ + { + "Name" : "Phobos" + }, + { + "Name" : "Deimos" + } + ] + } + ] print("Inserting items in the collection...") for planet in planets: container.create_item(planet) - print("\t'{0}' created".format(planet["id"])) + print("\t'{0}' created".format(planet['id'])) print("\tdone") def SimpleQuery(self, container): print("Quering the container...") - items = list( - container.query_items( - query="SELECT c.id FROM c", enable_cross_partition_query=True - ) - ) + items = list(container.query_items( + query="SELECT c.id FROM c", + enable_cross_partition_query = True + )) print("\tdone: {0}".format(items)) - + def DeleteDatabase(self): print("Cleaning up the resource...") self.client.delete_database(self.dbName) @@ -66,18 +78,18 @@ def Run(self): print("3) Insert Documents (items) into the Container") print("4) Delete Database (Clean up the resource)") print() - + # Ensure that the database does not exists try: self.DeleteDatabase() except: pass - + try: db = self.CreateDatabase() container = self.CreateContainer(db=db) self.CreateDocuments(container=container) - self.SimpleQuery(container=container) + self.SimpleQuery(container=container) finally: # if something goes wrong, the resource should be cleaned anyway - self.DeleteDatabase() + self.DeleteDatabase() \ No newline at end of file diff --git a/samples/smoketest/EventHubs.py b/samples/smoketest/EventHubs.py index 9a0ed400b5c5..8c8afc547e32 100644 --- a/samples/smoketest/EventHubs.py +++ b/samples/smoketest/EventHubs.py @@ -1,41 +1,32 @@ -import os -from datetime import datetime from azure.eventhub import EventHubClient, EventData, EventPosition - +from datetime import datetime +import os class EventHub: def __init__(self): # This test requires a previusly created Event Hub. # In this example the name is "myeventhub", but it could be change below connectionString = os.environ["EVENT_HUBS_CONNECTION_STRING"] - eventHubName = "myeventhub" - self.client = EventHubClient.from_connection_string( - connectionString, eventHubName - ) + eventHubName = 'myeventhub' + self.client = EventHubClient.from_connection_string(connectionString, eventHubName) def GetPartitionIds(self): print("Getting partitions id...") partition_ids = self.client.get_partition_ids() print("\tdone") - return partition_ids + return partition_ids def SendAndReceiveEvents(self, partitionID): - with self.client.create_consumer( - consumer_group="$default", - partition_id=partitionID, - event_position=EventPosition(datetime.utcnow()), - ) as consumer: + with self.client.create_consumer(consumer_group="$default", partition_id=partitionID, event_position=EventPosition(datetime.utcnow())) as consumer: print("Sending events...") with self.client.create_producer(partition_id=partitionID) as producer: event_list = [ EventData(b"Test Event 1 in Python"), - EventData(b"Test Event 2 in Python"), - EventData(b"Test Event 3 in Python"), - ] + EventData(b"Test Event 2 in Python"),EventData(b"Test Event 3 in Python")] producer.send(event_list) print("\tdone") - + print("Receiving events...") received = consumer.receive(max_batch_size=len(event_list), timeout=2) for event_data in received: @@ -43,12 +34,8 @@ def SendAndReceiveEvents(self, partitionID): print("\tdone") - if len(received) != len(event_list): - raise Exception( - "Error, expecting {0} events, but {1} were received.".format( - str(len(event_list)), str(len(received)) - ) - ) + if(len(received) != len(event_list)): + raise Exception("Error, expecting {0} events, but {1} were received.".format(str(len(event_list)),str(len(received)))) def Run(self): print() @@ -61,6 +48,6 @@ def Run(self): print() partitionID = self.GetPartitionIds() - # In this sample the same partition id is going to be used for the producer and consumer, - # It is the first one, but it could be any (is not relevant as long as it is the same in both producer and consumer) - self.SendAndReceiveEvents(partitionID[0]) + #In this sample the same partition id is going to be used for the producer and consumer, + #It is the first one, but it could be any (is not relevant as long as it is the same in both producer and consumer) + self.SendAndReceiveEvents(partitionID[0]) \ No newline at end of file diff --git a/samples/smoketest/KeyVaultSecrets.py b/samples/smoketest/KeyVaultSecrets.py index 7f27b02460f1..9579940b8f49 100644 --- a/samples/smoketest/KeyVaultSecrets.py +++ b/samples/smoketest/KeyVaultSecrets.py @@ -1,7 +1,6 @@ -import os from azure.identity import DefaultAzureCredential from azure.keyvault.secrets import SecretClient - +import os class KeyVault: def __init__(self): @@ -10,9 +9,7 @@ def __init__(self): # * AZURE_CLIENT_SECRET # * AZURE_TENANT_ID credential = DefaultAzureCredential() - self.secret_client = SecretClient( - vault_url=os.environ["AZURE_PROJECT_URL"], credential=credential - ) + self.secret_client = SecretClient(vault_url=os.environ["AZURE_PROJECT_URL"], credential=credential) def SetSecret(self): print("Setting a secret...") @@ -43,4 +40,4 @@ def Run(self): self.SetSecret() self.GetSecret() finally: - self.DeleteSecret() + self.DeleteSecret() \ No newline at end of file diff --git a/samples/smoketest/Program.py b/samples/smoketest/Program.py index f63139d9d0d8..998174240f7a 100644 --- a/samples/smoketest/Program.py +++ b/samples/smoketest/Program.py @@ -10,4 +10,4 @@ KeyVault().Run() StorageBlob().Run() EventHub().Run() -CosmosDB().Run() +CosmosDB().Run() \ No newline at end of file diff --git a/samples/smoketest/StorageBlobs.py b/samples/smoketest/StorageBlobs.py index 48fe3bc17546..dd1864885dfc 100644 --- a/samples/smoketest/StorageBlobs.py +++ b/samples/smoketest/StorageBlobs.py @@ -1,19 +1,15 @@ -import os from azure.storage.blob import BlobClient -from azure.core import exceptions - +import os class StorageBlob: def __init__(self): connectionString = os.environ["STORAGE_CONNECTION_STRING"] - self.blob = BlobClient.from_connection_string( - connectionString, container="mycontainer", blob="pyTestBlob.txt" - ) + self.blob = BlobClient.from_connection_string(connectionString, container="mycontainer", blob="pyTestBlob.txt") def UploadBLob(self): print("uploading blob...") - data = "This is a sample data for Python Test" - self.blob.upload_blob(data) + self.data = "This is a sample data for Python Test" + self.blob.upload_blob(self.data) print("\tdone") def DownloadBlob(self): @@ -37,15 +33,15 @@ def Run(self): print("2) Download a Blob") print("3) Delete that Blob (Clean up the resource)") print() - - # Ensure that the blob does not exists before the tests + + #Ensure that the blob does not exists before the tests try: self.DeleteBlob() - except exceptions.AzureError: + except: pass - + try: self.UploadBLob() self.DownloadBlob() finally: - self.DeleteBlob() + self.DeleteBlob() \ No newline at end of file From ff419ff3c80fa8d8009720233e8ffee027e7e406 Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 17:51:01 -0700 Subject: [PATCH 25/26] Gone trought Suyog comments --- samples/smoketest/CosmosDB.py | 65 ++++++++++++---------------- samples/smoketest/EventHubs.py | 39 +++++++++++------ samples/smoketest/KeyVaultSecrets.py | 9 ++-- samples/smoketest/Program.py | 2 +- samples/smoketest/StorageBlobs.py | 18 +++++--- 5 files changed, 71 insertions(+), 62 deletions(-) diff --git a/samples/smoketest/CosmosDB.py b/samples/smoketest/CosmosDB.py index 52457652ca29..b4e2a56aa025 100644 --- a/samples/smoketest/CosmosDB.py +++ b/samples/smoketest/CosmosDB.py @@ -1,13 +1,14 @@ +import os from azure.cosmos import CosmosClient from azure.cosmos.partition_key import PartitionKey -import os + class CosmosDB: def __init__(self): URL = os.environ["COSMOS_ENDPOINT"] KEY = os.environ["COSMOS_KEY"] - self.client = CosmosClient(URL,{'masterKey': KEY}) - self.dbName="pySolarSystem" + self.client = CosmosClient(URL, {"masterKey": KEY}) + self.dbName = "pySolarSystem" def CreateDatabase(self): print("Creating '{0}' database...".format(self.dbName)) @@ -16,53 +17,41 @@ def CreateDatabase(self): def CreateContainer(self, db): collectionName = "Planets" print("Creating '{0}' collection...".format(collectionName)) - partition_key = PartitionKey(path='/id', kind='Hash') + partition_key = PartitionKey(path="/id", kind="Hash") return db.create_container(id="Planets", partition_key=partition_key) def CreateDocuments(self, container): # Cosmos will look for an 'id' field in the items, if the 'id' is not specify Cosmos is going to assing a random key. planets = [ { - 'id' : "Earth", - 'HasRings' : False, - 'Radius' : 3959, - 'Moons' : - [ - { - 'Name' : "Moon" - } - ] - }, + "id": "Earth", + "HasRings": False, + "Radius": 3959, + "Moons": [{"Name": "Moon"}], + }, { - "id" : "Mars", - "HasRings" : False, - "Radius" : 2106, - "Moons" : - [ - { - "Name" : "Phobos" - }, - { - "Name" : "Deimos" - } - ] - } - ] + "id": "Mars", + "HasRings": False, + "Radius": 2106, + "Moons": [{"Name": "Phobos"}, {"Name": "Deimos"}], + }, + ] print("Inserting items in the collection...") for planet in planets: container.create_item(planet) - print("\t'{0}' created".format(planet['id'])) + print("\t'{0}' created".format(planet["id"])) print("\tdone") def SimpleQuery(self, container): print("Quering the container...") - items = list(container.query_items( - query="SELECT c.id FROM c", - enable_cross_partition_query = True - )) + items = list( + container.query_items( + query="SELECT c.id FROM c", enable_cross_partition_query=True + ) + ) print("\tdone: {0}".format(items)) - + def DeleteDatabase(self): print("Cleaning up the resource...") self.client.delete_database(self.dbName) @@ -78,18 +67,18 @@ def Run(self): print("3) Insert Documents (items) into the Container") print("4) Delete Database (Clean up the resource)") print() - + # Ensure that the database does not exists try: self.DeleteDatabase() except: pass - + try: db = self.CreateDatabase() container = self.CreateContainer(db=db) self.CreateDocuments(container=container) - self.SimpleQuery(container=container) + self.SimpleQuery(container=container) finally: # if something goes wrong, the resource should be cleaned anyway - self.DeleteDatabase() \ No newline at end of file + self.DeleteDatabase() diff --git a/samples/smoketest/EventHubs.py b/samples/smoketest/EventHubs.py index 8c8afc547e32..9a0ed400b5c5 100644 --- a/samples/smoketest/EventHubs.py +++ b/samples/smoketest/EventHubs.py @@ -1,32 +1,41 @@ -from azure.eventhub import EventHubClient, EventData, EventPosition -from datetime import datetime import os +from datetime import datetime +from azure.eventhub import EventHubClient, EventData, EventPosition + class EventHub: def __init__(self): # This test requires a previusly created Event Hub. # In this example the name is "myeventhub", but it could be change below connectionString = os.environ["EVENT_HUBS_CONNECTION_STRING"] - eventHubName = 'myeventhub' - self.client = EventHubClient.from_connection_string(connectionString, eventHubName) + eventHubName = "myeventhub" + self.client = EventHubClient.from_connection_string( + connectionString, eventHubName + ) def GetPartitionIds(self): print("Getting partitions id...") partition_ids = self.client.get_partition_ids() print("\tdone") - return partition_ids + return partition_ids def SendAndReceiveEvents(self, partitionID): - with self.client.create_consumer(consumer_group="$default", partition_id=partitionID, event_position=EventPosition(datetime.utcnow())) as consumer: + with self.client.create_consumer( + consumer_group="$default", + partition_id=partitionID, + event_position=EventPosition(datetime.utcnow()), + ) as consumer: print("Sending events...") with self.client.create_producer(partition_id=partitionID) as producer: event_list = [ EventData(b"Test Event 1 in Python"), - EventData(b"Test Event 2 in Python"),EventData(b"Test Event 3 in Python")] + EventData(b"Test Event 2 in Python"), + EventData(b"Test Event 3 in Python"), + ] producer.send(event_list) print("\tdone") - + print("Receiving events...") received = consumer.receive(max_batch_size=len(event_list), timeout=2) for event_data in received: @@ -34,8 +43,12 @@ def SendAndReceiveEvents(self, partitionID): print("\tdone") - if(len(received) != len(event_list)): - raise Exception("Error, expecting {0} events, but {1} were received.".format(str(len(event_list)),str(len(received)))) + if len(received) != len(event_list): + raise Exception( + "Error, expecting {0} events, but {1} were received.".format( + str(len(event_list)), str(len(received)) + ) + ) def Run(self): print() @@ -48,6 +61,6 @@ def Run(self): print() partitionID = self.GetPartitionIds() - #In this sample the same partition id is going to be used for the producer and consumer, - #It is the first one, but it could be any (is not relevant as long as it is the same in both producer and consumer) - self.SendAndReceiveEvents(partitionID[0]) \ No newline at end of file + # In this sample the same partition id is going to be used for the producer and consumer, + # It is the first one, but it could be any (is not relevant as long as it is the same in both producer and consumer) + self.SendAndReceiveEvents(partitionID[0]) diff --git a/samples/smoketest/KeyVaultSecrets.py b/samples/smoketest/KeyVaultSecrets.py index 9579940b8f49..7f27b02460f1 100644 --- a/samples/smoketest/KeyVaultSecrets.py +++ b/samples/smoketest/KeyVaultSecrets.py @@ -1,6 +1,7 @@ +import os from azure.identity import DefaultAzureCredential from azure.keyvault.secrets import SecretClient -import os + class KeyVault: def __init__(self): @@ -9,7 +10,9 @@ def __init__(self): # * AZURE_CLIENT_SECRET # * AZURE_TENANT_ID credential = DefaultAzureCredential() - self.secret_client = SecretClient(vault_url=os.environ["AZURE_PROJECT_URL"], credential=credential) + self.secret_client = SecretClient( + vault_url=os.environ["AZURE_PROJECT_URL"], credential=credential + ) def SetSecret(self): print("Setting a secret...") @@ -40,4 +43,4 @@ def Run(self): self.SetSecret() self.GetSecret() finally: - self.DeleteSecret() \ No newline at end of file + self.DeleteSecret() diff --git a/samples/smoketest/Program.py b/samples/smoketest/Program.py index 998174240f7a..f63139d9d0d8 100644 --- a/samples/smoketest/Program.py +++ b/samples/smoketest/Program.py @@ -10,4 +10,4 @@ KeyVault().Run() StorageBlob().Run() EventHub().Run() -CosmosDB().Run() \ No newline at end of file +CosmosDB().Run() diff --git a/samples/smoketest/StorageBlobs.py b/samples/smoketest/StorageBlobs.py index dd1864885dfc..7e0c394f9580 100644 --- a/samples/smoketest/StorageBlobs.py +++ b/samples/smoketest/StorageBlobs.py @@ -1,10 +1,14 @@ -from azure.storage.blob import BlobClient import os +from azure.storage.blob import BlobClient +from azure.core import exceptions + class StorageBlob: def __init__(self): connectionString = os.environ["STORAGE_CONNECTION_STRING"] - self.blob = BlobClient.from_connection_string(connectionString, container="mycontainer", blob="pyTestBlob.txt") + self.blob = BlobClient.from_connection_string( + connectionString, container="mycontainer", blob="pyTestBlob.txt" + ) def UploadBLob(self): print("uploading blob...") @@ -33,15 +37,15 @@ def Run(self): print("2) Download a Blob") print("3) Delete that Blob (Clean up the resource)") print() - - #Ensure that the blob does not exists before the tests + + # Ensure that the blob does not exists before the tests try: self.DeleteBlob() - except: + except exceptions.AzureError: pass - + try: self.UploadBLob() self.DownloadBlob() finally: - self.DeleteBlob() \ No newline at end of file + self.DeleteBlob() From e2190c9437e6aee5a066b624785804b2914533bd Mon Sep 17 00:00:00 2001 From: Jonathan Cardenas Date: Tue, 23 Jul 2019 18:10:45 -0700 Subject: [PATCH 26/26] use of snake case in file names --- samples/smoketest/Program.py | 8 ++++---- samples/smoketest/{CosmosDB.py => cosmos_db.py} | 0 samples/smoketest/{EventHubs.py => event_hubs.py} | 0 .../{KeyVaultSecrets.py => key_vault_secrets.py} | 0 samples/smoketest/{StorageBlobs.py => storage_blob.py} | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename samples/smoketest/{CosmosDB.py => cosmos_db.py} (100%) rename samples/smoketest/{EventHubs.py => event_hubs.py} (100%) rename samples/smoketest/{KeyVaultSecrets.py => key_vault_secrets.py} (100%) rename samples/smoketest/{StorageBlobs.py => storage_blob.py} (100%) diff --git a/samples/smoketest/Program.py b/samples/smoketest/Program.py index f63139d9d0d8..dd43a67f9287 100644 --- a/samples/smoketest/Program.py +++ b/samples/smoketest/Program.py @@ -1,7 +1,7 @@ -from KeyVaultSecrets import KeyVault -from StorageBlobs import StorageBlob -from EventHubs import EventHub -from CosmosDB import CosmosDB +from key_vault_secrets import KeyVault +from storage_blob import StorageBlob +from event_hubs import EventHub +from cosmos_db import CosmosDB print("==========================================") print(" AZURE TRACK 2 SDKs SMOKE TEST") diff --git a/samples/smoketest/CosmosDB.py b/samples/smoketest/cosmos_db.py similarity index 100% rename from samples/smoketest/CosmosDB.py rename to samples/smoketest/cosmos_db.py diff --git a/samples/smoketest/EventHubs.py b/samples/smoketest/event_hubs.py similarity index 100% rename from samples/smoketest/EventHubs.py rename to samples/smoketest/event_hubs.py diff --git a/samples/smoketest/KeyVaultSecrets.py b/samples/smoketest/key_vault_secrets.py similarity index 100% rename from samples/smoketest/KeyVaultSecrets.py rename to samples/smoketest/key_vault_secrets.py diff --git a/samples/smoketest/StorageBlobs.py b/samples/smoketest/storage_blob.py similarity index 100% rename from samples/smoketest/StorageBlobs.py rename to samples/smoketest/storage_blob.py