コード例 #1
0
    def test_change_thesis(self):
        supervisor = Supervisor(
            first_name="Max",
            last_name="Mustermann",
            id="mmuster")

        supervisor.save()

        thesis = ThesisStub.applied(supervisor)
        thesis.save()

        data = {
            'begin_date': date(2021, 1, 1),
            'due_date': date(2021, 3, 1),
            'title': 'xxxrxxx',
            'external': not thesis.external,
            'external_where': '',
            'student_email': '*****@*****.**'
        }

        form = ThesisApplicationForm(data)
        form.full_clean()

        changed_thesis = form.change_thesis(thesis, assessor=None)

        self.assertEqual(changed_thesis.title, data["title"])
        self.assertEqual(changed_thesis.begin_date, data["begin_date"])
        self.assertEqual(changed_thesis.due_date, data["due_date"])
        self.assertEqual(changed_thesis.assessor, None)
        self.assertEqual(changed_thesis.supervisor, thesis.supervisor)
        self.assertEqual(changed_thesis.external, data["external"])
        self.assertEqual(changed_thesis.external_where, data["external_where"])
        self.assertEqual(changed_thesis.student_contact, data["student_email"])
コード例 #2
0
    def test_can_hand_in_thesis(self):
        """Hand In Date should default to deadline of thesis"""
        thesis = ThesisStub.applied(self.supervisor)
        thesis.restriction_note = True
        thesis.save()

        hand_in_date = thesis.deadline + timedelta(15)

        post_data = {
            'new_title': "A brand new title",
            'handed_in_date_day': str(hand_in_date.day),
            'handed_in_date_month': str(hand_in_date.month),
            'handed_in_date_year': str(hand_in_date.year),
            'restriction_note': 'on'
        }

        response = self.client.post(
            reverse('handin', args=[thesis.surrogate_key]), post_data)

        handed_in_thesis = Thesis.objects.get(
            surrogate_key=thesis.surrogate_key)

        self.assertEqual(302, response.status_code)
        self.assertEqual(Thesis.HANDED_IN, handed_in_thesis.status)
        self.assertEqual(hand_in_date, handed_in_thesis.handed_in_date)
        self.assertEqual(post_data["new_title"], handed_in_thesis.title)
コード例 #3
0
    def test_no_operations_possible_for_graded_thesis(self):
        thesis = ThesisStub.applied(self.supervisor)
        thesis.save()
        thesis.assign_grade(Decimal("1.3"), date(2020, 3, 1))

        response = self.client.get(reverse('overview'))

        self.assertNotIn('class="icon-link"', str(response.content))
コード例 #4
0
    def test_empty_change_view(self):
        thesis = ThesisStub.applied(self.supervisor)
        thesis.save()

        response = self.client.get(
            reverse('change', args=[thesis.surrogate_key]))

        self.assertEqual(200, response.status_code)
        self.assertEqual(response.context["student"], thesis.student)
コード例 #5
0
    def test_empty_form(self):
        thesis = ThesisStub.applied(self.supervisor)

        thesis.save()

        response = self.client.get(
            reverse('prolong', args=[thesis.surrogate_key]))

        self.assertEqual(200, response.status_code)
コード例 #6
0
    def test_initial_grade_form(self):
        thesis = ThesisStub.applied(self.supervisor)

        thesis.save()

        response = self.client.get(
            reverse('grade', args=[thesis.surrogate_key]))

        initial_date = response.context["form"].initial["examination_date"]

        self.assertEqual(200, response.status_code)
        self.assertEqual(thesis.due_date, initial_date)
コード例 #7
0
    def test_default_values_are_set_correctly(self):
        """Hand In Date should default to deadline of thesis"""
        thesis = ThesisStub.applied(self.supervisor)
        thesis.restriction_note = True
        thesis.save()

        response = self.client.get(
            reverse('handin', args=[thesis.surrogate_key]))

        context = response.context
        form = context["form"]

        self.assertEqual(200, response.status_code)
        self.assertEqual(context["thesis"], thesis)
        self.assertEqual(form["new_title"].value(), thesis.title)
        self.assertEqual(form["handed_in_date"].value(), thesis.deadline)
コード例 #8
0
    def test_supervisor_does_not_see_theses_of_other_supervisors(self):
        ThesisStub.small(self.supervisor)

        other_supervisor = Supervisor(first_name="Peter",
                                      last_name="Müller",
                                      id="p.mueller")

        other_supervisor.save()

        not_visible = ThesisStub.applied(other_supervisor)

        response = self.client.get(reverse('overview'))

        self.assertEqual(200, response.status_code)
        self.assertEqual(3, len(response.context["theses"]))
        self.assertTrue(not_visible not in response.context["theses"])
        self.assertIn('class="icon-link"', str(response.content))
コード例 #9
0
    def test_validate_invalid_date(self):
        """Hand In Date should default to deadline of thesis"""
        thesis = ThesisStub.applied(self.supervisor)
        thesis.save()

        post_data = {
            'new_title': "A brand new title",
            'handed_in_date_day': "",
            'handed_in_date_month': "",
            'handed_in_date_year': "",
            'restriction_note': 'on'
        }

        response = self.client.post(
            reverse('handin', args=[thesis.surrogate_key]), post_data)

        self.assertEqual(200, response.status_code)
        self.assertIn('handed_in_date', response.context["form"].errors)
