CourseModelStudentTestCase   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 77.14 %

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
dl 54
loc 70
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B test_gradable_submissions_list() 27 27 2
A setUp() 0 5 1
B testGradedSubmissionsList() 27 27 2
A testCourseAuthors() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
'''
2
    Tets cases focusing on the Course model class methods.
3
'''
4
5
from .helpers.course import create_course
6
from .helpers.assignment import create_pass_fail_grading
7
from .helpers.assignment import create_open_assignment
8
from .helpers.submission import create_submission
9
10
11
from opensubmit.models import Submission
12
from opensubmit.tests.cases import SubmitStudentTestCase
13
14
15
class CourseModelStudentTestCase(SubmitStudentTestCase):
16
    def setUp(self):
17
        super(CourseModelStudentTestCase, self).setUp()
18
        self.course = create_course(self.user)
19
        grading = create_pass_fail_grading()
20
        self.assignment = create_open_assignment(self.course, grading)
21
22 View Code Duplication
    def test_gradable_submissions_list(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
23
        # Expected number of results when the submission has that state
24
        expected = (
25
            (0, Submission.RECEIVED),
26
            (0, Submission.WITHDRAWN),
27
            (1, Submission.SUBMITTED),
28
            (0, Submission.TEST_VALIDITY_PENDING),
29
            (0, Submission.TEST_VALIDITY_FAILED),
30
            (0, Submission.TEST_FULL_PENDING),
31
            (1, Submission.TEST_FULL_FAILED),
32
            (1, Submission.SUBMITTED_TESTED),
33
            (1, Submission.GRADING_IN_PROGRESS),
34
            (0, Submission.GRADED),
35
            (0, Submission.CLOSED),
36
            (0, Submission.CLOSED_TEST_FULL_PENDING))
37
38
        # Course without submissions should not have gradable submissions
39
        qs = self.course.gradable_submissions()
40
        self.assertEqual(qs.count(), 0)
41
42
        for count, state in expected:
43
            sub = create_submission(self.user, self.assignment)
44
            sub.state = state
45
            sub.save()
46
            self.assertEqual(
47
                qs.count(), count,
48
                "Submission count for state %s is incorrect." % state)
49
50 View Code Duplication
    def testGradedSubmissionsList(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
51
        # Expected number of results when the submission has that state
52
        expected = (
53
            (0, Submission.RECEIVED),
54
            (0, Submission.WITHDRAWN),
55
            (0, Submission.SUBMITTED),
56
            (0, Submission.TEST_VALIDITY_PENDING),
57
            (0, Submission.TEST_VALIDITY_FAILED),
58
            (0, Submission.TEST_FULL_PENDING),
59
            (0, Submission.TEST_FULL_FAILED),
60
            (0, Submission.SUBMITTED_TESTED),
61
            (0, Submission.GRADING_IN_PROGRESS),
62
            (1, Submission.GRADED),
63
            (0, Submission.CLOSED),
64
            (0, Submission.CLOSED_TEST_FULL_PENDING))
65
66
        # Course without submissions should not have gradable submissions
67
        qs = self.course.graded_submissions()
68
        self.assertEqual(qs.count(), 0)
69
70
        for count, state in expected:
71
            sub = create_submission(self.user, self.assignment)
72
            sub.state = state
73
            sub.save()
74
            self.assertEqual(
75
                qs.count(), count,
76
                "Submission count for state %s is incorrect." % state)
77
78
    def testCourseAuthors(self):
79
        # Course without submissions should have no authors
80
        qs = self.course.authors()
81
        self.assertEqual(qs.count(), 0)
82
83
        sub = create_submission(self.user, self.assignment)
84
        self.assertEqual(qs.count(), len(sub.authors.all()))
85