Exemple #1
0
    def test_wizard(self):
        class TestButton(Button):
            id_ = Button.generate_id('creme_config', 'test_wizard')
            verbose_name = 'Testing purpose'

        button_registry.register(TestButton)

        ct = self.contact_ct
        url = self.WIZARD_URL
        ctxt1 = self.assertGET200(url).context
        self.assertEqual(_('New buttons configuration'), ctxt1.get('title'))

        with self.assertNoException():
            ctypes = ctxt1['form'].fields['ctype'].ctypes

        self.assertIn(ct, ctypes)

        # ---
        step_key = 'button_menu_wizard-current_step'
        response2 = self.assertPOST200(
            url,
            data={
                step_key: '0',
                '0-ctype': ct.id,
            },
        )

        ctxt2 = response2.context
        self.assertEqual(
            _('New buttons configuration for «{model}»').format(model=ct),
            ctxt2.get('title'),
        )

        with self.assertNoException():
            choices = ctxt2['form'].fields['button_ids'].choices

        self.assertInChoices(
            value=TestButton.id_,
            label=button_registry.get_button(TestButton.id_),
            choices=choices,
        )

        # --
        response3 = self.client.post(
            url,
            data={
                step_key: '1',
                '1-button_ids': [TestButton.id_],
            },
        )
        self.assertNoFormError(response3)
        self.assertListEqual(
            [(TestButton.id_, 1000)],
            [
                *ButtonMenuItem.objects
                               .filter(content_type=ct)
                               .values_list('button_id', 'order'),
            ],
        )
Exemple #2
0
    def test_wizard(self):
        class TestButton(Button):
            id_          = Button.generate_id('creme_config', 'test_wizard')
            verbose_name = 'Testing purpose'

        # button = TestButton()
        # button_registry.register(button)
        button_registry.register(TestButton)

        ct = self.contact_ct
        url = self.WIZARD_URL
        response = self.assertGET200(url)

        with self.assertNoException():
            ctypes = response.context['form'].fields['ctype'].ctypes

        self.assertIn(ct, ctypes)

        step_key = 'button_menu_wizard-current_step'
        response = self.assertPOST200(url, data={step_key: '0',
                                                 '0-ctype': ct.id,
                                                },
                                     )

        with self.assertNoException():
            button_ids = response.context['form'].fields['button_ids']

        # button_index = self._find_field_index(button_ids, button.id_)
        button_index = self._find_field_index(button_ids, TestButton.id_)

        response = self.client.post(url,
                                    data={
                                        step_key: '1',
                                        '1-button_ids_check_{}'.format(button_index): 'on',
                                        # '1-button_ids_value_%s' % button_index: button.id_,
                                        '1-button_ids_value_{}'.format(button_index): TestButton.id_,
                                        '1-button_ids_order_{}'.format(button_index): 1,
                                    },
                                   )
        self.assertNoFormError(response)
        # self.assertEqual([(button.id_, 1000)],
        self.assertEqual([(TestButton.id_, 1000)],
                         [(bmi.button_id, bmi.order) for bmi in ButtonMenuItem.objects.filter(content_type=ct)]
                        )
Exemple #3
0
    def test_edit02(self):
        "Edit the default configuration."
        class TestButton(Button):
            id_ = Button.generate_id('creme_config', 'test_edit02')
            verbose_name = 'Testing purpose'

        button_registry.register(TestButton)

        url = reverse('creme_config__edit_ctype_buttons', args=(0,))
        response = self.assertGET200(url)
        self.assertTemplateUsed(response, 'creme_core/generics/blockform/edit-popup.html')

        context = response.context
        self.assertEqual(_('Edit default configuration'), context.get('title'))
        self.assertEqual(_('Save the modifications'),     context.get('submit_label'))

        with self.assertNoException():
            choices = context['form'].fields['button_ids'].choices

        self.assertInChoices(
            value=TestButton.id_,
            label=button_registry.get_button(TestButton.id_),
            choices=choices,
        )

        response = self.client.post(
            url,
            data={
                'button_ids': TestButton.id_,
            },
        )
        self.assertNoFormError(response)
        self.assertListEqual(
            [(TestButton.id_, 1)],
            [
                *ButtonMenuItem.objects
                               .filter(content_type=None)
                               .values_list('button_id', 'order'),
            ],
        )
Exemple #4
0
    def test_edit02(self):
        "Edit the default configuration"
        class TestButton(Button):
            id_          = Button.generate_id('creme_config', 'test_edit02')
            verbose_name = 'Testing purpose'


        # button = TestButton()
        # button_registry.register(button)
        button_registry.register(TestButton)

        url = reverse('creme_config__edit_ctype_buttons', args=(0,))
        response = self.assertGET200(url)
        # self.assertTemplateUsed(response, 'creme_core/generics/blockform/edit_popup.html')
        self.assertTemplateUsed(response, 'creme_core/generics/blockform/edit-popup.html')

        context = response.context
        self.assertEqual(_('Edit default configuration'), context.get('title'))
        self.assertEqual(_('Save the modifications'),     context.get('submit_label'))

        with self.assertNoException():
            button_ids = context['form'].fields['button_ids']

        # button_index = self._find_field_index(button_ids, button.id_)
        button_index = self._find_field_index(button_ids, TestButton.id_)

        response = self.client.post(url,
                                    data={'button_ids_check_{}'.format(button_index): 'on',
                                          # 'button_ids_value_%s' % button_index: button.id_,
                                          'button_ids_value_{}'.format(button_index): TestButton.id_,
                                          'button_ids_order_{}'.format(button_index): 1,
                                         }
                                   )
        self.assertNoFormError(response)
        # self.assertEqual([(button.id_, 1)],
        self.assertEqual([(TestButton.id_, 1)],
                         [(bmi.button_id, bmi.order) for bmi in ButtonMenuItem.objects.filter(content_type=None)]
                        )
