Ejemplo n.º 1
0
 def test_create_task_with_empty_file_reference(self):
     # Creates no file, if reference is empty
     form = TaskForm({
         'reference': '',
         'description': 'task description',
     })
     form.is_valid()
     task = form.save()
     self.assertEqual(Task.objects.count(), 1)
     self.assertIsNone(task.file)
Ejemplo n.º 2
0
 def test_create_task_with_unknown_file_reference(self):
     form = TaskForm({
         'reference': 'abcdef',
         'description': 'task description',
     })
     form.is_valid()
     task = form.save()
     self.assertEqual(Task.objects.count(), 1)
     self.assertEqual(File.objects.count(), 1)
     self.assertEqual(task.file.reference, 'abcdef')
Ejemplo n.º 3
0
 def test_empty_description(self):
     form = TaskForm({
         'reference': '123',
         'description': ''  # invalid
     })
     self.assertFalse(form.is_valid())
     self.assertIsNotNone(form.errors['description'])
Ejemplo n.º 4
0
 def test_max_length_reference(self):
     form = TaskForm({
         'reference': 'a' * 129,  # invalid
         'description': 'valid',
     })
     self.assertFalse(form.is_valid())
     self.assertIn('reference', form.errors)
Ejemplo n.º 5
0
 def post(self, request):
     form = TaskForm(request.POST)
     if form.is_valid():
         form.save()
         return redirect(reverse('index'))
     return self.render_to_response(self.get_context_data(form=form))