コード例 #1
0
ファイル: test_forms.py プロジェクト: tkv29/EvaP
    def test_results_cache_refreshed(self):
        contributor = baker.make(UserProfile, first_name="Peter")
        evaluation = baker.make(Evaluation, state="published")
        baker.make(Contribution,
                   contributor=contributor,
                   evaluation=evaluation)

        cache_results(evaluation)
        results_before = get_results(evaluation)

        form_data = get_form_data_from_instance(UserForm, contributor)
        form_data["first_name"] = "Patrick"
        form = UserForm(form_data, instance=contributor)
        form.save()

        results_after = get_results(evaluation)

        self.assertCountEqual(
            (result.contributor.first_name
             for result in results_before.contribution_results
             if result.contributor),
            ("Peter", ),
        )

        self.assertCountEqual(
            (result.contributor.first_name
             for result in results_after.contribution_results
             if result.contributor),
            ("Patrick", ),
        )
コード例 #2
0
ファイル: views.py プロジェクト: Paul-Geppert/EvaP
def user_create(request):
    form = UserForm(request.POST or None, instance=UserProfile())

    if form.is_valid():
        form.save()
        messages.success(request, _("Successfully created user."))
        return redirect('staff:user_index')
    else:
        return render(request, "staff_user_form.html", dict(form=form))
コード例 #3
0
ファイル: views.py プロジェクト: lmm-git/EvaP
def user_create(request):
    form = UserForm(request.POST or None, instance=UserProfile())

    if form.is_valid():
        form.save()
        messages.success(request, _("Successfully created user."))
        return redirect('staff:user_index')
    else:
        return render(request, "staff_user_form.html", dict(form=form))
コード例 #4
0
    def test_user_cannot_be_removed_from_evaluation_already_voted_for(self):
        student = baker.make(UserProfile)
        baker.make(Evaluation, participants=[student], voters=[student], course__semester__is_active=True)

        form_data = get_form_data_from_instance(UserForm, student)
        form_data["evaluations_participating_in"] = []
        form = UserForm(form_data, instance=student)

        self.assertFalse(form.is_valid())
        self.assertIn('evaluations_participating_in', form.errors)
        self.assertIn("Evaluations for which the user already voted can't be removed", form.errors['evaluations_participating_in'][0])
コード例 #5
0
ファイル: test_forms.py プロジェクト: fsr-itse/EvaP
    def test_user_cannot_be_removed_from_evaluation_already_voted_for(self):
        student = mommy.make(UserProfile)
        mommy.make(Evaluation, participants=[student], voters=[student])

        form_data = get_form_data_from_instance(UserForm, student)
        form_data["evaluations_participating_in"] = []
        form = UserForm(form_data, instance=student)

        self.assertFalse(form.is_valid())
        self.assertIn('evaluations_participating_in', form.errors)
        self.assertIn("Evaluations for which the user already voted can't be removed", form.errors['evaluations_participating_in'][0])
コード例 #6
0
ファイル: test_forms.py プロジェクト: Onderi/EvaP
    def test_user_cannot_be_removed_from_course_already_voted_for(self):
        student = mommy.make(UserProfile)
        mommy.make(Course, participants=[student], voters=[student])

        form_data = get_form_data_from_instance(UserForm, student)
        form_data["courses_participating_in"] = []
        form = UserForm(form_data, instance=student)

        self.assertFalse(form.is_valid())
        self.assertIn('courses_participating_in', form.errors)
        self.assertIn("Courses for which the user already voted can't be removed", form.errors['courses_participating_in'][0])
コード例 #7
0
ファイル: views.py プロジェクト: Paul-Geppert/EvaP
def user_edit(request, user_id):
    user = get_object_or_404(UserProfile, id=user_id)
    form = UserForm(request.POST or None, request.FILES or None, instance=user)

    courses_contributing_to = Course.objects.filter(semester=Semester.active_semester(), contributions__contributor=user)

    if form.is_valid():
        form.save()
        messages.success(request, _("Successfully updated user."))
        return redirect('staff:user_index')
    else:
        return render(request, "staff_user_form.html", dict(form=form, object=user, courses_contributing_to=courses_contributing_to))
