test_progress.py 1.78 KB
Newer Older
Jay Zoldak committed
1
from django.test import TestCase
2 3 4 5 6
from courseware import progress
from mock import MagicMock


class ProgessTests(TestCase):
Jay Zoldak committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
        def setUp(self):

                self.d = dict({'duration_total': 0,
            'duration_watched': 0,
            'done': True,
            'questions_correct': 4,
            'questions_incorrect': 0,
            'questions_total': 0})

                self.c = progress.completion()
                self.c2 = progress.completion()
                self.c2.dict = dict({'duration_total': 0,
            'duration_watched': 0,
            'done': True,
            'questions_correct': 2,
            'questions_incorrect': 1,
            'questions_total': 0})

                self.cplusc2 = dict({'duration_total': 0,
            'duration_watched': 0,
            'done': True,
            'questions_correct': 2,
            'questions_incorrect': 1,
            'questions_total': 0})

                self.oth = dict({'duration_total': 0,
            'duration_watched': 0,
            'done': True,
            'questions_correct': 4,
            'questions_incorrect': 0,
            'questions_total': 7})

                self.x = MagicMock()
                self.x.dict = self.oth

                self.d_oth = {'duration_total': 0,
            'duration_watched': 0,
            'done': True,
            'questions_correct': 4,
            'questions_incorrect': 0,
            'questions_total': 7}

        def test_getitem(self):
                self.assertEqual(self.c.__getitem__('duration_watched'), 0)

        def test_setitem(self):
                self.c.__setitem__('questions_correct', 4)
                self.assertEqual(str(self.c), str(self.d))

        def test_repr(self):
                self.assertEqual(self.c.__repr__(), str(progress.completion()))