Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yi Gu committed Dec 17, 2024
1 parent 7dad4e1 commit 221c7b1
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 2 deletions.
6 changes: 5 additions & 1 deletion azure-quantum/azure/quantum/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ def list_top_level_items(
status: Optional[list[JobStatus]] = None,
created_after: Optional[datetime] = None,
created_before: Optional[datetime] = None,
orderby_property: Optional[str] = None,
is_asc: Optional[bool] = True
) -> List[Union[Job, Session]]:
"""
Get a list of top level items for the given workspace,
Expand All @@ -620,7 +622,9 @@ def list_top_level_items(
target=target,
status=status,
created_after=created_after,
created_before=created_before
created_before=created_before,
orderby_property=orderby_property,
is_asc=is_asc
)

result = [WorkspaceItemFactory.__new__(workspace=self, item_details=item_details)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
User-Agent:
- testapp azsdk-python-quantum/1.0.0b1 Python/3.9.20 (Windows-10-10.0.26100-SP0)
x-ms-quantum-api-key:
- PLACEHOLDER
method: GET
uri: https://eastus.quantum.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.Quantum/workspaces/myworkspace/topLevelItems?api-version=2024-10-01-preview&filter=CreationTime%20ge%202024-12-01&skip=0&top=100&orderby=CreationTime%20asc&test-sequence-id=1
response:
body:
string: '{"value": [{"containerUri": "https://mystorage.blob.core.windows.net/job-7b3860ea-b9a9-11ef-872e-5414f37777d8?sv=PLACEHOLDER&ss=b&srt=co&spr=https&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sp=rwlac&sig=PLACEHOLDER",
"inputDataUri": "https://mystorage.blob.core.windows.net/job-7b3860ea-b9a9-11ef-872e-5414f37777d8/inputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"inputDataFormat": "ionq.circuit.v1", "inputParams": {}, "metadata": null,
"sessionId": null, "status": "Succeeded", "jobType": "QuantumComputing", "outputDataFormat":
"ionq.quantum-results.v1", "outputDataUri": "https://mystorage.blob.core.windows.net/job-7b3860ea-b9a9-11ef-872e-5414f37777d8/rawOutputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"beginExecutionTime": "2024-12-13T23:25:09.521Z", "cancellationTime": null,
"quantumComputingData": {"count": 1}, "errorData": null, "isCancelling": false,
"tags": [], "name": "ionq-3ghz-job", "id": "7b3860ea-b9a9-11ef-872e-5414f37777d8",
"providerId": "ionq", "target": "ionq.simulator", "creationTime": "2024-12-13T23:25:07.3780629Z",
"endExecutionTime": "2024-12-13T23:25:09.535Z", "costEstimate": {"currencyCode":
"USD", "events": [{"dimensionId": "gs1q", "dimensionName": "1Q Gate Shot",
"measureUnit": "1q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}, {"dimensionId": "gs2q", "dimensionName": "2Q Gate Shot",
"measureUnit": "2q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}], "estimatedTotal": 0.0}, "itemType": "Job"}, {"containerUri":
"https://mystorage.blob.core.windows.net/job-faec0f94-b9a9-11ef-bad5-5414f37777d8?sv=PLACEHOLDER&ss=b&srt=co&spr=https&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sp=rwlac&sig=PLACEHOLDER",
"inputDataUri": "https://mystorage.blob.core.windows.net/job-faec0f94-b9a9-11ef-bad5-5414f37777d8/inputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"inputDataFormat": "ionq.circuit.v1", "inputParams": {"shots": 100}, "metadata":
null, "sessionId": null, "status": "Succeeded", "jobType": "QuantumComputing",
"outputDataFormat": "ionq.quantum-results.v1", "outputDataUri": "https://mystorage.blob.core.windows.net/job-faec0f94-b9a9-11ef-bad5-5414f37777d8/rawOutputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"beginExecutionTime": "2024-12-13T23:28:42.239Z", "cancellationTime": null,
"quantumComputingData": {"count": 1}, "errorData": null, "isCancelling": false,
"tags": [], "name": "ionq-3ghz-job", "id": "faec0f94-b9a9-11ef-bad5-5414f37777d8",
"providerId": "ionq", "target": "ionq.simulator", "creationTime": "2024-12-13T23:28:40.2258653Z",
"endExecutionTime": "2024-12-13T23:28:42.254Z", "costEstimate": {"currencyCode":
"USD", "events": [{"dimensionId": "gs1q", "dimensionName": "1Q Gate Shot",
"measureUnit": "1q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}, {"dimensionId": "gs2q", "dimensionName": "2Q Gate Shot",
"measureUnit": "2q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}], "estimatedTotal": 0.0}, "itemType": "Job"}, {"containerUri":
"https://mystorage.blob.core.windows.net/job-9b5ac687-b9aa-11ef-ab50-5414f37777d8?sv=PLACEHOLDER&ss=b&srt=co&spr=https&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sp=rwlac&sig=PLACEHOLDER",
"inputDataUri": "https://mystorage.blob.core.windows.net/job-9b5ac687-b9aa-11ef-ab50-5414f37777d8/inputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"inputDataFormat": "ionq.circuit.v1", "inputParams": {"shots": 100}, "metadata":
null, "sessionId": null, "status": "Succeeded", "jobType": "QuantumComputing",
"outputDataFormat": "ionq.quantum-results.v1", "outputDataUri": "https://mystorage.blob.core.windows.net/job-9b5ac687-b9aa-11ef-ab50-5414f37777d8/rawOutputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"beginExecutionTime": "2024-12-13T23:33:12.975Z", "cancellationTime": null,
"quantumComputingData": {"count": 1}, "errorData": null, "isCancelling": false,
"tags": [], "name": "ionq-3ghz-job", "id": "9b5ac687-b9aa-11ef-ab50-5414f37777d8",
"providerId": "ionq", "target": "ionq.simulator", "creationTime": "2024-12-13T23:33:11.1048323Z",
"endExecutionTime": "2024-12-13T23:33:12.993Z", "costEstimate": {"currencyCode":
"USD", "events": [{"dimensionId": "gs1q", "dimensionName": "1Q Gate Shot",
"measureUnit": "1q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}, {"dimensionId": "gs2q", "dimensionName": "2Q Gate Shot",
"measureUnit": "2q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}], "estimatedTotal": 0.0}, "itemType": "Job"}, {"containerUri":
"https://mystorage.blob.core.windows.net/job-c77255d5-b9aa-11ef-b204-5414f37777d8?sv=PLACEHOLDER&ss=b&srt=co&spr=https&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sp=rwlac&sig=PLACEHOLDER",
"inputDataUri": "https://mystorage.blob.core.windows.net/job-c77255d5-b9aa-11ef-b204-5414f37777d8/inputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"inputDataFormat": "ionq.circuit.v1", "inputParams": {"shots": 100}, "metadata":
null, "sessionId": null, "status": "Succeeded", "jobType": "QuantumComputing",
"outputDataFormat": "ionq.quantum-results.v1", "outputDataUri": "https://mystorage.blob.core.windows.net/job-c77255d5-b9aa-11ef-b204-5414f37777d8/rawOutputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"beginExecutionTime": "2024-12-13T23:34:25.067Z", "cancellationTime": null,
"quantumComputingData": {"count": 1}, "errorData": null, "isCancelling": false,
"tags": [], "name": "ionq-job", "id": "c77255d5-b9aa-11ef-b204-5414f37777d8",
"providerId": "ionq", "target": "ionq.simulator", "creationTime": "2024-12-13T23:34:23.2821615Z",
"endExecutionTime": "2024-12-13T23:34:25.078Z", "costEstimate": {"currencyCode":
"USD", "events": [{"dimensionId": "gs1q", "dimensionName": "1Q Gate Shot",
"measureUnit": "1q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}, {"dimensionId": "gs2q", "dimensionName": "2Q Gate Shot",
"measureUnit": "2q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}], "estimatedTotal": 0.0}, "itemType": "Job"}, {"containerUri":
"https://mystorage.blob.core.windows.net/job-d590084b-b9aa-11ef-9429-5414f37777d8?sv=PLACEHOLDER&ss=b&srt=co&spr=https&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sp=rwlac&sig=PLACEHOLDER",
"inputDataUri": "https://mystorage.blob.core.windows.net/job-d590084b-b9aa-11ef-9429-5414f37777d8/inputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"inputDataFormat": "ionq.circuit.v1", "inputParams": {"shots": 100}, "metadata":
null, "sessionId": null, "status": "Succeeded", "jobType": "QuantumComputing",
"outputDataFormat": "ionq.quantum-results.v1", "outputDataUri": "https://mystorage.blob.core.windows.net/job-d590084b-b9aa-11ef-9429-5414f37777d8/rawOutputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"beginExecutionTime": "2024-12-13T23:34:48.452Z", "cancellationTime": null,
"quantumComputingData": {"count": 1}, "errorData": null, "isCancelling": false,
"tags": [], "name": "ionq-job", "id": "d590084b-b9aa-11ef-9429-5414f37777d8",
"providerId": "ionq", "target": "ionq.simulator", "creationTime": "2024-12-13T23:34:46.73503Z",
"endExecutionTime": "2024-12-13T23:34:48.472Z", "costEstimate": {"currencyCode":
"USD", "events": [{"dimensionId": "gs1q", "dimensionName": "1Q Gate Shot",
"measureUnit": "1q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}, {"dimensionId": "gs2q", "dimensionName": "2Q Gate Shot",
"measureUnit": "2q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}], "estimatedTotal": 0.0}, "itemType": "Job"}, {"containerUri":
"https://mystorage.blob.core.windows.net/job-e36040de-b9aa-11ef-ba7d-5414f37777d8?sv=PLACEHOLDER&ss=b&srt=co&spr=https&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sp=rwlac&sig=PLACEHOLDER",
"inputDataUri": "https://mystorage.blob.core.windows.net/job-e36040de-b9aa-11ef-ba7d-5414f37777d8/inputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"inputDataFormat": "ionq.circuit.v1", "inputParams": {"shots": 100}, "metadata":
null, "sessionId": null, "status": "Succeeded", "jobType": "QuantumComputing",
"outputDataFormat": "ionq.quantum-results.v1", "outputDataUri": "https://mystorage.blob.core.windows.net/job-e36040de-b9aa-11ef-ba7d-5414f37777d8/rawOutputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"beginExecutionTime": "2024-12-13T23:35:11.546Z", "cancellationTime": null,
"quantumComputingData": {"count": 1}, "errorData": null, "isCancelling": false,
"tags": [], "name": "ionq-job", "id": "e36040de-b9aa-11ef-ba7d-5414f37777d8",
"providerId": "ionq", "target": "ionq.simulator", "creationTime": "2024-12-13T23:35:09.8725735Z",
"endExecutionTime": "2024-12-13T23:35:11.558Z", "costEstimate": {"currencyCode":
"USD", "events": [{"dimensionId": "gs1q", "dimensionName": "1Q Gate Shot",
"measureUnit": "1q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}, {"dimensionId": "gs2q", "dimensionName": "2Q Gate Shot",
"measureUnit": "2q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}], "estimatedTotal": 0.0}, "itemType": "Job"}, {"containerUri":
"https://mystorage.blob.core.windows.net/job-eeb7031c-b9aa-11ef-be96-5414f37777d8?sv=PLACEHOLDER&ss=b&srt=co&spr=https&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sp=rwlac&sig=PLACEHOLDER",
"inputDataUri": "https://mystorage.blob.core.windows.net/job-eeb7031c-b9aa-11ef-be96-5414f37777d8/inputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"inputDataFormat": "ionq.circuit.v1", "inputParams": {}, "metadata": null,
"sessionId": null, "status": "Succeeded", "jobType": "QuantumComputing", "outputDataFormat":
"ionq.quantum-results.v1", "outputDataUri": "https://mystorage.blob.core.windows.net/job-eeb7031c-b9aa-11ef-be96-5414f37777d8/rawOutputData?sv=PLACEHOLDER&st=2000-01-01T00%3A00%3A00Z&se=2050-01-01T00%3A00%3A00Z&sr=b&sp=rcw&sig=PLACEHOLDER",
"beginExecutionTime": "2024-12-13T23:35:30.993Z", "cancellationTime": null,
"quantumComputingData": {"count": 1}, "errorData": null, "isCancelling": false,
"tags": [], "name": "ionq-3ghz-job", "id": "eeb7031c-b9aa-11ef-be96-5414f37777d8",
"providerId": "ionq", "target": "ionq.simulator", "creationTime": "2024-12-13T23:35:29.1596424Z",
"endExecutionTime": "2024-12-13T23:35:31.015Z", "costEstimate": {"currencyCode":
"USD", "events": [{"dimensionId": "gs1q", "dimensionName": "1Q Gate Shot",
"measureUnit": "1q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}, {"dimensionId": "gs2q", "dimensionName": "2Q Gate Shot",
"measureUnit": "2q gate shot", "amountBilled": 0.0, "amountConsumed": 0.0,
"unitPrice": 0.0}], "estimatedTotal": 0.0}, "itemType": "Job"}], "nextLink":
null}'
headers:
connection:
- keep-alive
content-length:
- '11412'
content-type:
- application/json; charset=utf-8
transfer-encoding:
- chunked
status:
code: 200
message: OK
version: 1
55 changes: 54 additions & 1 deletion azure-quantum/tests/unit/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,57 @@ def test_list_top_level_items_filtered_by_created_before(self):

check_item_created_before = item.details.creation_time.date() <= test_date
self.assertTrue( check_item_created_before, item.details.creation_time)


@pytest.mark.live_test
def test_list_top_level_items_orderby_asc(self):
ws = self.create_workspace()
subscription_id = ws.subscription_id
resource_group = ws.resource_group
workspace_name = ws.name

test_date = date(2024, 12, 1)

items = ws.list_top_level_items(created_after = test_date, orderby_property="CreationTime", is_asc=True)

creation_time = None
for item in items:
self.assertEqual(item.workspace.subscription_id, subscription_id)
self.assertEqual(item.workspace.resource_group, resource_group)
self.assertEqual(item.workspace.name, workspace_name)

check_item_created_after = item.details.creation_time.date() >= test_date
self.assertTrue( check_item_created_after, item.details.creation_time)

if creation_time is None:
creation_time = item.details.creation_time
else:
check_item_created_before_order = item.details.creation_time >= creation_time
self.assertTrue( check_item_created_before_order, item.details.creation_time)
creation_time = item.details.creation_time

@pytest.mark.live_test
def test_list_top_level_items_orderby_desc(self):
ws = self.create_workspace()
subscription_id = ws.subscription_id
resource_group = ws.resource_group
workspace_name = ws.name

test_date = date(2024, 12, 1)

items = ws.list_top_level_items(created_after = test_date, orderby_property="CreationTime", is_asc=False)

creation_time = None
for item in items:
self.assertEqual(item.workspace.subscription_id, subscription_id)
self.assertEqual(item.workspace.resource_group, resource_group)
self.assertEqual(item.workspace.name, workspace_name)

check_item_created_after = item.details.creation_time.date() >= test_date
self.assertTrue( check_item_created_after, item.details.creation_time)

if creation_time is None:
creation_time = item.details.creation_time
else:
check_item_created_before_order = item.details.creation_time <= creation_time
self.assertTrue( check_item_created_before_order, item.details.creation_time)
creation_time = item.details.creation_time

0 comments on commit 221c7b1

Please sign in to comment.