def test_survey_should_not_be_empty(self):
     form_data = self.form_data.copy()
     form_data['survey'] = ''
     indicator_form = IndicatorForm(form_data)
     self.assertFalse(indicator_form.is_valid())
     self.assertEqual(['This field is required.'],
                      indicator_form.errors['survey'])
 def test_invalid(self):
     form_data = self.form_data
     form_data['name'] = ''
     indicator_form = IndicatorForm(form_data)
     self.assertFalse(indicator_form.is_valid())
     self.assertEqual(['This field is required.'],
                      indicator_form.errors['name'])
Ejemplo n.º 3
0
 def test_survey_should_not_be_empty(self):
     form_data = self.form_data.copy()
     form_data['survey'] = ''
     indicator_form = IndicatorForm(form_data)
     self.assertFalse(indicator_form.is_valid())
     self.assertEqual(['This field is required.'],
                      indicator_form.errors['survey'])
Ejemplo n.º 4
0
 def test_invalid(self):
     form_data = self.form_data.copy()
     form_data['name'] = ''
     indicator_form = IndicatorForm(form_data)
     self.assertFalse(indicator_form.is_valid())
     self.assertEqual(['This field is required.'],
                      indicator_form.errors['name'])
Ejemplo n.º 5
0
 def test_batch_should_belong_to_survey(self):
     form_data = self.form_data.copy()
     new_survey = Survey.objects.create(name="haha")
     new_batch = Batch.objects.create(
         name="batch not belonging to survey", survey=new_survey)
     form_data['batch'] = new_batch.id
     indicator_form = IndicatorForm(form_data)
     self.assertFalse(indicator_form.is_valid())
 def test_batch_should_belong_to_survey(self):
     form_data = self.form_data.copy()
     new_survey = Survey.objects.create(name="haha")
     new_batch = Batch.objects.create(name="batch not belonging to survey",
                                      survey=new_survey)
     form_data['batch'] = new_batch.id
     indicator_form = IndicatorForm(form_data)
     self.assertFalse(indicator_form.is_valid())
Ejemplo n.º 7
0
 def test_batch_should_belong_to_survey(self):
     form_data = self.form_data.copy()
     new_survey= Survey.objects.create(name="haha")
     new_batch = Batch.objects.create(name="batch not belonging to survey", survey=new_survey)
     form_data['batch'] = new_batch.id
     indicator_form = IndicatorForm(form_data)
     self.assertFalse(indicator_form.is_valid())
     self.assertEqual(["Batch %s does not belong to the selected Survey."% (new_batch.name)], indicator_form.errors['batch'])
Ejemplo n.º 8
0
 def test_batch_should_belong_to_survey(self):
     form_data = self.form_data.copy()
     new_survey = Survey.objects.create(name="haha")
     new_batch = Batch.objects.create(name="batch not belonging to survey",
                                      survey=new_survey)
     form_data['batch'] = new_batch.id
     indicator_form = IndicatorForm(form_data)
     self.assertFalse(indicator_form.is_valid())
     self.assertEqual([
         "Select a valid choice. That choice is not one of the available choices."
     ], indicator_form.errors['batch'])
Ejemplo n.º 9
0
def edit(request, indicator_id):
    indicator = Indicator.objects.get(id=indicator_id)
    indicator_form = IndicatorForm(instance=indicator)
    if request.method == 'POST':
        indicator_form = IndicatorForm(data=request.POST, instance=indicator)
        if indicator_form.is_valid():
            indicator_form.save()
            messages.success(request, "Indicator successfully edited.")
            return HttpResponseRedirect("/indicators/")
        messages.error(request, "Indicator was not successfully edited.")
    context = {'indicator_form': indicator_form, 'title': 'Edit Indicator', 'button_label': 'Save'}
    return render(request, 'indicator/new.html', context)
