Skip to content

Commit

Permalink
Merge pull request #2620 from bcgov/test-data
Browse files Browse the repository at this point in the history
Test data
  • Loading branch information
Sepehr-Sobhani authored Dec 24, 2024
2 parents af6d0a5 + 220956b commit 0e93aea
Show file tree
Hide file tree
Showing 19 changed files with 2,620 additions and 18 deletions.
5 changes: 5 additions & 0 deletions bc_obps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ superuser: ## create a superuser
superuser:
$(POETRY_RUN) python $(MANAGE_PY) create_superuser

loadfixtures_v1: ## add all registration v1 fixture files to the db
loadfixtures_v1:
$(POETRY_RUN) python $(MANAGE_PY) load_fixtures_v1 $(ARGS)
$(POETRY_RUN) python $(MANAGE_PY) load_reporting_fixtures $(ARGS)

loadfixtures: ## add all registration fixture files to the db
loadfixtures:
$(POETRY_RUN) python $(MANAGE_PY) load_fixtures $(ARGS)
Expand Down
16 changes: 10 additions & 6 deletions bc_obps/common/management/commands/load_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ def handle(self, *args, **options):
f'{fixture_base_dir}/user_operator.json',
],
"admin-industry_user": [
fixture.replace('user_operator.json', 'admin/user_operator.json')
if 'user_operator.json' in fixture
else fixture
(
fixture.replace('user_operator.json', 'admin/user_operator.json')
if 'user_operator.json' in fixture
else fixture
)
for fixture in fixtures_base
],
"admin-industry_user_operator": [
fixture.replace('user_operator.json', 'admin/user_operator_approved.json')
if 'user_operator.json' in fixture
else fixture
(
fixture.replace('user_operator.json', 'admin/user_operator_approved.json')
if 'user_operator.json' in fixture
else fixture
)
for fixture in fixtures_base
],
# Add more workflows here
Expand Down
67 changes: 67 additions & 0 deletions bc_obps/common/management/commands/load_fixtures_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from django.core.management.base import BaseCommand
from django.core.management import call_command


class Command(BaseCommand):
help = 'Load fixtures for specified workflow or all fixtures if no argument provided'

def add_arguments(self, parser):
parser.add_argument('workflow', nargs='?', type=str, help='Name of the workflow')

def handle(self, *args, **options):
fixture_base_dir = 'registration/fixtures/mock/v1'
fixtures_base = [ # Order of fixtures is important
f'{fixture_base_dir}/address.json',
f'{fixture_base_dir}/user.json',
f'{fixture_base_dir}/contact.json',
f'{fixture_base_dir}/bc_obps_regulated_operation.json',
f'{fixture_base_dir}/bc_greenhouse_gas_id.json',
f'{fixture_base_dir}/operator.json',
f'{fixture_base_dir}/operation.json',
f'{fixture_base_dir}/multiple_operator.json',
f'{fixture_base_dir}/document.json',
f'{fixture_base_dir}/user_operator.json',
f'{fixture_base_dir}/parent_operator.json',
f'{fixture_base_dir}/partner_operator.json',
]

workflow_fixtures = {
"cas_admin": [
f'{fixture_base_dir}/address.json',
f'{fixture_base_dir}/user.json',
f'{fixture_base_dir}/contact.json',
f'{fixture_base_dir}/bc_obps_regulated_operation.json',
f'{fixture_base_dir}/bc_greenhouse_gas_id.json',
f'{fixture_base_dir}/operator.json',
f'{fixture_base_dir}/operation.json',
f'{fixture_base_dir}/user_operator.json',
],
"admin-industry_user": [
(
fixture.replace('user_operator.json', 'admin/user_operator.json')
if 'user_operator.json' in fixture
else fixture
)
for fixture in fixtures_base
],
"admin-industry_user_operator": [
(
fixture.replace('user_operator.json', 'admin/user_operator_approved.json')
if 'user_operator.json' in fixture
else fixture
)
for fixture in fixtures_base
],
# Add more workflows here
}

if 'workflow' in options and options['workflow'] in workflow_fixtures:
fixtures = workflow_fixtures[options['workflow']]
else:
# If no workflow specified, load all fixtures

fixtures = fixtures_base