コード例 #10
0
    def setUp(self):
        user = User(username="******",
                    password="******",
                    initials="PPP",
                    is_excom=True)
        user.save()

        self.client = Client()
        self.client.force_login(user)

        supervisor = Supervisor(id="t.prof",
                                first_name="Test",
                                last_name="Prof",
                                initials="TPF")
        supervisor.save()

        self.thesis = ThesisStub.applied(supervisor)
        self.thesis.save()
コード例 #11
0
    def test_validate_new_title_missing(self):
        """Hand In Date should default to deadline of thesis"""
        thesis = ThesisStub.applied(self.supervisor)
        thesis.save()

        hand_in_date = thesis.deadline + timedelta(15)

        post_data = {
            'handed_in_date_day': str(hand_in_date.day),
            'handed_in_date_month': str(hand_in_date.month),
            'handed_in_date_year': str(hand_in_date.year),
            'restriction_note': 'on'
        }

        response = self.client.post(
            reverse('handin', args=[thesis.surrogate_key]), post_data)

        self.assertEqual(200, response.status_code)
        self.assertIn('new_title', response.context["form"].errors)
コード例 #12
0
    def test_generates_grading_pdf(self):
        supervisor = Supervisor(
            first_name="Max", last_name="Muster", id="mmuster")

        thesis = ThesisStub.applied(supervisor)

        supervisor.save()
        thesis.save()

        response = self.client.get(
            reverse('grading_pdf', args=[thesis.surrogate_key]))

        expected_filename = "{0}_{1}_{2}.pdf".format(
            datetime.now().strftime("%Y%m%d"), 'bewertung', thesis.student.id)

        self.assertEqual(200, response.status_code)
        self.assertEqual('application/pdf',
                         response._headers['content-type'][1])
        self.assertIn(expected_filename, response._headers[
                      'content-disposition'][1])
コード例 #13
0
    def test_can_not_grade_thesis_without_handed_in_date(self):
        thesis = ThesisStub.applied(self.supervisor)

        thesis.save()

        post_data = {
            'restriction_note': False,
            'grade': Decimal("1.2"),
            'examination_date': date(2019, 2, 1),
        }

        response = self.client.post(
            reverse('grade', args=[thesis.surrogate_key]), post_data)

        self.assertEqual(200, response.status_code)
        self.assertFalse(response.context["form"].is_valid())
        self.assertIn('handed_in_date', response.context["form"].errors)

        thesis = Thesis.objects.get(surrogate_key=thesis.surrogate_key)

        self.assertEqual(Thesis.APPLIED, thesis.status)
コード例 #14
0
    def test_can_grade_thesis_without_restriction_note(self):
        thesis = ThesisStub.applied(self.supervisor)

        thesis.save()

        post_data = {
            'restriction_note': False,
            'examination_date': date(2019, 3, 1),
            'grade': Decimal("1.2"),
            'handed_in_date': date(2019, 2, 1),
        }

        response = self.client.post(
            reverse('grade', args=[thesis.surrogate_key]), post_data)

        self.assertEqual(302, response.status_code)

        thesis = Thesis.objects.get(surrogate_key=thesis.surrogate_key)

        self.assertEqual(Thesis.GRADED, thesis.status)
        self.assertEqual(Decimal("1.2"), thesis.grade)
        self.assertFalse(thesis.restriction_note)
コード例 #15
0
    def test_sets_prolongation_date_as_due_date(self):
        thesis = ThesisStub.applied(self.supervisor)

        thesis.begin_date = date(2018, 1, 1)
        thesis.due_date = date(2018, 3, 30)
        first_prolongation = date(2018, 4, 30)

        thesis.save()

        thesis.prolong(first_prolongation, 'because', 4)

        response = self.client.get(
            reverse('prolong', args=[thesis.surrogate_key]))

        initial_due_date = response.context["form"].initial["due_date"]
        initial_prolongation = response.context["form"].initial[
            "prolongation_date"]

        self.assertEqual(200, response.status_code)
        self.assertEqual(first_prolongation, initial_due_date)
        self.assertEqual(first_prolongation + timedelta(30),
                         initial_prolongation)
コード例 #16
0
    def test_valid_prolongation(self):
        thesis = ThesisStub.applied(self.supervisor)

        thesis.begin_date = date(2018, 1, 1)
        thesis.due_date = date(2018, 3, 30)

        thesis.save()

        post_data = {
            'prolongation_date': thesis.due_date + timedelta(30),
            'due_date': thesis.due_date,
            'reason': 'I was sick',
            'weeks': 4
        }

        response = self.client.post(
            reverse('prolong', args=[thesis.surrogate_key]), post_data)

        self.assertEqual(302, response.status_code)

        thesis = Thesis.objects.get(surrogate_key=thesis.surrogate_key)

        self.assertEqual(Thesis.PROLONGED, thesis.status)
コード例 #17
0
    def test_error_no_weeks(self):
        thesis = ThesisStub.applied(self.supervisor)

        thesis.begin_date = date(2018, 1, 1)
        thesis.due_date = date(2018, 3, 30)

        thesis.save()

        post_data = {
            'prolongation_date': thesis.due_date + timedelta(30),
            'due_date': thesis.due_date,
            'reason': 'A perfectly valid reason',
            'weeks': 0
        }

        response = self.client.post(
            reverse('prolong', args=[thesis.surrogate_key]), post_data)

        self.assertEqual(200, response.status_code)
        self.assertIn('weeks', response.context["form"].errors)

        thesis = Thesis.objects.get(surrogate_key=thesis.surrogate_key)

        self.assertEqual(Thesis.APPLIED, thesis.status)