Skip to content

Commit

Permalink
fix(tests): Add Project to make_fake_chant
Browse files Browse the repository at this point in the history
  • Loading branch information
dchiller committed Jun 18, 2024
1 parent 8084cfa commit 6807731
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions django/cantusdb_project/main_app/tests/make_fakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from main_app.models import Genre
from main_app.models import Notation
from main_app.models import Office
from main_app.models import Project
from main_app.models import Provenance
from main_app.models import Segment
from main_app.models import Sequence
Expand Down Expand Up @@ -151,7 +152,7 @@ def make_fake_chant(
manuscript_syllabized_full_text=None,
next_chant=None,
differentia=None,
segment=None,
project=None,
) -> Chant:
"""Generates a fake Chant object."""
if source is None:
Expand Down Expand Up @@ -189,8 +190,8 @@ def make_fake_chant(
manuscript_syllabized_full_text = faker.sentence(20)
if differentia is None:
differentia = make_random_string(2)
if segment is None:
segment = make_fake_segment()
if project is None:
project = make_fake_project()

chant = Chant.objects.create(
source=source,
Expand Down Expand Up @@ -225,7 +226,7 @@ def make_fake_chant(
indexing_notes=faker.sentence(),
json_info=None,
next_chant=next_chant,
segment=segment,
project=project,
)
chant.refresh_from_db() # several fields (e.g., incipit) are calculated automatically
# upon chant save. By refreshing from db before returning, we ensure all the chant's fields
Expand Down Expand Up @@ -303,6 +304,16 @@ def make_fake_segment(name: str = None, id: int = None) -> Segment:
return segment


def make_fake_project(name: str = None, id: int = None) -> Project:
if name is None:
name = faker.sentence(nb_words=2)
if id is None:
project = Project.objects.create(name=name)
return project
project = Project.objects.create(name=name, id=id)
return project


def make_fake_sequence(source=None, title=None, cantus_id=None) -> Sequence:
"""Generates a fake Sequence object."""
if source is None:
Expand Down

0 comments on commit 6807731

Please sign in to comment.