Example #1
0
def test_validation_on_write(tmp_path):
    file_path = tmp_path / "test.asdf"
    model = ValidationModel(pass_invalid_values=True)
    with pytest.warns(ValidationWarning):
        model.meta.string_attribute = 42

    with pytest.warns(ValidationWarning):
        model.save(file_path)
Example #2
0
def test_pass_invalid_values_on_write(tmp_path):
    file_path = tmp_path / "test.asdf"
    model = ValidationModel(pass_invalid_values=True)
    with pytest.warns(ValidationWarning):
        model.meta.string_attribute = 42
    with pytest.warns(ValidationWarning):
        model.save(file_path)

    with asdf.open(file_path) as af:
        assert af["meta"]["string_attribute"] == 42
Example #3
0
def QuestionView(request):
    user = check_validation(request)
    if user:
        if user.count < 20:
            question = QuestionModel.objects.order_by('?')[:1].first()

            print question
            test = ValidationModel.objects.complex_filter(Q(user=user) & Q(question=question))
            while test.exists():
                question = QuestionModel.objects.order_by('?')[:1].first()
                test = ValidationModel.objects.complex_filter(Q(user=user) & Q(question=question))

            new = ValidationModel(user=user, question=question)
            new.save()
            user.count += 1
            user.save()
            return render(request, 'quiz.html', {'question':question})
        else:
            return redirect('/endquiz/')
    else:
        return redirect('/login/')