Skip to content

Commit

Permalink
Fix random fixtures crashes (#3693)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeD1rk authored May 29, 2024
1 parent 12abd4e commit 9835df7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
26 changes: 26 additions & 0 deletions website/partners/migrations/0029_alter_partner_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 5.0.2 on 2024-05-22 19:06

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("partners", "0028_alter_partner_alternate_logo_alter_partner_logo_and_more"),
]

operations = [
migrations.AlterField(
model_name="partner",
name="address",
field=models.CharField(
max_length=100,
validators=[
django.core.validators.RegexValidator(
message="Enter a valid address",
regex="^([^/@:;%_]+) \\d+([^/@:;%_]*)",
)
],
),
),
]
8 changes: 2 additions & 6 deletions website/partners/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ class Partner(models.Model):
max_length=100,
validators=[
RegexValidator(
regex=(
r"^([1-9][e][\s])*([ëéÉËa-zA-Z]"
r"+(([\.][\s])|([\s]))?)+[1-9][0-9]"
r"*(([-][1-9][0-9]*)|([\s]?[ëéÉËa-zA-Z]+))?$"
),
message=_("Enter a valid address"),
regex=r"^([^/@:;%_]+) \d+([^/@:;%_]*)",
message="Enter a valid address",
)
],
)
Expand Down
12 changes: 8 additions & 4 deletions website/utils/management/commands/createfixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@


def _generate_title():
words = _faker.words(random.randint(1, 3))
words = _faker.words(random.randint(2, 4))
return " ".join([word.capitalize() for word in words])


Expand Down Expand Up @@ -237,7 +237,7 @@ def create_member_group(self, group_model):
if random.random() < 0.1:
month = timedelta(days=30)
member_group.until = _faker.date_time_between_dates(
member_group.since, member_group.since + 30 * month
member_group.since + 12 * month, member_group.since + 60 * month
).date()

member_group.active = random.random() < 0.9
Expand Down Expand Up @@ -273,12 +273,16 @@ def create_member_group_membership(self, member, group):

today = date.today()
membership.since = _faker.date_time_between_dates(
group.since, group.until
group.since,
group.until - timedelta(days=3)
if group.until
else group.since + timedelta(days=365),
).date()

if random.random() < 0.2 and membership.since < today:
membership.until = _faker.date_time_between_dates(
membership.since, group.until
membership.since,
group.until if group.until else group.since + timedelta(days=2 * 365),
).date()

membership.full_clean()
Expand Down

0 comments on commit 9835df7

Please sign in to comment.