示例#1
0
 def test_choices_only_has_regions_that_do_not_have_published_questionnaires(self):
     questionnaire = Questionnaire.objects.create(name="JRF 2013 Core English", status=Questionnaire.PUBLISHED, year=2013, region=self.afro)
     data = {'questionnaire': self.questionnaire, 'regions': [self.paho.id]}
     publish_questionnaire_form = PublishQuestionnaireForm(initial={'questionnaire': self.questionnaire}, data=data)
     self.assertTrue(publish_questionnaire_form.is_valid())
     region_choices = [choice for choice in publish_questionnaire_form.fields['regions'].choices]
     self.assertIn((self.paho.id, self.paho.name), region_choices)
     self.assertNotIn((self.afro.id, self.afro.name), region_choices)
示例#2
0
 def test_choices_has_regions_when_questionnaire_is_archived(self):
     questionnaire = Questionnaire.objects.create(name="JRF 2013 Core English", status=Questionnaire.ARCHIVED,
                                                  year=2013, region=self.afro)
     data = {'questionnaire': self.questionnaire, 'regions': [self.paho.id]}
     publish_questionnaire_form = PublishQuestionnaireForm(initial={'questionnaire': self.questionnaire}, data=data)
     self.assertTrue(publish_questionnaire_form.is_valid())
     region_choices = [choice for choice in publish_questionnaire_form.fields['regions'].choices]
     self.assertIn((self.paho.id, self.paho.name), region_choices)
     self.assertIn((self.afro.id, self.afro.name), region_choices)
示例#3
0
 def post(self, *args, **kwargs):
     questionnaire = Questionnaire.objects.get(id=self.kwargs['questionnaire_id'])
     form = PublishQuestionnaireForm(initial={'questionnaire': questionnaire}, data=self.request.POST)
     if form.is_valid():
         form.save()
         message = "The questionnaire has been published to %s" % ", ".join([region.name for region in form.cleaned_data['regions']])
         messages.success(self.request, message)
         return HttpResponseRedirect(reverse('manage_jrf_page'))
     else:
         message = "Questionnaire could not be published see errors below"
         messages.error(self.request, message)
     context = {'questionnaire': questionnaire, 'publish_form': form, 'btn_label': "Publish",
                'cancel_url': reverse('manage_jrf_page')}
     return render(self.request, self.template_name, context)
示例#4
0
    def test_creates_copies_for_regions_on_save(self):
        Questionnaire.objects.create(name="JRF 2013 Core English", status=Questionnaire.PUBLISHED, year=2013, region=self.afro)
        pacific = Region.objects.create(name="haha", organization=self.who)
        asia = Region.objects.create(name="hehe", organization=self.who)

        data = {'questionnaire': self.questionnaire, 'regions': [self.paho.id, pacific.id, asia.id]}

        publish_questionnaire_form = PublishQuestionnaireForm(initial={'questionnaire': self.questionnaire}, data=data)
        self.assertTrue(publish_questionnaire_form.is_valid())
        publish_questionnaire_form.save()
        questionnaires = Questionnaire.objects.filter(year=self.questionnaire.year)
        self.assertEqual(5, questionnaires.count())
        [self.assertEqual(1, region.questionnaire.all().count()) for region in [self.paho, pacific, asia]]
        self.assertEqual(1, self.afro.questionnaire.all().count())
        questionnaire = Questionnaire.objects.filter(id=self.questionnaire.id)[0]
        self.assertEqual(questionnaire.status, Questionnaire.PUBLISHED)
示例#5
0
 def test_valid(self):
     publish_questionnaire_form = PublishQuestionnaireForm(initial={'questionnaire': self.questionnaire},
                                                           data=self.form_data)
     self.assertTrue(publish_questionnaire_form.is_valid())
     self.assertIn((self.paho.id, self.paho.name), publish_questionnaire_form.fields['regions'].choices)
     self.assertIn((self.afro.id, self.afro.name), publish_questionnaire_form.fields['regions'].choices)