Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions backend/donations/management/commands/generate_orgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from localflavor.ro.ro_counties import COUNTIES_CHOICES

from donations.models.ngos import Cause, Ngo
from utils.random import random_33p, random_75p
from utils.text.cleanup import clean_slug, strip_accents

fake = Faker("ro_RO")
Expand Down Expand Up @@ -844,13 +845,13 @@ def handle(self, *args, **options):
password=owner_email.split("@")[0],
first_name=first_name,
last_name=last_name,
is_verified=random.choice([True, False]),
is_verified=random_75p(),
)
owner.save()
except IntegrityError:
continue

should_not_have_ngo = random.choice(range(0, 6)) == 3
should_not_have_ngo = random_33p()
if create_user_only or not create_valid and should_not_have_ngo:
continue

Expand All @@ -863,8 +864,8 @@ def handle(self, *args, **options):
"phone": fake.phone_number(),
"email": random.choice([owner_email, fake.email()]),
"website": fake.url(),
"is_active": create_valid or random.choice([True, False]),
"has_online_tax_account": create_valid or random.choice([True, False]),
"is_active": create_valid or random_75p(),
"has_online_tax_account": create_valid or random_75p(),
"ngohub_org_id": random.choice([random.randint(1, 9999), None]) if create_ngohub_id else None,
}
try:
Expand All @@ -879,7 +880,7 @@ def handle(self, *args, **options):
owner.ngo = org
owner.save()

ignore_cause = not create_valid or random.choice(range(0, 6)) == 3
ignore_cause = not create_valid or random_33p()

if ignore_cause:
continue
Expand All @@ -888,7 +889,7 @@ def handle(self, *args, **options):
ngo_cause = Cause.objects.create(
ngo=org,
is_main=True,
allow_online_collection=org.has_online_tax_account and random.choice(range(0, 6)) == 3,
allow_online_collection=org.has_online_tax_account and random_75p(),
slug=kebab_case_name,
name=org_name,
description=fake.paragraph(nb_sentences=3, variable_nb_sentences=True),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from faker import Faker

from donations.models.ngos import Cause, CauseVisibilityChoices, Ngo
from utils.random import random_75p

fake = Faker("ro_RO")

Expand Down Expand Up @@ -301,9 +302,7 @@ def handle(self, *args, **options):
]
)

allow_online_collection = (
ngo.has_online_tax_account if not ngo.has_online_tax_account else random.choice(range(0, 6)) == 3
)
allow_online_collection = ngo.has_online_tax_account and random_75p()
causes.append(
Cause(
ngo=ngo,
Expand Down
36 changes: 36 additions & 0 deletions backend/utils/random.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import random


def random_25p():
"""
25% chance of True
"""
return random.choice((True, False, False, False))


def random_33p():
"""
33% chance of True
"""
return random.choice((True, False, False))


def random_50p():
"""
50% chance of True
"""
return random.choice((True, False))


def random_66p():
"""
66% chance of True
"""
return random.choice((True, True, False))


def random_75p():
"""
75% chance of True
"""
return random.choice((True, True, True, False))
4 changes: 2 additions & 2 deletions backend/utils/staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def reset_staging(generate_orgs_count=0, generate_causes_count=0, generate_donat
logger.info("Deleted all users except the default admins")

# Generate new demo organizations
management.call_command("generate_orgs", generate_orgs_count, valid=True, ngohub=False)
management.call_command("generate_orgs", generate_orgs_count, ngohub=False)
logger.info("Generated %d demo organizations", generate_orgs_count)

# Generate new demo causes
Expand All @@ -88,7 +88,7 @@ def schedule_reset_staging(request):
raise PermissionDenied

logger.info("Scheduling a staging environment reset")
async_task(reset_staging, generate_orgs_count=20, generate_causes_count=25, generate_donations_count=100)
async_task(reset_staging, generate_orgs_count=25, generate_causes_count=30, generate_donations_count=150)

messages.add_message(
request,
Expand Down