Ejemplo n.º 10
0
def new(request):
    indicator_form = IndicatorForm()
    if request.method == 'POST':
        indicator_form = IndicatorForm(request.POST)
        if indicator_form.is_valid():
            indicator_form.save()
            messages.success(request, "Indicator successfully created.")
            return HttpResponseRedirect("/indicators/")
        messages.error(request, "Indicator was not created.")
    return render(request, 'indicator/new.html',
                  {'indicator_form': indicator_form, 'title': 'Add Indicator', 'button_label': 'Create',
                   'cancel_url':'/indicators/', 'action': '/indicators/new/'})
Ejemplo n.º 11
0
 def test_batch_should_belong_to_survey(self):
     form_data = self.form_data.copy()
     new_survey = Survey.objects.create(name="haha")
     new_batch = Batch.objects.create(name="batch not belonging to survey",
                                      survey=new_survey)
     form_data['batch'] = new_batch.id
     indicator_form = IndicatorForm(form_data)
     self.assertFalse(indicator_form.is_valid())
     self.assertEqual([
         "Batch %s does not belong to the selected Survey." %
         (new_batch.name)
     ], indicator_form.errors['batch'])
 def test_indicator_form_enforces_name_to_be_alphanumeric(self):
     data = self.form_data
     indicator_form = IndicatorForm(data=data)
     indicator_form.is_valid(
     )  # not so much interested if it is valid or not just want to create the cleaned
     self.assertTrue(indicator_form.cleaned_data['name'], data['name'])
     data['name'] = 'Men>4'
     indicator_form = IndicatorForm(data=data)
     indicator_form.is_valid()  # again not interested. just to confirm
     self.assertNotIn('name', indicator_form.cleaned_data)
Ejemplo n.º 13
0
def edit(request, indicator_id):
    indicator = Indicator.objects.get(id=indicator_id)
    indicator_form = IndicatorForm(instance=indicator)
    if request.method == 'POST':
        indicator_form = IndicatorForm(data=request.POST, instance=indicator)
        if indicator_form.is_valid():
            indicator_form.save()
            messages.success(request, "Indicator successfully edited.")
            return HttpResponseRedirect("/indicators/")
        messages.error(request, "Indicator was not successfully edited.")
    request.breadcrumbs([
        ('Indicators', reverse('list_indicator_page')),
    ])
    context = {
        'indicator_form': indicator_form,
        'title': 'Edit Indicator',
        'button_label': 'Save',
        'cancel_url': reverse('list_indicator_page'),
        'variable_form': IndicatorVariableForm(None)}
    return render(request, 'indicator/new.html', context)
Ejemplo n.º 14
0
def new(request):
    """Creates new indicator. HTML uses with ajax to create variables on same screen with popups"""
    indicator_form = IndicatorForm()
    if request.method == 'POST':
        indicator_form = IndicatorForm(data=request.POST)
        if indicator_form.is_valid():
            indicator_form.save()
            messages.success(request, "Indicator successfully created.")
            return HttpResponseRedirect(reverse('list_indicator_page'))
        messages.error(request, "Indicator was not created.")
    request.breadcrumbs([
        ('Indicators', reverse('list_indicator_page')),
    ])

    return render(request,
                  'indicator/new.html',
                  {'indicator_form': indicator_form,
                   'title': 'Add Indicator',
                   'button_label': 'Create',
                   'cancel_url': reverse('list_indicator_page'),
                   'action': '/indicators/new/',
                   'variable_form': IndicatorVariableForm(None)})
