Example #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)
Example #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)
Example #3
0
    def test_signal_requested(self):
        # test if adminaction_requested Signal can stop the action

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

        try:
            adminaction_requested.connect(myhandler, sender=self.sender_model)
            self._run_action(1)
            self.assertTrue(myhandler.invoked)
            self.assertIn(self.MESSAGE, self.app.cookies['messages'])
        finally:
            adminaction_requested.disconnect(myhandler, sender=self.sender_model)
Example #4
0
    def test_signal_requested(self):
        # test if adminaction_requested Signal can stop the action

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

        try:
            adminaction_requested.connect(myhandler, sender=self.sender_model)
            # response = self._run_action(code2=302)
            response = self._run_action(code2=302)
            self.assertTrue(myhandler.invoked)
            self.assertIn(self.MESSAGE, response.cookies['messages'].value)
        finally:
            adminaction_requested.disconnect(myhandler, sender=self.sender_model)
Example #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)
    def test_signal_requested(self):
        # test if adminaction_requested Signal can stop the action

        MESSAGE = 'Action Interrupted Test'

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

        try:
            adminaction_requested.connect(myhandler, sender=Permission)
            response = self._run_action(code2=302)
            self.assertTrue(myhandler.invoked)
            self.assertIn(MESSAGE, response.cookies['messages'].value)
        finally:
            adminaction_requested.disconnect(myhandler, sender=Permission)
Example #7
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)