From 2409982929ab8915dbb6ef14782a0fd758a3f34b Mon Sep 17 00:00:00 2001
From: Noah Jonah Gente <fu2662cw@mi.fu-berlin.de>
Date: Tue, 25 May 2021 17:51:56 +0200
Subject: [PATCH] Add Question Model and test

---
 .../migrations/0002_auto_20210525_1514.py     | 39 +++++++++++++++++++
 unisportomat/quiz/models.py                   |  6 +++
 unisportomat/quiz/tests.py                    | 13 ++++++-
 3 files changed, 57 insertions(+), 1 deletion(-)
 create mode 100644 unisportomat/quiz/migrations/0002_auto_20210525_1514.py

diff --git a/unisportomat/quiz/migrations/0002_auto_20210525_1514.py b/unisportomat/quiz/migrations/0002_auto_20210525_1514.py
new file mode 100644
index 0000000..e23bd68
--- /dev/null
+++ b/unisportomat/quiz/migrations/0002_auto_20210525_1514.py
@@ -0,0 +1,39 @@
+# Generated by Django 3.2 on 2021-05-25 15:14
+
+import django.core.validators
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ("quiz", "0001_refactor_sport_and_add_criteria"),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name="Question",
+            fields=[
+                (
+                    "id",
+                    models.BigAutoField(
+                        auto_created=True,
+                        primary_key=True,
+                        serialize=False,
+                        verbose_name="ID",
+                    ),
+                ),
+                ("text", models.TextField()),
+            ],
+        ),
+        migrations.AlterField(
+            model_name="criterionrating",
+            name="rating",
+            field=models.IntegerField(
+                validators=[
+                    django.core.validators.MaxValueValidator(10),
+                    django.core.validators.MinValueValidator(1),
+                ]
+            ),
+        ),
+    ]
diff --git a/unisportomat/quiz/models.py b/unisportomat/quiz/models.py
index a3b25fd..6df7d94 100644
--- a/unisportomat/quiz/models.py
+++ b/unisportomat/quiz/models.py
@@ -54,3 +54,9 @@ class Criterion(models.Model):
     """
 
     name = models.TextField()
+
+
+class Question(models.Model):
+    """Defines a Question that is assigned to exactly one Criterion"""
+
+    text = models.TextField()
diff --git a/unisportomat/quiz/tests.py b/unisportomat/quiz/tests.py
index 3c8a3f0..a0c4bde 100644
--- a/unisportomat/quiz/tests.py
+++ b/unisportomat/quiz/tests.py
@@ -1,7 +1,7 @@
 """ This module tests all our quiz models"""
 
 from django.test import TestCase
-from .models import Sport, Criterion
+from .models import Sport, Criterion, Question
 
 
 class SportModelTest(TestCase):
@@ -74,3 +74,14 @@ class CriterionModelTest(TestCase):
         Criterion(name=name).save()
         test_criterion = Criterion.objects.first()
         self.assertEqual(test_criterion.name, name)
+
+
+class QuestionModelTest(TestCase):
+    """Tests the Question model"""
+
+    def test_question_can_be_saved_and_loaded(self):
+        """New Question is saved to the db and can be loaded"""
+        text = "Ich trainiere gerne mit anderen im Team"
+        Question(text=text).save()
+        test_question = Question.objects.first()
+        self.assertEqual(test_question.text, text)
-- 
GitLab