Ejemplo n.º 1
0
    def test_signal_sent(self):
        def handler_factory(name):
            def myhandler(sender, action, request, queryset, **kwargs):
                handler_factory.invoked[name] = True
                self.assertEqual(action, self.action_name)
                self.assertSequenceEqual(queryset.order_by('id').values_list('id', flat=True),
                                         sorted(self._selected_values))

            return myhandler

        handler_factory.invoked = {}

        try:
            m1 = handler_factory('adminaction_requested')
            adminaction_requested.connect(m1, sender=self.sender_model)

            m2 = handler_factory('adminaction_start')
            adminaction_start.connect(m2, sender=self.sender_model)

            m3 = handler_factory('adminaction_end')
            adminaction_end.connect(m3, sender=self.sender_model)

            self._run_action()
            self.assertIn('adminaction_requested', handler_factory.invoked)
            self.assertIn('adminaction_start', handler_factory.invoked)
            self.assertIn('adminaction_end', handler_factory.invoked)

        finally:
            adminaction_requested.disconnect(m1, sender=self.sender_model)
            adminaction_start.disconnect(m2, sender=self.sender_model)
            adminaction_end.disconnect(m3, sender=self.sender_model)
Ejemplo n.º 2
0
    def test_signal_sent(self):
        def handler_factory(name):
            def myhandler(sender, action, request, queryset, **kwargs):
                handler_factory.invoked[name] = True
                self.assertEqual(action, self.action_name)
                self.assertSequenceEqual(
                    queryset.order_by('id').values_list('id', flat=True),
                    sorted(self._selected_values))

            return myhandler

        handler_factory.invoked = {}

        try:
            m1 = handler_factory('adminaction_requested')
            adminaction_requested.connect(m1, sender=self.sender_model)

            m2 = handler_factory('adminaction_start')
            adminaction_start.connect(m2, sender=self.sender_model)

            m3 = handler_factory('adminaction_end')
            adminaction_end.connect(m3, sender=self.sender_model)

            self._run_action()
            self.assertIn('adminaction_requested', handler_factory.invoked)
            self.assertIn('adminaction_start', handler_factory.invoked)
            self.assertIn('adminaction_end', handler_factory.invoked)

        finally:
            adminaction_requested.disconnect(m1, sender=self.sender_model)
            adminaction_start.disconnect(m2, sender=self.sender_model)
            adminaction_end.disconnect(m3, sender=self.sender_model)
Ejemplo n.º 3
0
    def test_signal_start(self):
        # test if adminaction_start Signal can stop the action

        def myhandler(sender, action, request, queryset, form, **kwargs):
            myhandler.invoked = True
            self.assertEqual(action, self.action_name)
            self.assertSequenceEqual(queryset.order_by('id').values_list('id', flat=True), self.selected_rows)
            self.assertTrue(isinstance(form, BaseForm))
            raise ActionInterrupted(self.MESSAGE)

        try:
            adminaction_start.connect(myhandler, sender=self.sender_model)
            response = self._run_action(code3=302)
            self.assertTrue(myhandler.invoked)
            self.assertIn(self.MESSAGE, response.cookies['messages'].value)
        finally:
            adminaction_start.disconnect(myhandler, sender=self.sender_model)
Ejemplo n.º 4
0
    def test_happy_path(self):
        url = reverse('admin:auth_user_changelist')

        def myhandler(sender, action, request, queryset, **kwargs):
            self.assertEqual(action, self.action_name)
            self.assertSequenceEqual(queryset.order_by('id').values_list('id', flat=True), self.selected_rows)

        try:
            adminaction_start.connect(myhandler, sender=User)
            adminaction_end.connect(myhandler, sender=User)
            adminaction_requested.connect(myhandler, sender=User)
            response = self._run_action(url=url, header=1)
            self.assertIn('Content-Disposition', response)
            self.assertIn('attachment;filename=', response['Content-Disposition'])
        finally:
            adminaction_start.disconnect(myhandler, sender=User)
            adminaction_end.disconnect(myhandler, sender=User)
            adminaction_requested.disconnect(myhandler, sender=User)
Ejemplo n.º 5
0
    def test_happy_path(self):
        url = reverse('admin:auth_user_changelist')

        def myhandler(sender, action, request, queryset, **kwargs):
            self.assertEqual(action, self.action_name)
            self.assertSequenceEqual(
                queryset.order_by('id').values_list('id', flat=True),
                self.selected_rows)

        try:
            adminaction_start.connect(myhandler, sender=User)
            adminaction_end.connect(myhandler, sender=User)
            adminaction_requested.connect(myhandler, sender=User)
            response = self._run_action(url=url, header=1)
            self.assertIn('Content-Disposition', response)
            self.assertIn('attachment;filename=',
                          response['Content-Disposition'])
        finally:
            adminaction_start.disconnect(myhandler, sender=User)
            adminaction_end.disconnect(myhandler, sender=User)
            adminaction_requested.disconnect(myhandler, sender=User)