Skip to content
Merged
Prev Previous commit
Next Next commit
Fix samples merge
  • Loading branch information
annatisch committed Oct 30, 2019
commit 49c3c14d439e1a1a5370bf32f1679e961ddaa8f9
10 changes: 5 additions & 5 deletions sdk/cosmos/azure-cosmos/samples/change_feed_management.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import azure.cosmos.documents as documents
import azure.cosmos.cosmos_client as cosmos_client
import azure.cosmos.errors as errors
import azure.cosmos.exceptions as exceptions
import azure.cosmos.partition_key as partition_key
import datetime
import uuid
Expand Down Expand Up @@ -60,7 +60,7 @@ def run_sample():
# setup database for this sample
try:
db = client.create_database(id=DATABASE_ID)
except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
raise RuntimeError("Database with id '{}' already exists".format(DATABASE_ID))

# setup container for this sample
Expand All @@ -71,7 +71,7 @@ def run_sample():
)
print('Container with id \'{0}\' created'.format(CONTAINER_ID))

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
raise RuntimeError("Container with id '{}' already exists".format(CONTAINER_ID))

create_items(container, 100)
Expand All @@ -80,10 +80,10 @@ def run_sample():
# cleanup database after sample
try:
client.delete_database(db)
except errors.CosmosResourceNotFoundError:
except exceptions.CosmosResourceNotFoundError:
pass

except errors.CosmosHttpResponseError as e:
except exceptions.CosmosHttpResponseError as e:
print('\nrun_sample has caught an error. {0}'.format(e.message))

finally:
Expand Down
26 changes: 13 additions & 13 deletions sdk/cosmos/azure-cosmos/samples/collection_management.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import azure.cosmos.cosmos_client as cosmos_client
import azure.cosmos.errors as errors
import azure.cosmos.exceptions as exceptions
from azure.cosmos.partition_key import PartitionKey

import config
Expand Down Expand Up @@ -77,7 +77,7 @@ def create_container(db, id):
db.create_container(id=id, partition_key=partition_key)
print('Container with id \'{0}\' created'.format(id))

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
print('A container with id \'{0}\' already exists'.format(id))

print("\n2.2 Create Container - With custom index policy")
Expand All @@ -101,7 +101,7 @@ def create_container(db, id):
print('IndexPolicy Mode - \'{0}\''.format(properties['indexingPolicy']['indexingMode']))
print('IndexPolicy Automatic - \'{0}\''.format(properties['indexingPolicy']['automatic']))

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
print('A container with id \'{0}\' already exists'.format(coll['id']))

print("\n2.3 Create Container - With custom offer throughput")
Expand All @@ -115,7 +115,7 @@ def create_container(db, id):
)
print('Container with id \'{0}\' created'.format(container.id))

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
print('A container with id \'{0}\' already exists'.format(coll['id']))

print("\n2.4 Create Container - With Unique keys")
Expand All @@ -131,7 +131,7 @@ def create_container(db, id):
print('Container with id \'{0}\' created'.format(container.id))
print('Unique Key Paths - \'{0}\', \'{1}\''.format(unique_key_paths[0], unique_key_paths[1]))

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
print('A container with id \'container_unique_keys\' already exists')

print("\n2.5 Create Collection - With Partition key V2 (Default)")
Expand All @@ -145,7 +145,7 @@ def create_container(db, id):
print('Container with id \'{0}\' created'.format(container.id))
print('Partition Key - \'{0}\''.format(properties['partitionKey']))

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
print('A container with id \'collection_partition_key_v2\' already exists')

print("\n2.6 Create Collection - With Partition key V1")
Expand All @@ -159,7 +159,7 @@ def create_container(db, id):
print('Container with id \'{0}\' created'.format(container.id))
print('Partition Key - \'{0}\''.format(properties['partitionKey']))

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
print('A container with id \'collection_partition_key_v1\' already exists')


Expand All @@ -180,7 +180,7 @@ def manage_offer_throughput(db, id):

print('Found Offer \'{0}\' for Container \'{1}\' and its throughput is \'{2}\''.format(offer.properties['id'], container.id, offer.properties['content']['offerThroughput']))

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
print('A container with id \'{0}\' does not exist'.format(id))

print("\n3.2 Change Offer Throughput of Container")
Expand All @@ -199,7 +199,7 @@ def read_Container(db, id):
container = db.get_container_client(id)
print('Container with id \'{0}\' was found, it\'s link is {1}'.format(container.id, container.container_link))

except errors.CosmosResourceNotFoundError:
except exceptions.CosmosResourceNotFoundError:
print('A container with id \'{0}\' does not exist'.format(id))


Expand All @@ -225,7 +225,7 @@ def delete_Container(db, id):

