]> git.parisson.com Git - django_quiz.git/commitdiff
working on the tests
authorTom Walker <tomwalker0472@gmail.com>
Wed, 18 Jun 2014 18:05:51 +0000 (19:05 +0100)
committerTom Walker <tomwalker0472@gmail.com>
Wed, 18 Jun 2014 18:05:51 +0000 (19:05 +0100)
multichoice/tests.py
quiz/models.py
quiz/tests.py
true_false/models.py
true_false/tests.py

index 501deb776c16733b19f3509d86e125df78958261..89bd22dca252925518b762cdb8b31264a26fef69 100644 (file)
@@ -1,16 +1,27 @@
-"""
-This file demonstrates writing tests using the unittest module. These will pass
-when you run "manage.py test".
+from django.test import TestCase
 
-Replace this with more appropriate tests for your application.
-"""
+from multichoice.models import MCQuestion, Answer
 
-from django.test import TestCase
+
+class TestMCQuestionModel(TestCase):
+    def setUp(self):
+        q = MCQuestion.objects.create(id = 1,
+                                      content = ("WHAT is the airspeed" +
+                                                 "velocity of an unladen" +
+                                                 "swallow?"),
+                                      explanation = "I, I don't know that!",)
+
+        Answer.objects.create(question = q,
+                              content = "African",
+                              correct = False,)
+
+        Answer.objects.create(question = q,
+                              content = "European",
+                              correct = True)
 
 
-class SimpleTest(TestCase):
-    def test_basic_addition(self):
-        """
-        Tests that 1 + 1 always equals 2.
-        """
-        self.assertEqual(1 + 1, 2)
+    def test_correct_answer(self):
+        china = Country.objects.get(name="China")
+        self.assertEqual(china.population, 1400000000)
+        self.assertEqual(china.climate, 'TEMPERATE')
+        self.assertEqual(china.healthcare, 4)
index d505fc88c5a09cc901a3fa5e547f5f85a85d9aeb..811aca3b96b8d5a4b0bcb24b55c38d78ac012d1c 100644 (file)
@@ -64,6 +64,7 @@ class Category(models.Model):
                                 unique = True,
                                 null = True,)
 
+    objects = CategoryManager()
 
     class Meta:
         verbose_name = "Category"
@@ -362,7 +363,7 @@ class Sitting(models.Model):
         if first_comma == -1 or first_comma == 0:
             return False
 
-        return self.question_list[:first_comma]
+        return int(self.question_list[:first_comma])
 
 
     def remove_first_question(self):
index 501deb776c16733b19f3509d86e125df78958261..cf4e4db0d27523af2608abdebbb213e5ec63d547 100644 (file)
@@ -1,16 +1,7 @@
-"""
-This file demonstrates writing tests using the unittest module. These will pass
-when you run "manage.py test".
-
-Replace this with more appropriate tests for your application.
-"""
-
 from django.test import TestCase
 
+from quiz.models import Category, Quiz, Progress, Sitting, Question
 
-class SimpleTest(TestCase):
-    def test_basic_addition(self):
-        """
-        Tests that 1 + 1 always equals 2.
-        """
-        self.assertEqual(1 + 1, 2)
+class TestCategory(TestCase):
+    def setUp(self):
+        Category.objects.new_category(category = "elderberries")
index f9ca634078c89378c91df5b5c8799b43d0f9d7f3..40b74d5ffa4702398352e9b7d7bdad2be0da92b9 100644 (file)
@@ -11,8 +11,10 @@ class TF_Question(Question):
     def check_if_correct(self, guess):
         if guess == "T":
             guess_bool = True
-        else:
+        elif guess == "F":
             guess_bool = False
+        else:
+            return False
 
         if guess_bool == self.correct:
             return True
index fa705ba53d76f031ab99a5a71d40f6751417bf28..8f15cc2703721afdd2a0a6cc46cdcd14f70c9e07 100644 (file)
@@ -1,6 +1,6 @@
 from django.test import TestCase
 
-from django_quiz.true_false.models import TF_Question
+from true_false.models import TF_Question
 
 
 class TestTrueFalseQuestionModel(TestCase):
@@ -15,7 +15,12 @@ class TestTrueFalseQuestionModel(TestCase):
     def test_true_q(self):
         red = TF_Question.objects.get(explanation = "it is")
         self.assertEqual(red.correct, True)
+        self.assertEqual(red.check_if_correct("T"), True)
+        self.assertEqual(red.check_if_correct("F"), False)
+        self.assertEqual(red.check_if_correct("4"), False)
 
     def test_false_q(self):
-        red = TF_Question.objects.get(explanation = "it is not")
-        self.assertEqual(red.correct, False)
+        blue = TF_Question.objects.get(explanation = "it is not")
+        self.assertEqual(blue.correct, False)
+        self.assertEqual(blue.check_if_correct("T"), False)
+        self.assertEqual(blue.check_if_correct("F"), True)