|
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, |
|
29 | 28 | ) |
30 | 29 | from testgen.commands.run_launch_db_config import run_launch_db_config |
31 | 30 | from testgen.commands.run_observability_exporter import run_observability_exporter |
32 | | -from testgen.commands.run_profiling_bridge import run_profiling_queries |
| 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 |
|
@@ -114,20 +115,16 @@ def cli(ctx: Context, verbose: bool): |
114 | 115 |
|
115 | 116 | @register_scheduler_job |
116 | 117 | @cli.command("run-profile", help="Generates a new profile of the table group.") |
117 | | -@pass_configuration |
118 | 118 | @click.option( |
119 | 119 | "-tg", |
120 | 120 | "--table-group-id", |
121 | 121 | required=True, |
122 | 122 | type=click.STRING, |
123 | | - help="The identifier for the table group used during a profile run. Use a table_group_id shown in list-table-groups.", |
| 123 | + help="ID of the table group to profile. Use a table_group_id shown in list-table-groups.", |
124 | 124 | ) |
125 | | -def run_profile(configuration: Configuration, table_group_id: str): |
| 125 | +def run_profile(table_group_id: str): |
126 | 126 | click.echo(f"run-profile with table_group_id: {table_group_id}") |
127 | | - spinner = None |
128 | | - if not configuration.verbose: |
129 | | - spinner = MoonSpinner("Processing ... ") |
130 | | - message = run_profiling_queries(table_group_id, spinner=spinner) |
| 127 | + message = run_profiling(table_group_id) |
131 | 128 | click.echo("\n" + message) |
132 | 129 |
|
133 | 130 |
|
@@ -163,28 +160,40 @@ def run_test_generation(configuration: Configuration, table_group_id: str, test_ |
163 | 160 |
|
164 | 161 | @register_scheduler_job |
165 | 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 | +) |
166 | 170 | @click.option( |
167 | 171 | "-pk", |
168 | 172 | "--project-key", |
169 | | - help="The identifier for a TestGen project. Use a project_key shown in list-projects.", |
| 173 | + help="DEPRECATED. Use --test-suite-id instead.", |
170 | 174 | required=False, |
171 | 175 | type=click.STRING, |
172 | 176 | default=settings.PROJECT_KEY, |
173 | 177 | ) |
174 | 178 | @click.option( |
175 | 179 | "-ts", |
176 | 180 | "--test-suite-key", |
177 | | - 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.", |
178 | 182 | required=False, |
179 | 183 | default=settings.DEFAULT_TEST_SUITE_KEY, |
180 | 184 | ) |
181 | | -@pass_configuration |
182 | | -def run_tests(configuration: Configuration, project_key: str, test_suite_key: str): |
183 | | - click.echo(f"run-tests for suite: {test_suite_key}") |
184 | | - spinner = None |
185 | | - if not configuration.verbose: |
186 | | - spinner = MoonSpinner("Processing ... ") |
187 | | - 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) |
188 | 197 | click.echo("\n" + message) |
189 | 198 |
|
190 | 199 |
|
@@ -370,27 +379,27 @@ def quick_start( |
370 | 379 |
|
371 | 380 | click.echo("loading initial data") |
372 | 381 | run_quick_start_increment(0) |
373 | | - minutes_offset = -30*24*60 # 1 month ago |
374 | | - 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" |
375 | 386 |
|
376 | 387 | click.echo(f"run-profile with table_group_id: {table_group_id}") |
377 | | - spinner = None |
378 | | - if not configuration.verbose: |
379 | | - spinner = MoonSpinner("Processing ... ") |
380 | | - message = run_profiling_queries(table_group_id, spinner=spinner, minutes_offset=minutes_offset) |
| 388 | + message = run_profiling(table_group_id, run_date=now_date + time_delta) |
381 | 389 | click.echo("\n" + message) |
382 | 390 |
|
383 | 391 | LOG.info(f"run-test-generation with table_group_id: {table_group_id} test_suite: {settings.DEFAULT_TEST_SUITE_KEY}") |
384 | 392 | message = run_test_gen_queries(table_group_id, settings.DEFAULT_TEST_SUITE_KEY) |
385 | 393 | click.echo("\n" + message) |
386 | 394 |
|
387 | | - 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) |
388 | 396 |
|
389 | | - for iteration in range(1, 4): |
390 | | - click.echo(f"Running iteration: {iteration} / 3") |
391 | | - 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 |
392 | 401 | run_quick_start_increment(iteration) |
393 | | - 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) |
394 | 403 |
|
395 | 404 | click.echo("Quick start has successfully finished.") |
396 | 405 |
|
|
0 commit comments