Skip to content

Commit

Permalink
Slightly improve test factories (#482)
Browse files Browse the repository at this point in the history
Whic working on the repo cleanup, I noticed frequent test failures related to `Branch.name` not being unique enough.
This fixes that along with some other improvements, like being able to use `CommitWithReportFactory` in `worker` which was not possible previously because of imports that are only valid within `api`.
  • Loading branch information
Swatinem authored Jan 20, 2025
1 parent 3a2414f commit d1762e3
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions shared/django_apps/core/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Meta:
model = models.Repository

private = True
name = factory.Faker("word")
name = factory.Faker("slug")
service_id = factory.Sequence(lambda n: f"{n}")
author = factory.SubFactory(OwnerFactory)
language = factory.Iterator(
Expand Down Expand Up @@ -109,8 +109,7 @@ def _create(cls, model_class, *args, **kwargs):
# The following replaces the old `commits.report` JSON column
# TODO: we may want to find another way to create this since the imports below
# create a cyclic dependency

from reports.tests.factories import (
from shared.django_apps.reports.tests.factories import (
CommitReportFactory,
ReportLevelTotalsFactory,
UploadFactory,
Expand Down Expand Up @@ -222,7 +221,7 @@ class Meta:
model = models.Branch

repository = factory.SubFactory(RepositoryFactory)
name = factory.Faker("sentence", nb_words=1)
name = factory.Faker("slug")
head = factory.LazyAttribute(lambda o: sha1(o.name.encode("utf-8")).hexdigest())


Expand Down

0 comments on commit d1762e3

Please sign in to comment.