Beispiel #1
0
    def test_knows_currently_open_survey(self):
        country = LocationType.objects.create(name='Country', slug='country')
        district = LocationType.objects.create(name='District',
                                               slug='district')
        uganda = Location.objects.create(name="Uganda", type=country)
        kampala = Location.objects.create(name="Kampala",
                                          type=district,
                                          tree_parent=uganda)

        open_survey = Survey.objects.create(name="open survey",
                                            description="open survey")
        closed_survey = Survey.objects.create(name="closed survey",
                                              description="closed survey")
        another_closed_survey = Survey.objects.create(
            name="another closed survey", description="another closed survey")

        open_batch = Batch.objects.create(order=1,
                                          name="Open Batch",
                                          survey=open_survey)
        closed_batch = Batch.objects.create(order=2,
                                            name="Closed Batch",
                                            survey=closed_survey)
        another_closed_batch = Batch.objects.create(
            order=3, name="Another Closed Batch", survey=another_closed_survey)

        open_batch.open_for_location(kampala)

        self.assertEqual(open_survey, Survey.currently_open_survey())
        self.assertNotEqual(closed_survey, Survey.currently_open_survey())
        self.assertNotEqual(another_closed_survey,
                            Survey.currently_open_survey())
Beispiel #2
0
 def test_saves_survey_with_sample_size_from_form_if_has_sampling_is_true(self):
     form_data = {
         'name': 'survey rajni',
         'description': 'survey description rajni',
         'has_sampling': True,
         'sample_size': 10,
         'type': True,
     }
     survey_form = SurveyForm(data=form_data)
     Survey.save_sample_size(survey_form)
     saved_survey = Survey.objects.filter(name=form_data['name'], has_sampling=form_data['has_sampling'])
     self.failUnless(saved_survey)
     self.assertEqual(form_data['sample_size'], saved_survey[0].sample_size)
Beispiel #3
0
 def test_saves_survey_with_sample_size_zero_if_has_sampling_is_false(self):
     form_data = {
         'name': 'survey rajni',
         'description': 'survey description rajni',
         'has_sampling': False,
         'sample_size': 10,
         'type': True,
     }
     survey_form = SurveyForm(data=form_data)
     Survey.save_sample_size(survey_form)
     saved_survey = Survey.objects.filter(
         name=form_data['name'], has_sampling=form_data['has_sampling'])
     self.failUnless(saved_survey)
     self.assertEqual(0, saved_survey[0].sample_size)
Beispiel #4
0
def edit(request, survey_id):
    survey = Survey.objects.get(id=survey_id)
    survey_form = SurveyForm(instance=survey)
    if request.method == 'POST':
        survey_form = SurveyForm(instance=survey, data=request.POST)
        if survey_form.is_valid():
            Survey.save_sample_size(survey_form)
            messages.success(request, 'Survey successfully edited.')
            return HttpResponseRedirect('/surveys/')

    context = {'survey_form': survey_form,
               'title': "Edit Survey",
               'button_label': 'Save',
               'id': 'edit-survey-form',
               'cancel_url': '/surveys/',
               'action': '/surveys/%s/edit/' %survey_id
               }
    return render(request, 'surveys/new.html', context)
Beispiel #5
0
 def test_fields(self):
     survey = Survey()
     fields = [str(item.attname) for item in survey._meta.fields]
     self.assertEqual(8, len(fields))
     for field in [
             'id', 'created', 'modified', 'name', 'description', 'type',
             'has_sampling', 'sample_size'
     ]:
         self.assertIn(field, fields)
Beispiel #6
0
    def test_knows_currently_open_survey(self):
        country = LocationType.objects.create(name='Country', slug='country')
        district = LocationType.objects.create(name='District', slug='district')
        uganda = Location.objects.create(name="Uganda", type=country)
        kampala = Location.objects.create(name="Kampala", type=district, tree_parent=uganda)

        open_survey = Survey.objects.create(name="open survey", description="open survey")
        closed_survey = Survey.objects.create(name="closed survey", description="closed survey")
        another_closed_survey = Survey.objects.create(name="another closed survey", description="another closed survey")

        open_batch = Batch.objects.create(order=1, name="Open Batch", survey=open_survey)
        closed_batch = Batch.objects.create(order=2, name="Closed Batch", survey=closed_survey)
        another_closed_batch = Batch.objects.create(order=3, name="Another Closed Batch", survey=another_closed_survey)

        open_batch.open_for_location(kampala)

        self.assertEqual(open_survey, Survey.currently_open_survey())
        self.assertNotEqual(closed_survey, Survey.currently_open_survey())
        self.assertNotEqual(another_closed_survey, Survey.currently_open_survey())
 def test_fields(self):
     survey = Survey()
     fields = [str(item.attname) for item in survey._meta.fields]
     self.assertEqual(10, len(fields))
     for field in [
             'id', 'created', 'modified', 'name', 'description',
             'has_sampling', 'sample_size', 'listing_form_id',
             'preferred_listing_id', 'random_sample_label'
     ]:
         self.assertIn(field, fields)
Beispiel #8
0
def edit(request, survey_id):
    survey = Survey.objects.get(id=survey_id)
    survey_form = SurveyForm(instance=survey)
    if request.method == 'POST':
        survey_form = SurveyForm(instance=survey, data=request.POST)
        if survey_form.is_valid():
            Survey.save_sample_size(survey_form)
            messages.success(request, 'Survey successfully edited.')
            return HttpResponseRedirect('/surveys/')

    context = {
        'survey_form': survey_form,
        'title': "Edit Survey",
        'button_label': 'Save',
        'id': 'edit-survey-form',
        'cancel_url': '/surveys/',
        'action': '/surveys/%s/edit/' % survey_id
    }
    return render(request, 'surveys/new.html', context)
Beispiel #9
0
def new(request):
    response = None
    survey_form = SurveyForm()

    if request.method == 'POST':
        survey_form = SurveyForm(request.POST)
        if survey_form.is_valid():
            Survey.save_sample_size(survey_form)
            messages.success(request, 'Survey successfully added.')
            response = HttpResponseRedirect('/surveys/')

    context = {'survey_form': survey_form,
               'title': "New Survey",
               'button_label': 'Create',
               'id': 'add-survey-form',
               'action': "/surveys/new/",
               'cancel_url': '/surveys/',
               }

    return response or render(request, 'surveys/new.html', context)
Beispiel #10
0
def new(request):
    response = None
    survey_form = SurveyForm()

    if request.method == 'POST':
        survey_form = SurveyForm(request.POST)
        if survey_form.is_valid():
            Survey.save_sample_size(survey_form)
            messages.success(request, 'Survey successfully added.')
            response = HttpResponseRedirect('/surveys/')

    context = {
        'survey_form': survey_form,
        'title': "New Survey",
        'button_label': 'Create',
        'id': 'add-survey-form',
        'action': "/surveys/new/",
        'cancel_url': '/surveys/',
    }

    return response or render(request, 'surveys/new.html', context)