def test_invalid(self): form_data = { 'name': 'test', 'description': 'description goes here', } batch_form = BatchForm(form_data) self.assertFalse(batch_form.is_valid())
def test_valid(self): form_data = { 'name': 'Batch 1', 'description': 'description goes here', } batch_form = BatchForm(form_data) self.assertTrue(batch_form.is_valid())
def test_valid(self): self.country = LocationType.objects.create(name='Country', slug='country') self.africa = Location.objects.create(name='Africa', type=self.country) self.city_ea = EnumerationArea.objects.create(name="CITY EA") self.city_ea.locations.add(self.africa) self.investigator_1 = Interviewer.objects.create( name="Investigator", ea=self.city_ea, gender='1', level_of_education='Primary', language='Eglish', weights=0) odk = ODKAccess.objects.create(interviewer=self.investigator_1, user_identifier='Test', is_active=True, reponse_timeout=1000, duration='H', odk_token='Test') form_data = { 'name': 'Batch 1', 'description': 'description goes here', } batch_form = BatchForm(form_data) self.assertFalse(batch_form.is_valid())
def _process_form(request, batchform, action_str='added'): if request.method == 'POST': batchform = BatchForm(data=request.POST, instance=batchform.instance) if batchform.is_valid(): batch = batchform.save() _add_success_message(request, action_str) batch_list_url = '/surveys/%s/batches/' % str(batch.survey.id) return HttpResponseRedirect(batch_list_url), batchform return None, batchform
def test_form_should_be_valid_if_name_already_exists_and_there_is_an_instance(self): survey = Survey.objects.create(name="very fast") form_data = { 'name': 'Batch A', 'description': 'description goes here', } batch = Batch.objects.create(survey=survey, name=form_data['name'], description='description') batch_form = BatchForm(data=form_data, instance=batch) self.assertTrue(batch_form.is_valid())
def test_form_should_be_invalid_if_name_already_exists_on_the_same_survey(self): survey = Survey.objects.create(name="very fast") Batch.objects.create(survey=survey, name='Batch A', description='description') form_data = { 'name': 'Batch A', 'description': 'description goes here', } batch_form = BatchForm(data=form_data, instance=Batch(survey=survey)) self.assertFalse(batch_form.is_valid())
def test_form_should_be_valid_if_name_already_exists_on_a_different_survey(self): survey = Survey.objects.create(name="very fast") form_data = { 'name': 'Batch A', 'description': 'description goes here', } Batch.objects.create(survey=survey, name=form_data['name'], description='description') different_survey = Survey.objects.create(name="different") batch_form = BatchForm(data=form_data, instance=Batch(survey=different_survey)) self.assertTrue(batch_form.is_valid())
def test_form_should_be_valid_if_name_already_exists_and_there_is_an_instance( self): survey = Survey.objects.create(name="very fast") form_data = { 'name': 'Batch A', 'description': 'description goes here', } batch = Batch.objects.create(survey=survey, name=form_data['name'], description='description') batch_form = BatchForm(data=form_data, instance=batch) self.assertTrue(batch_form.is_valid())
def _process_form(request, survey_id, instance=None, action_str='edited'): batch_form = BatchForm(instance=instance) response = None if request.method == 'POST': batch_form = BatchForm(data=request.POST, instance=instance) if batch_form.is_valid(): batch_form.save(**request.POST) messages.success(request, 'Question successfully %sed.' % action_str) response = HttpResponseRedirect(reverse('batch_index_page', args=(survey_id,))) else: messages.error(request, 'Question was not %sed.' % action_str) return response, batch_form
def _process_form(request, survey_id, instance=None, action_str='edited'): batch_form = BatchForm(instance=instance) response = None if request.method == 'POST': batch_form = BatchForm(data=request.POST, instance=instance) if batch_form.is_valid(): batch_form.save(**request.POST) messages.success(request, 'Question successfully %sed.' % action_str) response = HttpResponseRedirect( reverse('batch_index_page', args=(survey_id, ))) else: messages.error(request, 'Question was not %sed.' % action_str) return response, batch_form
def test_form_should_be_valid_if_name_already_exists_on_a_different_survey( self): survey = Survey.objects.create(name="very fast") form_data = { 'name': 'Batch A', 'description': 'description goes here', } Batch.objects.create(survey=survey, name=form_data['name'], description='description') different_survey = Survey.objects.create(name="different") batch_form = BatchForm(data=form_data, instance=Batch(survey=different_survey)) self.assertTrue(batch_form.is_valid())
def test_valid(self): self.country = LocationType.objects.create( name='Country', slug='country') self.africa = Location.objects.create(name='Africa', type=self.country) self.city_ea = EnumerationArea.objects.create(name="CITY EA") self.city_ea.locations.add(self.africa) self.investigator_1 = Interviewer.objects.create(name="Investigator", ea=self.city_ea, gender='1', level_of_education='Primary', language='Eglish', weights=0) odk = ODKAccess.objects.create(interviewer=self.investigator_1, user_identifier='Test', is_active=True, reponse_timeout=1000, duration='H', odk_token='Test') form_data = { 'name': 'Batch 1', 'description': 'description goes here', } batch_form = BatchForm(form_data) self.assertFalse(batch_form.is_valid())
def test_field_required(self): data={'name': '', 'description': ''} batch_form = BatchForm(data) self.assertFalse(batch_form.is_valid()) self.assertEqual(['This field is required.'], batch_form.errors['name'])
def test_field_required(self): data = {'name': '', 'description': ''} batch_form = BatchForm(data) self.assertFalse(batch_form.is_valid()) self.assertEqual(['This field is required.'], batch_form.errors['name'])