コード例 #8
0
ファイル: test_forms.py プロジェクト: tomkellog/EvaP
    def test_user_form(self):
        """
            Tests the UserForm with one valid and one invalid input dataset.
        """
        user = mommy.make(UserProfile)
        another_user = mommy.make(UserProfile)
        data = {"username": "******", "email": "*****@*****.**"}
        form = UserForm(instance=user, data=data)
        self.assertTrue(form.is_valid())

        data = {"username": another_user.username, "email": "[email protected]"}
        form = UserForm(instance=user, data=data)
        self.assertFalse(form.is_valid())
コード例 #9
0
ファイル: views.py プロジェクト: lmm-git/EvaP
def user_edit(request, user_id):
    user = get_object_or_404(UserProfile, id=user_id)
    form = UserForm(request.POST or None, request.FILES or None, instance=user)

    courses_contributing_to = Course.objects.filter(
        semester=Semester.active_semester(), contributions__contributor=user)

    if form.is_valid():
        form.save()
        messages.success(request, _("Successfully updated user."))
        return redirect('staff:user_index')
    else:
        return render(
            request, "staff_user_form.html",
            dict(form=form,
                 object=user,
                 courses_contributing_to=courses_contributing_to))
コード例 #10
0
    def test_user_with_same_username(self):
        """
            Tests whether the user form correctly handles usernames
            that already exist in the database
        """
        user = mommy.make(UserProfile)

        data = {"username": user.username}
        form = UserForm(data=data)
        self.assertFalse(form.is_valid())

        data = {"username": user.username.upper()}
        form = UserForm(data=data)
        self.assertFalse(form.is_valid())

        data = {"username": user.username.upper()}
        form = UserForm(instance=user, data=data)
        self.assertTrue(form.is_valid())
コード例 #11
0
    def test_user_with_same_email(self):
        """
            Tests whether the user form correctly handles email adresses
            that already exist in the database
            Regression test for #590
        """
        user = mommy.make(UserProfile, email="*****@*****.**")

        data = {"username": "******", "email": user.email}
        form = UserForm(data=data)
        self.assertFalse(form.is_valid())

        data = {"username": "******", "email": user.email.upper()}
        form = UserForm(data=data)
        self.assertFalse(form.is_valid())

        data = {"username": "******", "email": user.email.upper()}
        form = UserForm(instance=user, data=data)
        self.assertTrue(form.is_valid())
コード例 #12
0
    def test_user_form(self):
        """
            Tests the UserForm with one valid and one invalid input dataset.
        """
        user = mommy.make(UserProfile)
        another_user = mommy.make(UserProfile)
        data = {"username": "******", "email": "*****@*****.**"}
        form = UserForm(instance=user, data=data)
        self.assertTrue(form.is_valid())

        data = {"username": another_user.username, "email": "[email protected]"}
        form = UserForm(instance=user, data=data)
        self.assertFalse(form.is_valid())
コード例 #13
0
    def test_user_form(self):
        """
            Tests the UserForm with one valid and one invalid input dataset.
        """
        user = baker.make(UserProfile)
        another_user = baker.make(UserProfile, email="*****@*****.**")
        data = {"email": "*****@*****.**"}
        form = UserForm(instance=user, data=data)
        self.assertTrue(form.is_valid())

        data = {"email": another_user.email}
        form = UserForm(instance=user, data=data)
        self.assertFalse(form.is_valid())
コード例 #14
0
ファイル: test_forms.py プロジェクト: tomkellog/EvaP
    def test_user_with_same_username(self):
        """
            Tests whether the user form correctly handles usernames
            that already exist in the database
        """
        user = mommy.make(UserProfile)

        data = {"username": user.username}
        form = UserForm(data=data)
        self.assertFalse(form.is_valid())

        data = {"username": user.username.upper()}
        form = UserForm(data=data)
        self.assertFalse(form.is_valid())

        data = {"username": user.username.upper()}
        form = UserForm(instance=user, data=data)
        self.assertTrue(form.is_valid())
コード例 #15
0
ファイル: test_forms.py プロジェクト: tomkellog/EvaP
    def test_user_with_same_email(self):
        """
            Tests whether the user form correctly handles email adresses
            that already exist in the database
            Regression test for #590
        """
        user = mommy.make(UserProfile, email="*****@*****.**")

        data = {"username": "******", "email": user.email}
        form = UserForm(data=data)
        self.assertFalse(form.is_valid())

        data = {"username": "******", "email": user.email.upper()}
        form = UserForm(data=data)
        self.assertFalse(form.is_valid())

        data = {"username": "******", "email": user.email.upper()}
        form = UserForm(instance=user, data=data)
        self.assertTrue(form.is_valid())