def test_only_survey_batches_are_allowed(self): bacth_id_not_belongin_got_self_survey = str(self.batch_3.id) data = {'survey':str(self.survey.id), 'batch':bacth_id_not_belongin_got_self_survey} indicator_filter_form = IndicatorFilterForm(data=data) self.assertFalse(indicator_filter_form.is_valid()) self.assertEqual(['Select a valid choice. %s is not one of the available choices.'%data['batch']],indicator_filter_form.errors['batch'])
def test_invalid_batch_choices(self): indicator_filter_form = IndicatorFilterForm( data={ 'survey': str(self.survey.id), 'batch': 'ayoyoyooooooo' }) self.assertTrue(indicator_filter_form.is_valid())
def test_only_survey_batches_are_allowed(self): bacth_id_not_belongin_got_self_survey = str(self.batch_3.id) data = { 'survey': str(self.survey.id), 'batch': bacth_id_not_belongin_got_self_survey } indicator_filter_form = IndicatorFilterForm(data=data) self.assertTrue(indicator_filter_form.is_valid())
def test_invalid_survey_choices(self): indicator_filter_form = IndicatorFilterForm(data={ 'survey': 'ayoyoyoyoooo', 'batch': str(self.batch.id) }) self.assertFalse(indicator_filter_form.is_valid()) self.assertEqual([ 'Select a valid choice. ayoyoyoyoooo is not one of the available choices.' ], indicator_filter_form.errors['survey'])
def test_only_survey_batches_are_allowed(self): bacth_id_not_belongin_got_self_survey = str(self.batch_3.id) data = { 'survey': str(self.survey.id), 'batch': bacth_id_not_belongin_got_self_survey } indicator_filter_form = IndicatorFilterForm(data=data) self.assertFalse(indicator_filter_form.is_valid()) self.assertEqual([ 'Select a valid choice. %s is not one of the available choices.' % data['batch'] ], indicator_filter_form.errors['batch'])
def test_form_instance_should_have_all_surveys(self): indicator_filter_form = IndicatorFilterForm() self.assertEqual(3, len(indicator_filter_form.fields['survey'].choices)) self.assertIn((self.survey.id, self.survey.name), indicator_filter_form.fields['survey'].choices) self.assertIn((self.survey_2.id, self.survey_2.name), indicator_filter_form.fields['survey'].choices)
def index(request): indicators = Indicator.objects.all() indicator_filter_form = IndicatorFilterForm(data=request.GET) indicators = _process_form(indicator_filter_form, indicators) return render(request, 'indicator/index.html', { 'indicators': indicators, 'indicator_filter_form': indicator_filter_form })
def test_form_instance_should_have_all_modules(self): indicator_filter_form = IndicatorFilterForm() self.assertEqual(4, len(indicator_filter_form.fields['module'].choices)) self.assertIn((self.module_1.id, self.module_1.name), indicator_filter_form.fields['module'].choices) self.assertIn((self.module_2.id, self.module_2.name), indicator_filter_form.fields['module'].choices) self.assertIn((self.module_3.id, self.module_3.name), indicator_filter_form.fields['module'].choices)
def test_form_instance_should_have_all_batches(self): indicator_filter_form = IndicatorFilterForm() self.assertEqual(5, len(indicator_filter_form.fields['batch'].choices)) self.assertIn((self.batch_1.id, self.batch_1.name), indicator_filter_form.fields['batch'].choices) self.assertIn((self.batch.id, self.batch.name), indicator_filter_form.fields['batch'].choices) self.assertIn((self.batch_3.id, self.batch_3.name), indicator_filter_form.fields['batch'].choices) self.assertIn((self.batch_4.id, self.batch_4.name), indicator_filter_form.fields['batch'].choices)
def test_form_should_show_batches_under_a_survey_only_if_survey_given( self): indicator_filter_form = IndicatorFilterForm( data={ 'survey': str(self.survey.id), 'question_set': 'All' }) self.assertEqual( 3, len(indicator_filter_form.fields['question_set'].choices)) self.assertIn((self.batch_1.id, self.batch_1.name), indicator_filter_form.fields['question_set'].choices) self.assertIn((self.batch.id, self.batch.name), indicator_filter_form.fields['question_set'].choices)
def test_only_survey_batches_are_allowed(self): bacth_id_not_belongin_got_self_survey = str(self.batch_3.id) data = {'survey': str(self.survey.id), 'batch': bacth_id_not_belongin_got_self_survey} indicator_filter_form = IndicatorFilterForm(data=data) self.assertTrue(indicator_filter_form.is_valid())
def test_invalid_batch_choices(self): indicator_filter_form = IndicatorFilterForm( data={'survey': str(self.survey.id), 'batch': 'ayoyoyooooooo'}) self.assertTrue(indicator_filter_form.is_valid())
def test_invalid_survey_choices(self): indicator_filter_form = IndicatorFilterForm( data={'survey': 'ayoyoyoyoooo', 'batch': str(self.batch.id)}) self.assertFalse(indicator_filter_form.is_valid()) self.assertEqual(['Select a valid choice. ayoyoyoyoooo is not one of the available choices.'], indicator_filter_form.errors['survey'])