|
5 | 5 | from pathlib import Path |
6 | 6 | from typing import TYPE_CHECKING |
7 | 7 |
|
8 | | -from behave import given, when |
| 8 | +from behave import given, then, when |
9 | 9 | from behave.runner import Context |
10 | 10 | from file_management import download_file_from_remote_archive |
11 | 11 | from static_definitions import ProjectType, TrainerType |
@@ -140,3 +140,31 @@ def step_when_user_uploads_project_to_new_project(context: Context) -> None: |
140 | 140 | import_project_request={"file_id": file_id}, |
141 | 141 | ) |
142 | 142 | context.job_id = import_response.job_id |
| 143 | + |
| 144 | + |
| 145 | +@when("the user requests to export the project with '{included_models}'") |
| 146 | +def step_when_user_requests_project_export(context: Context, included_models: str) -> None: |
| 147 | + project_ie_api: ProjectImportExportApi = context.project_import_export_api |
| 148 | + project_export_response = project_ie_api.trigger_project_export( |
| 149 | + organization_id=context.organization_id, |
| 150 | + workspace_id=context.workspace_id, |
| 151 | + project_id=context.project_id, |
| 152 | + include_models=included_models, |
| 153 | + ) |
| 154 | + context.job_id = project_export_response.job_id |
| 155 | + |
| 156 | + |
| 157 | +@then("the exported project can be downloaded and is {exported_project_size} MB") |
| 158 | +def step_then_user_can_download_exported_project(context: Context, exported_project_size: int) -> None: |
| 159 | + metadata = context.job_info.actual_instance.metadata |
| 160 | + expected_size = int(exported_project_size) * 1000000 |
| 161 | + assert expected_size <= int(metadata.size) < expected_size + 1000000 |
| 162 | + download_url = metadata.download_url |
| 163 | + export_id = download_url.split("/")[-2] |
| 164 | + project_import_export_api = context.project_import_export_api |
| 165 | + project_import_export_api.download_exported_project( |
| 166 | + organization_id=context.organization_id, |
| 167 | + workspace_id=context.workspace_id, |
| 168 | + project_id=context.project_id, |
| 169 | + export_operation_id=export_id, |
| 170 | + ) |
0 commit comments