diff options
author | prathamesh | 2018-02-08 14:29:38 +0530 |
---|---|---|
committer | adityacp | 2018-03-21 17:32:41 +0530 |
commit | b3f5721f3cf4225902000f2f76e5138135383792 (patch) | |
tree | 21ab4b9c9d4ad5d900c1de15f7254faea689094b /grades/tests | |
parent | 06abd01fd28eb10aafd18dd60b790549e0233edc (diff) | |
download | online_test-b3f5721f3cf4225902000f2f76e5138135383792.tar.gz online_test-b3f5721f3cf4225902000f2f76e5138135383792.tar.bz2 online_test-b3f5721f3cf4225902000f2f76e5138135383792.zip |
Add weightage for Quiz and Create Grading System App
App Name: grades
Grading System provides with the grade for a given value.
It contains different grade ranges.
Has its own default grading system.
Allows you to modify and add grading system wth grade ranges.
To be done:
- Need to add README
- Good UI
- There are fields like can_be_used and order in models for future use.
- More tests
App name: Yaksh
Now every quiz has a default weightage of 100%, can be changed.
An aggregate is calculated for a given course.
Using grades app a grade is provide to the aggregate value.
Diffstat (limited to 'grades/tests')
-rw-r--r-- | grades/tests/test_models.py | 27 | ||||
-rw-r--r-- | grades/tests/test_views.py | 106 |
2 files changed, 133 insertions, 0 deletions
diff --git a/grades/tests/test_models.py b/grades/tests/test_models.py new file mode 100644 index 0000000..89708e2 --- /dev/null +++ b/grades/tests/test_models.py @@ -0,0 +1,27 @@ +from django.test import TestCase +from grades.models import GradingSystem, GradeRange + +# Create your tests here. +class GradingSystemTestCase(TestCase): + def setUp(self): + GradingSystem.objects.create(name='unusable') + + def test_get_grade(self): + # Given + grading_system = GradingSystem.objects.get(name='default') + expected_grades = {0:'F', 31:'F', 49:'P', 55:'C', 60:'B', 80:'A', + 95:'A+', 100:'A+', 100.5:'A+', 101:None, 109:None} + for marks in expected_grades.keys(): + # When + grade = grading_system.get_grade(marks) + # Then + self.assertEqual(expected_grades.get(marks), grade) + + def test_grade_system_unusable(self): + # Given + grading_system = GradingSystem.objects.get(name='unusable') + # When + grade = grading_system.get_grade(29) + # Then + self.assertIsNone(grade) + diff --git a/grades/tests/test_views.py b/grades/tests/test_views.py new file mode 100644 index 0000000..2c29ae5 --- /dev/null +++ b/grades/tests/test_views.py @@ -0,0 +1,106 @@ +from django.test import TestCase, Client +from django.contrib.auth.models import User +from django.core.urlresolvers import reverse +from grades.models import GradingSystem + + +def setUpModule(): + user = User.objects.create_user(username='grades_user', + password='grades_user') + +def tearDownModule(): + User.objects.all().delete() + + +class GradeViewTest(TestCase): + def setUp(self): + self.client = Client() + + def tearDown(self): + self.client.logout() + + def test_grade_view(self): + # Given + # URL redirection due to no login credentials + status_code = 302 + # When + response = self.client.get(reverse('grades:grading_systems')) + # Then + self.assertEqual(response.status_code, status_code) + + # Given + # successful login and grading systems views + self.client.login(username='grades_user', password='grades_user') + status_code = 200 + # When + response = self.client.get(reverse('grades:grading_systems')) + # Then + self.assertEqual(response.status_code, status_code) + self.assertTemplateUsed(response, 'grading_systems.html') + + +class AddGradingSystemTest(TestCase): + def setUp(self): + self.client = Client() + + def tearDown(self): + self.client.logout() + + def test_add_grades_view(self): + # Given + status_code = 302 + # When + response = self.client.get(reverse('grades:add_grade')) + # Then + self.assertEqual(response.status_code, status_code) + + # Given + status_code = 200 + self.client.login(username='grades_user', password='grades_user') + # When + response = self.client.get(reverse('grades:add_grade')) + # Then + self.assertEqual(response.status_code, status_code) + self.assertTemplateUsed(response, 'add_grades.html') + + def test_add_grades_post(self): + # Given + self.client.login(username='grades_user', password='grades_user') + data = {'name': ['new_sys'], 'description': ['About the grading system!'], + 'graderange_set-MIN_NUM_FORMS': ['0'], + 'graderange_set-TOTAL_FORMS': ['0'], 'can_be_used': ['on'], + 'graderange_set-MAX_NUM_FORMS': ['1000'], 'add': ['Add'], + 'graderange_set-INITIAL_FORMS': ['0']} + # When + response = self.client.post(reverse('grades:add_grade'), data) + # Then + grading_systems = GradingSystem.objects.filter(name='new_sys') + self.assertEqual(len(grading_systems), 1) + + # Given + grading_system = grading_systems.first() + # When + ranges = grading_system.graderange_set.all() + # Then + self.assertEqual(len(ranges), 0) + + # Given + data = {'graderange_set-0-upper_limit': ['40'], + 'graderange_set-0-order': ['0'], + 'graderange_set-0-description': ['Fail'], + 'graderange_set-0-lower_limit': ['0'], + 'graderange_set-0-system': [''], 'name': ['new_sys'], + 'graderange_set-MIN_NUM_FORMS': ['0'], + 'graderange_set-TOTAL_FORMS': ['1'], 'can_be_used': ['on'], + 'graderange_set-MAX_NUM_FORMS': ['1000'], + 'graderange_set-0-id': [''], + 'description': ['About the grading system!'], + 'graderange_set-0-grade': ['F'], + 'graderange_set-INITIAL_FORMS': ['0'], 'save': ['Save']} + # When + response = self.client.post(reverse('grades:edit_grade', + kwargs={'system_id': 2}), data) + # Then + ranges = grading_system.graderange_set.all() + self.assertEqual(len(ranges), 1) + |