Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: create Experiment and Phase object in bootstrap.py #1361

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .env-github-actions
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ SQL_HOST=db
SQL_PORT=5432
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
Expand Down
9 changes: 6 additions & 3 deletions backend/experiment/management/commands/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand All @@ -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
Expand Down
20 changes: 15 additions & 5 deletions backend/experiment/management/tests.py
Original file line number Diff line number Diff line change
@@ -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):

Expand All @@ -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)