|
4 | 4 | import subprocess |
5 | 5 | import sys |
6 | 6 | from dataclasses import dataclass, field |
| 7 | +from datetime import UTC, datetime, timedelta |
7 | 8 |
|
8 | 9 | import click |
9 | 10 | from click.core import Context |
10 | | -from progress.spinner import MoonSpinner |
11 | 11 |
|
12 | 12 | from testgen import settings |
13 | | -from testgen.commands.run_execute_tests import run_execution_steps |
14 | 13 | from testgen.commands.run_generate_tests import run_test_gen_queries |
15 | 14 | from testgen.commands.run_get_entities import ( |
16 | 15 | run_get_results, |
|
31 | 30 | from testgen.commands.run_observability_exporter import run_observability_exporter |
32 | 31 | from testgen.commands.run_profiling import run_profiling |
33 | 32 | from testgen.commands.run_quick_start import run_quick_start, run_quick_start_increment |
| 33 | +from testgen.commands.run_test_execution import run_test_execution |
34 | 34 | from testgen.commands.run_test_metadata_exporter import run_test_metadata_exporter |
35 | 35 | from testgen.commands.run_upgrade_db_config import get_schema_revision, is_db_revision_up_to_date, run_upgrade_db_config |
36 | 36 | from testgen.common import ( |
|
45 | 45 | from testgen.common.models import with_database_session |
46 | 46 | from testgen.common.models.profiling_run import ProfilingRun |
47 | 47 | from testgen.common.models.test_run import TestRun |
| 48 | +from testgen.common.models.test_suite import TestSuite |
48 | 49 | from testgen.scheduler import register_scheduler_job, run_scheduler |
49 | 50 | from testgen.utils import plugins |
50 | 51 |
|
@@ -159,28 +160,40 @@ def run_test_generation(configuration: Configuration, table_group_id: str, test_ |
159 | 160 |
|
160 | 161 | @register_scheduler_job |
161 | 162 | @cli.command("run-tests", help="Performs tests defined for a test suite.") |
| 163 | +@click.option( |
| 164 | + "-t", |
| 165 | + "--test-suite-id", |
| 166 | + required=False, |
| 167 | + type=click.STRING, |
| 168 | + help="ID of the test suite to run. Use a test_suite_id shown in list-test-suites.", |
| 169 | +) |
162 | 170 | @click.option( |
163 | 171 | "-pk", |
164 | 172 | "--project-key", |
165 | | - help="The identifier for a TestGen project. Use a project_key shown in list-projects.", |
| 173 | + help="DEPRECATED. Use --test-suite-id instead.", |
166 | 174 | required=False, |
167 | 175 | type=click.STRING, |
168 | 176 | default=settings.PROJECT_KEY, |
169 | 177 | ) |
170 | 178 | @click.option( |
171 | 179 | "-ts", |
172 | 180 | "--test-suite-key", |
173 | | - help="The identifier for a test suite. Use a test_suite_key shown in list-test-suites.", |
| 181 | + help="DEPRECATED. Use --test-suite-id instead.", |
174 | 182 | required=False, |
175 | 183 | default=settings.DEFAULT_TEST_SUITE_KEY, |
176 | 184 | ) |
177 | | -@pass_configuration |
178 | | -def run_tests(configuration: Configuration, project_key: str, test_suite_key: str): |
179 | | - click.echo(f"run-tests for suite: {test_suite_key}") |
180 | | - spinner = None |
181 | | - if not configuration.verbose: |
182 | | - spinner = MoonSpinner("Processing ... ") |
183 | | - message = run_execution_steps(project_key, test_suite_key, spinner=spinner) |
| 185 | +@with_database_session |
| 186 | +def run_tests(test_suite_id: str | None = None, project_key: str | None = None, test_suite_key: str | None = None): |
| 187 | + click.echo(f"run-tests for suite: {test_suite_id or test_suite_key}") |
| 188 | + # For backward compatibility |
| 189 | + if not test_suite_id: |
| 190 | + test_suites = TestSuite.select_minimal_where( |
| 191 | + TestSuite.project_code == project_key, |
| 192 | + TestSuite.test_suite == test_suite_key, |
| 193 | + ) |
| 194 | + if test_suites: |
| 195 | + test_suite_id = test_suites[0].id |
| 196 | + message = run_test_execution(test_suite_id) |
184 | 197 | click.echo("\n" + message) |
185 | 198 |
|
186 | 199 |
|
@@ -366,24 +379,27 @@ def quick_start( |
366 | 379 |
|
367 | 380 | click.echo("loading initial data") |
368 | 381 | run_quick_start_increment(0) |
369 | | - minutes_offset = -30*24*60 # 1 month ago |
370 | | - table_group_id="0ea85e17-acbe-47fe-8394-9970725ad37d" |
| 382 | + now_date = datetime.now(UTC) |
| 383 | + time_delta = timedelta(days=-30) # 1 month ago |
| 384 | + table_group_id = "0ea85e17-acbe-47fe-8394-9970725ad37d" |
| 385 | + test_suite_id = "9df7489d-92b3-49f9-95ca-512160d7896f" |
371 | 386 |
|
372 | 387 | click.echo(f"run-profile with table_group_id: {table_group_id}") |
373 | | - message = run_profiling(table_group_id, minutes_offset=minutes_offset) |
| 388 | + message = run_profiling(table_group_id, run_date=now_date + time_delta) |
374 | 389 | click.echo("\n" + message) |
375 | 390 |
|
376 | 391 | LOG.info(f"run-test-generation with table_group_id: {table_group_id} test_suite: {settings.DEFAULT_TEST_SUITE_KEY}") |
377 | 392 | message = run_test_gen_queries(table_group_id, settings.DEFAULT_TEST_SUITE_KEY) |
378 | 393 | click.echo("\n" + message) |
379 | 394 |
|
380 | | - run_execution_steps(settings.PROJECT_KEY, settings.DEFAULT_TEST_SUITE_KEY, minutes_offset=minutes_offset) |
| 395 | + run_test_execution(test_suite_id, run_date=now_date + time_delta) |
381 | 396 |
|
382 | | - for iteration in range(1, 4): |
383 | | - click.echo(f"Running iteration: {iteration} / 3") |
384 | | - minutes_offset = -10*24*60 * (3-iteration) |
| 397 | + total_iterations = 3 |
| 398 | + for iteration in range(1, total_iterations + 1): |
| 399 | + click.echo(f"Running iteration: {iteration} / {total_iterations}") |
| 400 | + run_date = now_date + timedelta(days=-10 * (total_iterations - iteration)) # 10 day increments |
385 | 401 | run_quick_start_increment(iteration) |
386 | | - run_execution_steps(settings.PROJECT_KEY, settings.DEFAULT_TEST_SUITE_KEY, minutes_offset=minutes_offset) |
| 402 | + run_test_execution(test_suite_id, run_date=run_date) |
387 | 403 |
|
388 | 404 | click.echo("Quick start has successfully finished.") |
389 | 405 |
|
|
0 commit comments