Ejemplo n.º 15
0
def edit(request, indicator_id):
    indicator = Indicator.objects.get(id=indicator_id)
    indicator_form = IndicatorForm(instance=indicator)
    if request.method == 'POST':
        indicator_form = IndicatorForm(data=request.POST, instance=indicator)
        if indicator_form.is_valid():
            indicator_form.save()
            messages.success(request, "Indicator successfully edited.")
            return HttpResponseRedirect("/indicators/")
        messages.error(request, "Indicator was not successfully edited.")
    context = {
        'indicator_form': indicator_form,
        'title': 'Edit Indicator',
        'button_label': 'Save'
    }
    return render(request, 'indicator/new.html', context)
 def test_indicator_formulae(self):
     qset = mommy.make(Batch, survey=self.survey)
     indicator_variable = mommy.make(IndicatorVariable,
                                     name='test_variable')
     indicator_variable2 = mommy.make(IndicatorVariable,
                                      name='test_variable2')
     form_data = self.form_data
     form_data['formulae'] = '{{*-a}} > 1'
     form_data['question_set'] = qset.id
     data = QueryDict(mutable=True,
                      query_string='variables[]=%s&variables[]=%s' %
                      (indicator_variable.id, indicator_variable2.id))
     data.update(**form_data)
     indicator_form = IndicatorForm(data)
     self.assertFalse(indicator_form.is_valid())
     form_data['formulae'] = '{{test_variable > 1'
     data.update(**form_data)
     indicator_form = IndicatorForm(data)
     self.assertFalse(indicator_form.is_valid())
     form_data['formulae'] = '{{test_variable}} > 1'
     data.update(**form_data)
     indicator_form = IndicatorForm(data)
     self.assertTrue(indicator_form.is_valid())
Ejemplo n.º 17
0
def new(request):
    indicator_form = IndicatorForm()
    if request.method == 'POST':
        indicator_form = IndicatorForm(request.POST)
        if indicator_form.is_valid():
            indicator_form.save()
            messages.success(request, "Indicator successfully created.")
            return HttpResponseRedirect("/indicators/")
        messages.error(request, "Indicator was not created.")
    return render(
        request, 'indicator/new.html', {
            'indicator_form': indicator_form,
            'title': 'Add Indicator',
            'button_label': 'Create',
            'cancel_url': '/indicators/',
            'action': '/indicators/new/'
        })
Ejemplo n.º 18
0
def edit(request, indicator_id):
    indicator = Indicator.objects.get(id=indicator_id)
    indicator_form = IndicatorForm(instance=indicator)
    if request.method == 'POST':
        indicator_form = IndicatorForm(data=request.POST, instance=indicator)
        if indicator_form.is_valid():
            indicator_form.save()
            messages.success(request, "Indicator successfully edited.")
            return HttpResponseRedirect("/indicators/")
        messages.error(request, "Indicator was not successfully edited.")
    request.breadcrumbs([
        ('Indicators', reverse('list_indicator_page')),
    ])
    context = {
        'indicator_form': indicator_form,
        'title': 'Edit Indicator',
        'button_label': 'Save',
        'cancel_url': reverse('list_indicator_page'),
        'variable_form': IndicatorVariableForm(None)
    }
    return render(request, 'indicator/new.html', context)
Ejemplo n.º 19
0
def new(request):
    """Creates new indicator. HTML uses with ajax to create variables on same screen with popups"""
    indicator_form = IndicatorForm()
    if request.method == 'POST':
        indicator_form = IndicatorForm(data=request.POST)
        if indicator_form.is_valid():
            indicator_form.save()
            messages.success(request, "Indicator successfully created.")
            return HttpResponseRedirect(reverse('list_indicator_page'))
        messages.error(request, "Indicator was not created.")
    request.breadcrumbs([
        ('Indicators', reverse('list_indicator_page')),
    ])

    return render(
        request, 'indicator/new.html', {
            'indicator_form': indicator_form,
            'title': 'Add Indicator',
            'button_label': 'Create',
            'cancel_url': reverse('list_indicator_page'),
            'action': '/indicators/new/',
            'variable_form': IndicatorVariableForm(None)
        })
 def test_survey_does_not_match_qset(self):
     qset = mommy.make(Batch, survey=self.survey)
     form_data = self.form_data
     indicator_form = IndicatorForm(data=form_data)
     self.assertFalse(indicator_form.is_valid())
     self.assertIn('question_set', indicator_form.errors)
Ejemplo n.º 21
0
 def test_valid(self):
     indicator_form = IndicatorForm(self.form_data)
     self.assertTrue(indicator_form.is_valid())
Ejemplo n.º 22
0
 def test_valid(self):
     indicator_form = IndicatorForm(self.form_data)
     self.assertTrue(indicator_form.is_valid())