Skip to content

Commit bd06d25

Browse files
committed
Tests and requirements file for Azure Storage
1 parent a6c185f commit bd06d25

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

tests/contrib/serverless/azurefunctions/azure_functions_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
import pytest
3131

32-
azure = pytest.importorskip("azure")
32+
azure = pytest.importorskip("azure-functions")
3333

3434
import datetime
3535
import os

tests/instrumentation/azure_tests.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
3939
azureblob = pytest.importorskip("azure.storage.blob")
4040
azurequeue = pytest.importorskip("azure.storage.queue")
4141
azuretable = pytest.importorskip("azure.cosmosdb.table")
42+
azuredatatable = pytest.importorskip("azure.data.tables")
4243
azurefile = pytest.importorskip("azure.storage.fileshare")
4344
pytestmark = [pytest.mark.azurestorage]
4445

46+
from azure.data.tables import TableServiceClient as DataTableServiceClient
4547
from azure.cosmosdb.table.tableservice import TableService
4648
from azure.storage.blob import BlobServiceClient
4749
from azure.storage.fileshare import ShareClient
@@ -82,6 +84,18 @@ def queue_client():
8284
queue_client.delete_queue()
8385

8486

87+
@pytest.fixture()
88+
def data_table_service():
89+
table_name = "apmagentpythonci" + str(uuid.uuid4().hex)
90+
data_table_service_client = DataTableServiceClient.from_connection_string(conn_str=CONNECTION_STRING)
91+
data_table_service = data_table_service_client.get_table_client(table_name)
92+
data_table_service.create_table()
93+
data_table_service.table_name = table_name
94+
95+
yield data_table_service
96+
97+
data_table_service.delete_table()
98+
8599
@pytest.fixture()
86100
def table_service():
87101
table_name = "apmagentpythonci" + str(uuid.uuid4().hex)
@@ -182,6 +196,23 @@ def test_queue(instrument, elasticapm_client, queue_client):
182196
assert span["action"] == "delete"
183197

184198

199+
def test_data_table_create(instrument, elasticapm_client):
200+
table_name = "apmagentpythonci" + str(uuid.uuid4().hex)
201+
data_table_service_client = DataTableServiceClient.from_connection_string(conn_str=CONNECTION_STRING)
202+
data_table_service = data_table_service_client.get_table_client(table_name)
203+
204+
elasticapm_client.begin_transaction("transaction.test")
205+
data_table_service.create_table()
206+
data_table_service.delete_table()
207+
elasticapm_client.end_transaction("MyView")
208+
209+
span = elasticapm_client.events[constants.SPAN][0]
210+
211+
assert span["name"] == "AzureTable Create {}".format(table_name)
212+
assert span["type"] == "storage"
213+
assert span["subtype"] == "azuretable"
214+
assert span["action"] == "Create"
215+
185216
def test_table_create(instrument, elasticapm_client):
186217
table_name = "apmagentpythonci" + str(uuid.uuid4().hex)
187218
table_service = TableService(connection_string=CONNECTION_STRING)
@@ -198,6 +229,40 @@ def test_table_create(instrument, elasticapm_client):
198229
assert span["subtype"] == "azuretable"
199230
assert span["action"] == "Create"
200231

232+
def test_data_table(instrument, elasticapm_client, data_table_service):
233+
table_name = data_table_service.table_name
234+
elasticapm_client.begin_transaction("transaction.test")
235+
task = {"PartitionKey": "tasksSeattle", "RowKey": "001", "description": "Take out the trash", "priority": 200}
236+
data_table_service.create_entity(task)
237+
task = {"PartitionKey": "tasksSeattle", "RowKey": "001", "description": "Take out the garbage", "priority": 250}
238+
data_table_service.update_entity(task)
239+
task = data_table_service.get_entity("tasksSeattle", "001")
240+
data_table_service.delete_entity("tasksSeattle", "001")
241+
elasticapm_client.end_transaction("MyView")
242+
243+
span = elasticapm_client.events[constants.SPAN][0]
244+
assert span["name"] == "AzureTable Insert {}".format(table_name)
245+
assert span["type"] == "storage"
246+
assert span["subtype"] == "azuretable"
247+
assert span["action"] == "Insert"
248+
249+
span = elasticapm_client.events[constants.SPAN][1]
250+
assert span["name"] == "AzureTable Update {}(PartitionKey='tasksSeattle',RowKey='001')".format(table_name)
251+
assert span["type"] == "storage"
252+
assert span["subtype"] == "azuretable"
253+
assert span["action"] == "Update"
254+
255+
span = elasticapm_client.events[constants.SPAN][2]
256+
assert span["name"] == "AzureTable Query {}(PartitionKey='tasksSeattle',RowKey='001')".format(table_name)
257+
assert span["type"] == "storage"
258+
assert span["subtype"] == "azuretable"
259+
assert span["action"] == "Query"
260+
261+
span = elasticapm_client.events[constants.SPAN][3]
262+
assert span["name"] == "AzureTable Delete {}(PartitionKey='tasksSeattle',RowKey='001')".format(table_name)
263+
assert span["type"] == "storage"
264+
assert span["subtype"] == "azuretable"
265+
assert span["action"] == "Delete"
201266

202267
def test_table(instrument, elasticapm_client, table_service):
203268
table_name = table_service.table_name
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
azure-storage-blob
2+
azure-storage-queue
3+
azure-data-tables
4+
azure-storage-file-share
5+
-r reqs-base.txt

0 commit comments

Comments
 (0)