Skip to content
Snippets Groups Projects

Resolve "Rework importer script to use new data format from rusty hektor"

Files
7
from django.conf import settings
import constance
from rest_framework.test import APITestCase
from rest_framework.test import APITestCase
from core.models import Feedback, SubmissionSubscription
from core.models import Feedback, SubmissionSubscription
from util.factories import make_test_data
from util.factories import make_test_data
 
config = constance.config
class StopAfterFiftyPercent(APITestCase):
 
class StopOnPass(APITestCase):
@classmethod
@classmethod
def setUpTestData(cls):
def setUpTestData(cls):
settings.STOP_ON_PASS = True
config.STOP_ON_PASS = True
def setUp(self):
def setUp(self):
self.data = make_test_data(data_dict={
self.data = make_test_data(data_dict={
'exams': [{
'exams': [
'module_reference': 'Test Exam 01',
{
'total_score': 50,
'module_reference': 'Test Exam 01',
'pass_score': 25,
'total_score': 50,
}],
'pass_score': 25,
 
'pass_only': True
 
},
 
{
 
'module_reference': 'Test Exam 02',
 
'total_score': 50,
 
'pass_score': 25,
 
'pass_only': False
 
}
 
],
'submission_types': [
'submission_types': [
{
{
'name': '01. Sort this or that',
'name': '01. Sort this or that',
@@ -40,6 +51,7 @@ class StopAfterFiftyPercent(APITestCase):
@@ -40,6 +51,7 @@ class StopAfterFiftyPercent(APITestCase):
],
],
'students': [
'students': [
{'username': 'student01', 'exam': 'Test Exam 01'},
{'username': 'student01', 'exam': 'Test Exam 01'},
 
{'username': 'student02', 'exam': 'Test Exam 02'},
],
],
'tutors': [
'tutors': [
{'username': 'tutor01'},
{'username': 'tutor01'},
@@ -49,6 +61,7 @@ class StopAfterFiftyPercent(APITestCase):
@@ -49,6 +61,7 @@ class StopAfterFiftyPercent(APITestCase):
{'username': 'reviewer'}
{'username': 'reviewer'}
],
],
'submissions': [
'submissions': [
 
# Student 1
{
{
'text': 'function blabl\n'
'text': 'function blabl\n'
' on multi lines\n'
' on multi lines\n'
@@ -71,6 +84,31 @@ class StopAfterFiftyPercent(APITestCase):
@@ -71,6 +84,31 @@ class StopAfterFiftyPercent(APITestCase):
' lorem ipsum und so\n',
' lorem ipsum und so\n',
'type': '03. Super simple task',
'type': '03. Super simple task',
'user': 'student01'
'user': 'student01'
 
},
 
 
# Student 2
 
{
 
'text': 'function blabl\n'
 
' on multi lines\n'
 
' for blabla in bla:\n'
 
' lorem ipsum und so\n',
 
'type': '01. Sort this or that',
 
'user': 'student02',
 
},
 
{
 
'text': 'function blabl\n'
 
' asasxasx\n'
 
' lorem ipsum und so\n',
 
'type': '02. Merge this or that or maybe even this',
 
'user': 'student02'
 
},
 
{
 
'text': 'function blabl\n'
 
' on multi lines\n'
 
' asasxasx\n'
 
' lorem ipsum und so\n',
 
'type': '03. Super simple task',
 
'user': 'student02'
}
}
]}
]}
)
)
@@ -81,30 +119,71 @@ class StopAfterFiftyPercent(APITestCase):
@@ -81,30 +119,71 @@ class StopAfterFiftyPercent(APITestCase):
feedback_stage=SubmissionSubscription.FEEDBACK_CREATION)
feedback_stage=SubmissionSubscription.FEEDBACK_CREATION)
def test_all_feedback_is_available(self):
def test_all_feedback_is_available(self):
self.assertEqual(3, self.subscription.get_available_in_stage())
self.assertEqual(6, self.subscription.get_available_in_stage())
def test_all_is_available_when_score_is_too_low(self):
def test_all_is_available_when_score_is_too_low(self):
Feedback.objects.create(
Feedback.objects.create(
of_submission=self.data['submissions'][0], score=20, is_final=True)
of_submission=self.data['submissions'][0], score=20, is_final=True)
self.assertEqual(2, self.subscription.get_available_in_stage())
self.assertEqual(5, self.subscription.get_available_in_stage())
def test_default_does_not_pass_exam(self):
def test_default_does_not_pass_exam(self):
self.assertFalse(self.data['students'][0].student.passes_exam)
self.assertFalse(self.data['students'][0].student.passes_exam)
def test_no_more_submissions_after_student_passed_exam(self):
def test_no_more_submissions_after_pass_only_student_passed_exam(self):
Feedback.objects.create(
Feedback.objects.create(
of_submission=self.data['submissions'][0], score=20)
of_submission=self.data['submissions'][0], score=20)
Feedback.objects.create(
Feedback.objects.create(
of_submission=self.data['submissions'][1], score=15)
of_submission=self.data['submissions'][1], score=15)
self.data['students'][0].student.refresh_from_db()
self.data['students'][0].student.refresh_from_db()
self.assertEqual(0, self.subscription.get_available_in_stage())
self.assertEqual(3, self.subscription.get_available_in_stage())
self.assertEqual(35, self.data['students'][0].student.total_score)
self.assertEqual(35, self.data['students'][0].student.total_score)
self.assertTrue(self.data['students'][0].student.passes_exam)
self.assertTrue(self.data['students'][0].student.passes_exam)
def test_validation_still_allowed(self):
# def test_submissions_left_after_not_pass_only_student_passed_exam(self):
a1 = self.subscription.get_or_create_work_assignment()
# Feedback.objects.create(
a2 = self.subscription.get_or_create_work_assignment()
# of_submission=self.data['submissions'][3], score=20)
 