print('Container with id \'{0}\' was deleted'.format(id))

except errors.CosmosResourceNotFoundError:
except exceptions.CosmosResourceNotFoundError:
print('A container with id \'{0}\' does not exist'.format(id))


Expand All @@ -237,7 +237,7 @@ def run_sample():
try:
db = client.create_database(id=DATABASE_ID)

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
db = client.get_database_client(DATABASE_ID)

# query for a container
Expand All @@ -262,10 +262,10 @@ def run_sample():
try:
client.delete_database(db)

except errors.CosmosResourceNotFoundError:
except exceptions.CosmosResourceNotFoundError:
pass

except errors.CosmosHttpResponseError as e:
except exceptions.CosmosHttpResponseError as e:
print('\nrun_sample has caught an error. {0}'.format(e.message))

finally:
Expand Down
10 changes: 5 additions & 5 deletions sdk/cosmos/azure-cosmos/samples/database_management.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import azure.cosmos.cosmos_client as cosmos_client
import azure.cosmos.errors as errors
import azure.cosmos.exceptions as exceptions

import config

Expand Down Expand Up @@ -52,7 +52,7 @@ def create_database(client, id):
client.create_database(id=id)
print('Database with id \'{0}\' created'.format(id))

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
print('A database with id \'{0}\' already exists'.format(id))


Expand All @@ -63,7 +63,7 @@ def read_database(client, id):
database = client.get_database_client(id)
print('Database with id \'{0}\' was found, it\'s link is {1}'.format(id, database.database_link))

except errors.CosmosResourceNotFoundError:
except exceptions.CosmosResourceNotFoundError:
print('A database with id \'{0}\' does not exist'.format(id))


Expand All @@ -89,7 +89,7 @@ def delete_database(client, id):

print('Database with id \'{0}\' was deleted'.format(id))

except errors.CosmosResourceNotFoundError:
except exceptions.CosmosResourceNotFoundError:
print('A database with id \'{0}\' does not exist'.format(id))


Expand All @@ -111,7 +111,7 @@ def run_sample():
# delete database by id
delete_database(client, DATABASE_ID)

except errors.CosmosHttpResponseError as e:
except exceptions.CosmosHttpResponseError as e:
print('\nrun_sample has caught an error. {0}'.format(e.message))

finally:
Expand Down
10 changes: 5 additions & 5 deletions sdk/cosmos/azure-cosmos/samples/document_management.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import azure.cosmos.cosmos_client as cosmos_client
import azure.cosmos.errors as errors
import azure.cosmos.exceptions as exceptions
from azure.cosmos.partition_key import PartitionKey
import datetime

Expand Down Expand Up @@ -163,15 +163,15 @@ def run_sample():
try:
db = client.create_database(id=DATABASE_ID)

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
pass

# setup container for this sample
try:
container = db.create_container(id=CONTAINER_ID, partition_key=PartitionKey(path='/id', kind='Hash'))
print('Container with id \'{0}\' created'.format(CONTAINER_ID))

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
print('Container with id \'{0}\' was found'.format(CONTAINER_ID))

create_items(container)
Expand All @@ -186,10 +186,10 @@ def run_sample():
try:
client.delete_database(db)

except errors.CosmosResourceNotFoundError:
except exceptions.CosmosResourceNotFoundError:
pass

except errors.CosmosHttpResponseError as e:
except exceptions.CosmosHttpResponseError as e:
print('\nrun_sample has caught an error. {0}'.format(e.message))

finally:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#SOFTWARE.

import azure.cosmos.cosmos_client as cosmos_client
import azure.cosmos.errors as errors
import azure.cosmos.exceptions as exceptions
import requests
import six
import json
Expand Down Expand Up @@ -268,15 +268,15 @@ def run_sample():
# setup database for this sample
try:
db = client.create_database(id=DATABASE_ID)
except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
db = client.get_database_client(DATABASE_ID)

# setup container for this sample
try:
container, document = create_nonpartitioned_collection(db)
print('Container with id \'{0}\' created'.format(CONTAINER_ID))

except errors.CosmosResourceExistsError:
except exceptions.CosmosResourceExistsError:
print('Container with id \'{0}\' was found'.format(CONTAINER_ID))

# Read Item created in non partitioned collection using older API version
Expand All @@ -291,10 +291,10 @@ def run_sample():
# cleanup database after sample
try:
client.delete_database(db)
except errors.CosmosResourceNotFoundError:
except exceptions.CosmosResourceNotFoundError:
pass

except errors.CosmosHttpResponseError as e:
except exceptions.CosmosHttpResponseError as e:
print('\nrun_sample has caught an error. {0}'.format(e.message))

finally:
Expand Down