コード例 #1
0
ファイル: test_tasks.py プロジェクト: lorn/connect
    def test_fires_added_to_group_signal(self):
        """
        Test that adding a user to a group fires the correct django signal

        Signal test method found at
        https://stackoverflow.com/questions/3817213/
        """
        def add_user_group_signal_receiver(**kwargs):
            """Demo signal for testing"""
            # pylint: disable=attribute-defined-outside-init
            self.add_signal_group = kwargs['group']
            self.add_signal_user = kwargs['user']

        # Attach our test signal
        group_member_added.connect(add_user_group_signal_receiver)

        group = self.create_group()
        user = self.create_user()

        self.assertFalse(hasattr(self, 'add_signal_group'))
        self.assertFalse(hasattr(self, 'add_signal_user'))
        add_user_to_group(user_id=user.pk, group_id=group.pk)

        self.assertEqual(self.add_signal_group, group)
        self.assertEqual(self.add_signal_user, user)

        group_member_added.disconnect(receiver=add_user_group_signal_receiver)
コード例 #2
0
ファイル: test_tasks.py プロジェクト: lorn/connect
    def test_does_not_remove_userthreads_for_other_groups(self):
        """Only delete UserThreads for the group a user is leaving."""
        # Create a new thread and add our user to the thread's group
        thread2 = self.create_thread()
        add_user_to_group(self.user.pk, thread2.group.pk)

        # Remove user from the group created in setup
        remove_user_from_group(self.user.pk, self.group.pk)

        # There should still be a userthread for the group created in this test
        # through thread2.
        self.assertTrue(
            UserThread.objects.filter(user=self.user, thread=thread2).exists())
コード例 #3
0
    def add_to_group(self,
                     group_id,
                     notification=None,
                     period=None,
                     immediate=False):
        """Adds the user to a group.

        Optionally provide kwargs, which will be passed into the subscription
        create statement
        """
        if immediate:
            group_tasks.add_user_to_group(user_id=self.pk,
                                          group_id=group_id,
                                          notification=notification,
                                          period=period)
        else:
            group_tasks.add_user_to_group.delay(user_id=self.pk,
                                                group_id=group_id,
                                                notification=notification,
                                                period=period)