Example #1
0
 def test_result_save_correct_data_error(self):
     data = {'error': 'Test'}
     self.DataBaseObjectsNumber()
     form = ResultForm(data=data)
     self.assertTrue(form.is_valid())
     r = form.save()
     self.assertIsInstance(r, Result)
     self.assertEqual(r.error, 'Test')
     self.DataBaseObjectsId(r)
     self.assertEqual(r.value, None)
Example #2
0
 def test_result_save_correct_data(self):
     data = {"value": 200}
     self.assertEqual(len(Result.objects.all()), 0)
     form = ResultForm(data=data)
     self.assertTrue(form.is_valid())
     r = form.save()
     self.assertIsInstance(r, Result)
     self.assertEqual(r.value, 200)
     self.assertEqual(r.id, 1)
     self.assertEqual(r.error, None)
Example #3
0
def results_list(request):
    if request.method == "POST":
        form = ResultForm(data=request.POST)

        if form.is_valid():
            if form.cleaned_data['error'] == '':
                form.cleaned_data['error'] = None
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 "Utworzono nowy Result!!")
        else:
            messages.add_message(request, messages.ERROR,
                                 form.errors['__all__'])

    form = ResultForm()
    results = Result.objects.all()
    return render(request=request,
                  template_name="maths/results.html",
                  context={
                      "results": results,
                      "form": form
                  })
Example #4
0
 def test_result_save_correct_data_error_value(self):
     data = {'value': 200, 'error': 'Test'}
     self.DataBaseObjectsNumber()
     form = ResultForm(data=data)
     self.assertFalse(form.is_valid())