-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add management command and workflow for generating live test data fro…
…m historical exports (#2569) * First commit of E2E improvements For running in production-like environments. * add e2e generator workflow and profile changes * lint * double os * more linting somehow * don't do generation via profile * Linting. Runs defaults * invoke via workflow instead of profile * Apply suggestions from code review * lint --------- Co-authored-by: Matt Jadud <[email protected]>
- Loading branch information
Showing
6 changed files
with
133 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
name: "Task: run Django command to generate and disseminate test data for non-production environments." | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
environment: | ||
required: true | ||
type: choice | ||
description: Which environment should the workflow run on? | ||
options: | ||
- dev | ||
- staging | ||
dbkeys: | ||
required: false | ||
type: string | ||
description: Comma-separated list of report-IDs. | ||
years: | ||
required: false | ||
type: string | ||
description: Comma-separated list of report years. The list of years needs to be the same lenght as the list of dbkeys. | ||
|
||
jobs: | ||
end-to-end-test-data: | ||
name: Generate and disseminate end-to-end test data in ${{ inputs.environment }} database | ||
runs-on: ubuntu-latest | ||
environment: ${{ inputs.environment }} | ||
env: | ||
space: ${{ inputs.environment }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run Django command to generate and disseminate end-to-end test data in ${{ inputs.environment }} | ||
uses: cloud-gov/cg-cli-tools@main | ||
with: | ||
cf_username: ${{ secrets.CF_USERNAME }} | ||
cf_password: ${{ secrets.CF_PASSWORD }} | ||
cf_org: gsa-tts-oros-fac | ||
cf_space: ${{ env.space }} | ||
command: cf run-task gsa-fac -k 2G -m 2G --name generate_e2e_data --command "python manage.py end_to_end_test_data_generator --dbkeys ${{ inputs.dbkeys }} --years ${{ inputs.years }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
backend/dissemination/management/commands/end_to_end_test_data_generator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import os | ||
import logging | ||
import sys | ||
|
||
from config.settings import ENVIRONMENT | ||
from django.core.management.base import BaseCommand | ||
from dissemination.workbooklib.end_to_end_core import run_end_to_end | ||
|
||
CYPRESS_TEST_EMAIL_ADDR = os.getenv("CYPRESS_LOGIN_TEST_EMAIL_AUDITEE") | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument("--email", type=str, required=False) | ||
parser.add_argument("--dbkeys", type=str, required=False, default="") | ||
parser.add_argument("--years", type=str, required=False, default="") | ||
|
||
def handle(self, *args, **options): | ||
dbkeys_str = options["dbkeys"] | ||
years_str = options["years"] | ||
dbkeys = dbkeys_str.split(",") | ||
years = years_str.split(",") | ||
|
||
if len(dbkeys) != len(years): | ||
logger.error( | ||
"Received {} dbkeys and {} years. Must be equal. Exiting.".format( | ||
len(dbkeys), len(years) | ||
) | ||
) | ||
sys.exit(-1) | ||
|
||
lengths = [len(s) == 2 for s in years] | ||
if dbkeys_str and years_str and (not all(lengths)): | ||
logger.error("Years must be two digits. Exiting.") | ||
sys.exit(-2) | ||
|
||
email = options.get("email", CYPRESS_TEST_EMAIL_ADDR) | ||
|
||
defaults = [ | ||
(182926, 22), | ||
(181744, 22), | ||
(191734, 22), | ||
] | ||
|
||
if ENVIRONMENT in ["LOCAL", "DEVELOPMENT", "PREVIEW", "STAGING"]: | ||
if dbkeys_str and years_str: | ||
logger.info( | ||
f"Generating test reports for DBKEYS: {dbkeys_str} and YEARS: {years_str}" | ||
) | ||
for dbkey, year in zip(dbkeys, years): | ||
run_end_to_end(email, dbkey, year) | ||
else: | ||
for pair in defaults: | ||
logger.info("Running {}-{} end-to-end".format(pair[0], pair[1])) | ||
run_end_to_end(email, str(pair[0]), str(pair[1])) | ||
else: | ||
logger.error( | ||
"Cannot run end-to-end workbook generation in production. Exiting." | ||
) | ||
sys.exit(-3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters