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
4 changes: 2 additions & 2 deletions src/apps/api/tests/test_competitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_manual_migration_makes_submissions_from_one_phase_in_another(self):

# make 5 submissions in phase 1
for _ in range(5):
SubmissionFactory(owner=self.creator, phase=self.phase_1, status=Submission.FINISHED)
SubmissionFactory(owner=self.creator, phase=self.phase_1, status=Submission.FINISHED, leaderboard=self.leaderboard)
assert self.phase_1.submissions.count() == 5
assert self.phase_2.submissions.count() == 0

Expand All @@ -130,7 +130,7 @@ def test_manual_migration_makes_submissions_out_of_only_parents_not_children(sel
self.client.login(username='creator', password='creator')

# make 1 submission with 4 children
parent = SubmissionFactory(owner=self.creator, phase=self.phase_1, has_children=True, status=Submission.FINISHED)
parent = SubmissionFactory(owner=self.creator, phase=self.phase_1, has_children=True, status=Submission.FINISHED, leaderboard=self.leaderboard)
for _ in range(4):
# Make a submission _and_ new Task for phase 2
self.phase_2.tasks.add(TaskFactory())
Expand Down
1 change: 1 addition & 0 deletions src/apps/chahub/tests/test_chahub_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def setUp(self):
participant=self.participant,
status='Finished',
is_public=True,
leaderboard=None
)

def test_submission_save_sends_to_chahub(self):
Expand Down
2 changes: 2 additions & 0 deletions src/apps/competitions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,12 @@ def apply_phase_migration(self, current_phase, next_phase, force_migration=False
self.is_migrating = True
self.save()

# Get submissions of current phase with finished status and which are on leaderboard
submissions = Submission.objects.filter(
phase=current_phase,
is_migrated=False,
parent__isnull=True,
leaderboard__isnull=False,
status=Submission.FINISHED
)

Expand Down
4 changes: 3 additions & 1 deletion src/apps/competitions/tests/test_phase_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from competitions.models import Submission, Competition, Phase
from competitions.tasks import do_phase_migrations
from factories import UserFactory, CompetitionFactory, PhaseFactory, SubmissionFactory, CompetitionParticipantFactory, \
TaskFactory
TaskFactory, LeaderboardFactory

twenty_minutes_ago = now() - timedelta(hours=0, minutes=20)
twenty_five_minutes_ago = now() - timedelta(hours=0, minutes=25)
Expand All @@ -22,6 +22,7 @@ def setUp(self):
self.competition = CompetitionFactory(created_by=self.owner, title="Competition One")
self.competition_participant = CompetitionParticipantFactory(user=self.normal_user,
competition=self.competition)
self.leaderboard = LeaderboardFactory()
self.phase1 = PhaseFactory(
competition=self.competition,
auto_migrate_to_this_phase=False,
Expand Down Expand Up @@ -59,6 +60,7 @@ def make_submission(self, **kwargs):
kwargs.setdefault('participant', self.competition_participant)
kwargs.setdefault('phase', self.phase1)
kwargs.setdefault('status', Submission.FINISHED)
kwargs.setdefault('leaderboard', self.leaderboard)
sub = SubmissionFactory(**kwargs)
return sub

Expand Down
17 changes: 9 additions & 8 deletions src/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,22 @@ class Meta:
task = factory.SubFactory(TaskFactory)


class LeaderboardFactory(DjangoModelFactory):
class Meta:
model = Leaderboard

title = factory.Faker('word')
key = factory.Faker('word')


class SubmissionFactory(DjangoModelFactory):
class Meta:
model = Submission

owner = factory.SubFactory(UserFactory)
phase = factory.SubFactory(PhaseFactory)
name = factory.Sequence(lambda n: f'Submission {n}')
leaderboard = factory.SubFactory(LeaderboardFactory)

created_when = factory.Faker('date_time_between', start_date='-5y', end_date='now', tzinfo=UTC)
data = factory.SubFactory(
Expand All @@ -182,14 +191,6 @@ class Meta:
status = factory.LazyAttribute(lambda n: random.choice(['unknown', 'denied', 'approved', 'pending']))


class LeaderboardFactory(DjangoModelFactory):
class Meta:
model = Leaderboard

title = factory.Faker('word')
key = factory.Faker('word')


class ColumnFactory(DjangoModelFactory):
class Meta:
model = Column
Expand Down