示例#1
0
    def test_text_option_type(self):

        option_group = OptionGroup.objects.get(pk=2)
        attendee = Attend.objects.get(pk=2)

        post = {
            _pack_id("option", 3): "some text",
        }

        OptionGroupSelectionsForm = dynamic_selections_form_factory(SCOPE.SADMIN, option_group)
        form = OptionGroupSelectionsForm(post, user=attendee.user, attendee=attendee)

        self.assertTrue(form.is_valid())
        self.assertEqual(form.cleaned_data[_pack_id('option', 3)], "some text")

        form.save()

        selections = dynamic_selections(SCOPE.VIEW_REGISTRATION,
                                        attendee,
                                        option_group=option_group,
                                        as_dict=True)

        option, selection = selections[3]
        self.assertIsNotNone(selection)
        self.assertEqual(selection.text, "some text")
示例#2
0
    def test_saving_selections_to_new_attendee(self):

        option_group = OptionGroup.objects.all()[0]
        attendee = Attend.objects.all()[0]

        OptionGroupSelectionsForm = dynamic_selections_form_factory(SCOPE.SADMIN, option_group)

        post = {
            _pack_id('option', 1): "1",
            _pack_id('option', 2): "1"
        }

        form = OptionGroupSelectionsForm(post, user=attendee.user)

        self.assertTrue(form.is_valid())

        self.assertTrue(hasattr(form, 'cleaned_data'))
        self.assertTrue(form.cleaned_data[_pack_id('option', 1)])
        self.assertTrue(form.cleaned_data[_pack_id('option', 2)])

        form.save(attendee=attendee)

        for option, selected in dynamic_selections(SCOPE.VIEW_REGISTRATION,
                                                   attendee,
                                                   option_group=option_group):
            self.assertTrue(selected)
示例#3
0
    def test_membership_widget_required_new_user(self):

        option_group = OptionGroup.objects.get(pk=2)
        attendee = Attend.objects.get(pk=1)

        OptionGroupSelectionsForm = dynamic_selections_form_factory(SCOPE.EDIT_REGISTRATION, option_group)
        form = OptionGroupSelectionsForm(
            {_pack_id("option", 2): _pack_id("suboption", 5)}, user=attendee.user, attendee=attendee
        )

        self.assertTrue(form.is_valid())
        self.assertTrue(hasattr(form, "cleaned_data"))

        form.save()

        self.assertEqual(Membership.objects.all().count(), 2)
示例#4
0
    def test_membership_widget_required_member_not_selecting_anything(self):

        option_group = OptionGroup.objects.get(pk=2)
        attendee = Attend.objects.get(pk=2)

        OptionGroupSelectionsForm = dynamic_selections_form_factory(SCOPE.EDIT_REGISTRATION, option_group)
        form = OptionGroupSelectionsForm({_pack_id("option", 2): "__EMPTY__"}, user=attendee.user, attendee=attendee)

        self.assertTrue(form.is_valid())
示例#5
0
    def test_delete_existing_selections(self):

        option_group = OptionGroup.objects.all()[0]
        attendee = Attend.objects.get(pk=2)

        for option, selection in dynamic_selections(SCOPE.VIEW_REGISTRATION,
                                                    attendee,
                                                    option_group=option_group):
            self.assertIsNotNone(selection)

        OptionGroupSelectionsForm = dynamic_selections_form_factory(SCOPE.SADMIN, option_group)

        form = OptionGroupSelectionsForm({}, user=attendee.user)

        self.assertTrue(form.is_valid())

        self.assertTrue(hasattr(form, 'cleaned_data'))
        self.assertFalse(form.cleaned_data[_pack_id('option', 1)])
        self.assertFalse(form.cleaned_data[_pack_id('option', 2)])

        form.save(attendee=attendee)

        for option, selected in dynamic_selections(SCOPE.VIEW_REGISTRATION, attendee, option_group=option_group):
            self.assertFalse(selected)