# Feedback.objects.create(
 
# of_submission=self.data['submissions'][4], score=15)
 
#
 
# self.data['students'][1].student.refresh_from_db()
 
# self.assertEqual(4, self.subscription.get_available_in_stage())
 
# self.assertEqual(35, self.data['students'][1].student.total_score)
 
# self.assertTrue(self.data['students'][1].student.passes_exam)
 
 
def test_validation_still_allowed_when_stop_on_pass(self):
 
subscription_s1 = SubmissionSubscription.objects.create(
 
owner=self.tutor01,
 
feedback_stage=SubmissionSubscription.FEEDBACK_CREATION,
 
query_type=SubmissionSubscription.STUDENT_QUERY,
 
query_key=self.data['students'][0].student.pk
 
)
 
a1 = subscription_s1.get_or_create_work_assignment()
 
a2 = subscription_s1.get_or_create_work_assignment()
 
 
# signals recognize the open assignments
 
Feedback.objects.create(
 
of_submission=a1.submission, score=20)
 
Feedback.objects.create(
 
of_submission=a2.submission, score=15)
 
 
subscription_other_tutor = SubmissionSubscription.objects.create(
 
owner=self.tutor02,
 
feedback_stage=SubmissionSubscription.FEEDBACK_VALIDATION)
 
 
self.assertEqual(0, subscription_s1.get_available_in_stage())
 
self.assertEqual(2, subscription_other_tutor.get_available_in_stage())
 
self.assertEqual(6, subscription_other_tutor.get_remaining_not_final())
 
 
def test_validation_still_allowed_when_not_stop_on_pass(self):
 
subscription_s1 = SubmissionSubscription.objects.create(
 
owner=self.tutor01,
 
feedback_stage=SubmissionSubscription.FEEDBACK_CREATION,
 
query_type=SubmissionSubscription.STUDENT_QUERY,
 
query_key=self.data['students'][1].student.pk
 
)
 
a1 = subscription_s1.get_or_create_work_assignment()
 
a2 = subscription_s1.get_or_create_work_assignment()
# signals recognize the open assignments
# signals recognize the open assignments
Feedback.objects.create(
Feedback.objects.create(
@@ -112,10 +191,10 @@ class StopAfterFiftyPercent(APITestCase):
@@ -112,10 +191,10 @@ class StopAfterFiftyPercent(APITestCase):
Feedback.objects.create(
Feedback.objects.create(
of_submission=a2.submission, score=15)
of_submission=a2.submission, score=15)
subscription = SubmissionSubscription.objects.create(
subscription_other_tutor = SubmissionSubscription.objects.create(
owner=self.tutor02,
owner=self.tutor02,
feedback_stage=SubmissionSubscription.FEEDBACK_VALIDATION)
feedback_stage=SubmissionSubscription.FEEDBACK_VALIDATION)
self.assertEqual(0, self.subscription.get_available_in_stage())
self.assertEqual(1, subscription_s1.get_available_in_stage())
self.assertEqual(2, subscription.get_available_in_stage())
self.assertEqual(2, subscription_other_tutor.get_available_in_stage())
self.assertEqual(3, subscription.get_remaining_not_final())
self.assertEqual(6, subscription_other_tutor.get_remaining_not_final())
Loading