Exemple #5
0
    def test_edit03(self):
        ct = self.contact_ct

        class TestButton01(Button):
            id_          = Button.generate_id('creme_config', 'test_edit03_1')
            verbose_name = 'Testing purpose'


        class TestButton02(Button):
            id_          = Button.generate_id('creme_config', 'test_edit03_2')
            verbose_name = 'Testing purpose'

            def get_ctypes(self):
                return [FakeContact, FakeOrganisation]


        class TestButton03(Button):
            id_          = Button.generate_id('creme_config', 'test_edit03_3')
            verbose_name = 'Testing purpose'

            def get_ctypes(self):
                return [FakeOrganisation]  # No Contact


        # button01 = TestButton01()
        # button02 = TestButton02()
        # button03 = TestButton03()
        # button_registry.register(button01, button02, button03)
        button_registry.register(TestButton01, TestButton02, TestButton03)

        # self.client.post(self.ADD_URL, data={'ctype': ct.id})
        # self.assertEqual(1, ButtonMenuItem.objects.filter(content_type=ct).count())
        ButtonMenuItem.objects.create(content_type=ct, order=1)

        url = reverse('creme_config__edit_ctype_buttons', args=(ct.id,))
        context = self.assertGET200(url).context
        self.assertEqual(_('Edit configuration for «{model}»').format(model=ct),
                         context.get('title')
                        )

        with self.assertNoException():
            button_ids = context['form'].fields['button_ids']

        # button01_index = self._find_field_index(button_ids, button01.id_)
        # button02_index = self._find_field_index(button_ids, button02.id_)
        button01_index = self._find_field_index(button_ids, TestButton01.id_)
        button02_index = self._find_field_index(button_ids, TestButton02.id_)

        for i, (f_button_id, f_button_vname) in enumerate(button_ids.choices):
            # if f_button_id == button03.id_:
            if f_button_id == TestButton03.id_:
                self.fail('Button03 is incompatible with Contact')

        response = self.client.post(url,
                                    data={'button_ids_check_{}'.format(button01_index): 'on',
                                          # 'button_ids_value_%s' % button01_index: button01.id_,
                                          'button_ids_value_{}'.format(button01_index): TestButton01.id_,
                                          'button_ids_order_{}'.format(button01_index): 1,

                                          'button_ids_check_{}'.format(button02_index): 'on',
                                          # 'button_ids_value_%s' % button02_index: button02.id_,
                                          'button_ids_value_{}'.format(button02_index): TestButton02.id_,
                                          'button_ids_order_{}'.format(button02_index): 2,
                                         }
                                   )
        self.assertNoFormError(response)
        # self.assertEqual([(button01.id_, 1000), (button02.id_, 1001)],
        self.assertEqual([(TestButton01.id_, 1000), (TestButton02.id_, 1001)],
                         [(bmi.button_id, bmi.order)
                            for bmi in ButtonMenuItem.objects.filter(content_type=ct)
                                                             .order_by('order')
                         ]
                        )
Exemple #6
0
    def test_edit03(self):
        ct = self.contact_ct

        class TestButton01(Button):
            id_ = Button.generate_id('creme_config', 'test_edit03_1')
            verbose_name = 'Test button #1'

        class TestButton02(Button):
            id_ = Button.generate_id('creme_config', 'test_edit03_2')
            verbose_name = 'Test button #2'

            def get_ctypes(self):
                return [FakeContact, FakeOrganisation]

        class TestButton03(Button):
            id_ = Button.generate_id('creme_config', 'test_edit03_3')
            verbose_name = 'Test button #3'

            def get_ctypes(self):
                return [FakeOrganisation]  # No Contact

        button_registry.register(TestButton01, TestButton02, TestButton03)

        ButtonMenuItem.objects.create(content_type=ct, order=1)

        url = reverse('creme_config__edit_ctype_buttons', args=(ct.id,))
        context = self.assertGET200(url).context
        self.assertEqual(
            _('Edit configuration for «{model}»').format(model=ct),
            context.get('title'),
        )

        with self.assertNoException():
            choices = context['form'].fields['button_ids'].choices

        self.assertInChoices(
            value=TestButton01.id_,
            label=button_registry.get_button(TestButton01.id_),
            choices=choices,
        )
        self.assertInChoices(
            value=TestButton02.id_,
            label=button_registry.get_button(TestButton02.id_),
            choices=choices,
        )

        # NB: Button03 is incompatible with Contact
        self.assertNotInChoices(value=TestButton03.id_, choices=choices)

        response = self.client.post(
            url,
            data={
                'button_ids': [TestButton01.id_, TestButton02.id_],
            },
        )
        self.assertNoFormError(response)
        self.assertListEqual(
            [(TestButton01.id_, 1000), (TestButton02.id_, 1001)],
            [
                *ButtonMenuItem.objects
                               .filter(content_type=ct)
                               .order_by('order')
                               .values_list('button_id', 'order'),
            ],
        )