for fixture in fixtures:
self.stdout.write(self.style.SUCCESS(f"Loading: {fixture}"))
call_command('loaddata', fixture)
4 changes: 2 additions & 2 deletions bc_obps/registration/api/v1/e2e_test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def v1_setup(
call_command('truncate_dev_data_tables')
return HttpResponse("Test setup complete.", status=200)
if load_only: # only load the data
call_command('load_fixtures', workflow)
call_command('load_fixtures_v1', workflow)
return HttpResponse("Test setup complete.", status=200)
call_command('truncate_dev_data_tables')
call_command('load_fixtures', workflow)
call_command('load_fixtures_v1', workflow)
return HttpResponse("Test setup complete.", status=200)
except Exception as e:
return HttpResponse(f"Test setup failed. Reason:{e}", status=500)
Expand Down
13 changes: 3 additions & 10 deletions bc_obps/registration/fixtures/mock/operator.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@
"model": "registration.operator",
"pk": "685d581b-5698-411f-ae00-de1d97334a71",
"fields": {
"legal_name": "Operator 1 Legal Name",
"trade_name": "Operator 1 Trade Name",
"legal_name": "Alpha Enterprises",
"cra_business_number": 123456789,
"bc_corporate_registry_number": "abc1234567",
"business_structure": "Sole Proprietorship",
"physical_address": 3,
"mailing_address": 4,
"website": "http://www.example.com",
"documents": [],
"contacts": [],
"status": "Draft",
"is_new": true,
"verified_at": null,
"verified_by": null
"status": "Approved",
"is_new": false
}
},
{
Expand Down
212 changes: 212 additions & 0 deletions bc_obps/registration/fixtures/mock/v1/address.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
[
{
"model": "registration.address",
"pk": 1,
"fields": {
"street_address": "123 Main St",
"municipality": "Cityville",
"province": "ON",
"postal_code": "A1B 2C3"
}
},
{
"model": "registration.address",
"pk": 2,
"fields": {
"street_address": "456 Elm St",
"municipality": "Townsville",
"province": "BC",
"postal_code": "X0Y 1Z0"
}
},
{
"model": "registration.address",
"pk": 3,
"fields": {
"street_address": "123 Main St",
"municipality": "City",
"province": "ON",
"postal_code": "A1B 2C3"
}
},
{
"model": "registration.address",
"pk": 4,
"fields": {
"street_address": "789 Oak St",
"municipality": "Village",
"province": "BC",
"postal_code": "M2N 3P4"
}
},
{
"model": "registration.address",
"pk": 5,
"fields": {
"street_address": "101 Maple St",
"municipality": "Hamlet",
"province": "QC",
"postal_code": "H3Z 2Y7"
}
},
{
"model": "registration.address",
"pk": 6,
"fields": {
"street_address": "202 Pine St",
"municipality": "Borough",
"province": "AB",
"postal_code": "T5K 1P2"
}
},
{
"model": "registration.address",
"pk": 7,
"fields": {
"street_address": "303 Cedar St",
"municipality": "Metropolis",
"province": "ON",
"postal_code": "M4B 1B3"
}
},
{
"model": "registration.address",
"pk": 8,
"fields": {
"street_address": "404 Birch St",
"municipality": "Uptown",
"province": "BC",
"postal_code": "V6B 2W3"
}
},
{
"model": "registration.address",
"pk": 9,
"fields": {
"street_address": "505 Spruce St",
"municipality": "Downtown",
"province": "ON",
"postal_code": "K1A 0B1"
}
},
{
"model": "registration.address",
"pk": 10,
"fields": {
"street_address": "606 Fir St",
"municipality": "Suburbia",
"province": "QC",
"postal_code": "G1V 4N7"
}
},
{
"model": "registration.address",
"pk": 11,
"fields": {
"street_address": "707 Willow St",
"municipality": "Riverside",
"province": "MB",
"postal_code": "R3C 4A5"
}
},
{
"model": "registration.address",
"pk": 12,
"fields": {
"street_address": "808 Poplar St",
"municipality": "Lakeside",
"province": "NS",
"postal_code": "B3H 2Y9"
}
},
{
"model": "registration.address",
"pk": 13,
"fields": {
"street_address": "909 Aspen St",
"municipality": "Hillside",
"province": "NB",
"postal_code": "E3B 1A1"
}
},
{
"model": "registration.address",
"pk": 14,
"fields": {
"street_address": "1010 Redwood St",
"municipality": "Seaside",
"province": "PE",
"postal_code": "C1A 7N8"
}
},
{
"model": "registration.address",
"pk": 15,
"fields": {
"street_address": "1111 Chestnut St",
"municipality": "Mountainview",
"province": "NL",
"postal_code": "A1C 5H7"
}
},
{
"model": "registration.address",
"pk": 16,
"fields": {
"street_address": "1212 Walnut St",
"municipality": "Forestville",
"province": "SK",
"postal_code": "S7K 3R5"
}
},
{
"model": "registration.address",
"pk": 17,
"fields": {
"street_address": "1313 Hickory St",
"municipality": "Prairie",
"province": "MB",
"postal_code": "R2C 4A6"
}
},
{
"model": "registration.address",
"pk": 18,
"fields": {
"street_address": "1414 Sycamore St",
"municipality": "Baytown",
"province": "ON",
"postal_code": "L4W 5N8"
}
},
{
"model": "registration.address",
"pk": 19,
"fields": {
"street_address": "1515 Magnolia St",
"municipality": "Harbor",
"province": "BC",
"postal_code": "V8W 1N4"
}
},
{
"model": "registration.address",
"pk": 20,
"fields": {
"street_address": "1616 Dogwood St",
"municipality": "Cove",
"province": "QC",
"postal_code": "J4Z 2Y8"
}
},
{
"model": "registration.address",
"pk": 21,
"fields": {
"street_address": "1717 Alder St",
"municipality": "Grove",
"province": "ON",
"postal_code": "N2L 3G1"
}
}
]
Loading

0 comments on commit 0e93aea

Please sign in to comment.