From 0198441555c0b6c5a42b15c23fd984612a9f75bf Mon Sep 17 00:00:00 2001 From: Tom Walker Date: Wed, 18 Jun 2014 19:05:51 +0100 Subject: [PATCH] working on the tests --- multichoice/tests.py | 35 +++++++++++++++++++++++------------ quiz/models.py | 3 ++- quiz/tests.py | 17 ++++------------- true_false/models.py | 4 +++- true_false/tests.py | 11 ++++++++--- 5 files changed, 40 insertions(+), 30 deletions(-) diff --git a/multichoice/tests.py b/multichoice/tests.py index 501deb7..89bd22d 100644 --- a/multichoice/tests.py +++ b/multichoice/tests.py @@ -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) diff --git a/quiz/models.py b/quiz/models.py index d505fc8..811aca3 100644 --- a/quiz/models.py +++ b/quiz/models.py @@ -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): diff --git a/quiz/tests.py b/quiz/tests.py index 501deb7..cf4e4db 100644 --- a/quiz/tests.py +++ b/quiz/tests.py @@ -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") diff --git a/true_false/models.py b/true_false/models.py index f9ca634..40b74d5 100644 --- a/true_false/models.py +++ b/true_false/models.py @@ -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 diff --git a/true_false/tests.py b/true_false/tests.py index fa705ba..8f15cc2 100644 --- a/true_false/tests.py +++ b/true_false/tests.py @@ -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) -- 2.39.5