From c5e317b070fe24ad77544f68bf69ca1f3edb13b1 Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Tue, 12 Nov 2024 13:37:24 +0100 Subject: [PATCH 1/3] close #1266: create Experiment and Phase object in bootstrap.py --- .../management/commands/bootstrap.py | 9 ++++++--- .../commands/templates/experiment.py | 6 +++--- backend/experiment/management/tests.py | 20 ++++++++++++++----- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/backend/experiment/management/commands/bootstrap.py b/backend/experiment/management/commands/bootstrap.py index b78bd9c8e..5c88da199 100644 --- a/backend/experiment/management/commands/bootstrap.py +++ b/backend/experiment/management/commands/bootstrap.py @@ -2,7 +2,7 @@ from django.core.management.base import BaseCommand from django.contrib.auth.models import User -from experiment.models import Block +from experiment.models import Block, Experiment, Phase from section.models import Playlist from question.questions import create_default_questions @@ -17,12 +17,15 @@ def handle(self, *args, **options): if User.objects.count() == 0: management.call_command("createsuperuser", "--no-input") print("Created superuser") - if Block.objects.count() == 0: + if Experiment.objects.count() == 0: + experiment = Experiment.objects.create(slug="test") + phase = Phase.objects.create(experiment=experiment) playlist = Playlist.objects.create(name="Empty Playlist") block = Block.objects.create( + phase=phase, rules="RHYTHM_BATTERY_FINAL", slug="gold-msi", ) block.playlists.add(playlist) block.add_default_question_series() - print("Created default block") + print("Created default experiment, phase and block") diff --git a/backend/experiment/management/commands/templates/experiment.py b/backend/experiment/management/commands/templates/experiment.py index b0eeb4af1..d932bd961 100644 --- a/backend/experiment/management/commands/templates/experiment.py +++ b/backend/experiment/management/commands/templates/experiment.py @@ -41,7 +41,7 @@ def get_intro_explainer(self): step_numbers=True ) - def next_round(self, session: Session): + def next_round(self, session: Session) -> list: # ask any questions defined in the admin interface if session.get_rounds_passed() == 0: actions = [self.get_intro_explainer()] @@ -63,9 +63,9 @@ def next_round(self, session: Session): ) ] else: - return self.get_trial(session) + return self.get_next_trial(session) - def get_trial(self, session): + def get_next_trial(self, session) -> Trial: # define a key, by which responses to this trial can be found in the database key = 'test_trial' # get a random section diff --git a/backend/experiment/management/tests.py b/backend/experiment/management/tests.py index a030666e8..c7802da88 100644 --- a/backend/experiment/management/tests.py +++ b/backend/experiment/management/tests.py @@ -1,10 +1,13 @@ -from django.core.management import call_command -from django.test import TestCase import csv -from django.conf import settings from os.path import join from os import remove - + +from django.core.management import call_command +from django.test import TestCase +from django.conf import settings + +from experiment.models import Block, Experiment, Phase +from section.models import Playlist class CompilePlaylistTest(TestCase): @@ -23,8 +26,15 @@ def test_output_csv(self): self.assertEqual(row['duration'], '20.025850340136053') self.assertEqual(row['tag'], '0') self.assertEqual(row['group'], '0') - finally: + finally: remove(filename) # Make sure csv file is deleted even if tests fail +class BootrapTest(TestCase): + def test_bootstrap(self): + call_command("bootstrap") + self.assertEqual(Experiment.objects.count(), 1) + self.assertEqual(Phase.objects.count(), 1) + self.assertEqual(Block.objects.count(), 1) + self.assertEqual(Playlist.objects.count(), 1) From da6d077fcb881de057a825e51505340b80f16627 Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Tue, 12 Nov 2024 13:54:55 +0100 Subject: [PATCH 2/3] fix GitHub action: provide Django superuser name / password for test --- .env-github-actions | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.env-github-actions b/.env-github-actions index 8e7f7c7f7..29ffc2466 100644 --- a/.env-github-actions +++ b/.env-github-actions @@ -5,6 +5,8 @@ SQL_HOST=db SQL_PORT=5432 AML_SECRET_KEY=amlsecretkey AML_LOCATION_PROVIDER=http://ip2country:5000/{} +DJANGO_SUPERUSER_USERNAME=admin +DJANGO_SUPERUSER_PASSWORD=admin AML_DEBUG=True DJANGO_SETTINGS_MODULE=aml.development_settings CSRF_TRUSTED_ORIGINS=http://localhost:3000 From b10168bc9444292c92b8469f5e648e328350fa57 Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Wed, 13 Nov 2024 09:08:14 +0100 Subject: [PATCH 3/3] add user email for testing --- .env-github-actions | 1 + 1 file changed, 1 insertion(+) diff --git a/.env-github-actions b/.env-github-actions index 29ffc2466..1058b6fa9 100644 --- a/.env-github-actions +++ b/.env-github-actions @@ -7,6 +7,7 @@ AML_SECRET_KEY=amlsecretkey AML_LOCATION_PROVIDER=http://ip2country:5000/{} DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_PASSWORD=admin +DJANGO_SUPERUSER_EMAIL=mail@example.com AML_DEBUG=True DJANGO_SETTINGS_MODULE=aml.development_settings CSRF_TRUSTED_ORIGINS=http://localhost:3000