Esempio n. 1
0
    def test_member_receives_application_update(self):
        application = ApplicationFactory(user=self.user, group=self.group)

        client = self.connect_as(self.member)

        application.status = 'accepted'
        application.save()

        messages = client.messages_by_topic['applications:update']
        self.assertEqual(len(messages), 1)
        response = messages[0]
        self.assertEqual(response['payload']['id'], application.id)

        messages = client.messages_by_topic['status']
        self.assertEqual(len(messages), 2, messages)
        # No pending applications
        self.assertEqual(
            messages[1]['payload'],
            {'groups': {
                self.group.id: {
                    'pending_application_count': 0
                }
            }})
        # Notification gets deleted because application has been accepted
        self.assertEqual(messages[0]['payload'],
                         {'unseen_notification_count': 0})
Esempio n. 2
0
    def test_applicant_receives_application_update(self):
        application = ApplicationFactory(user=self.user, group=self.group)

        self.client = self.connect_as(self.user)

        application.status = 'accepted'
        application.save()

        messages = self.application_update_messages()
        self.assertEqual(len(messages), 1)
        response = messages[0]
        self.assertEqual(response['payload']['id'], application.id)
Esempio n. 3
0
    def test_application_status_update(self, write_points):
        write_points.reset_mock()

        two_hours_ago = timezone.now() - relativedelta(hours=2)

        application = ApplicationFactory(group=GroupFactory(),
                                         user=UserFactory(),
                                         created_at=two_hours_ago)

        write_points.assert_called_with([{
            'measurement': 'karrot.events',
            'tags': {
                'group': str(application.group.id),
                'group_status': application.group.status,
            },
            'fields': {
                'application_pending': 1,
            },
        }])

        write_points.reset_mock()
        application.status = 'accepted'
        application.save()

        self.assertEqual(len(write_points.mock_calls), 1)

        point = write_points.call_args[0][0][0]

        expected_seconds = 60 * 60 * 2
        # can take a little longer to run sometimes...
        expected_seconds_range = range(expected_seconds, expected_seconds + 3)

        self.assertEqual(point['measurement'], 'karrot.events')
        self.assertEqual(
            point['tags'], {
                'group': str(application.group.id),
                'group_status': application.group.status,
                'application_status': application.status,
            })
        self.assertEqual(point['fields']['application_accepted'], 1)
        self.assertIn(point['fields']['application_alive_seconds'],
                      expected_seconds_range)
        self.assertIn(point['fields']['application_accepted_alive_seconds'],
                      expected_seconds_range)
Esempio n. 4
0
    def test_applicant_receives_application_update(self):
        application = ApplicationFactory(user=self.user, group=self.group)
        Notification.objects.all().delete()

        client = self.connect_as(self.user)

        application.status = 'accepted'
        application.save()

        messages = client.messages_by_topic['applications:update']
        self.assertEqual(len(messages), 1)
        response = messages[0]
        self.assertEqual(response['payload']['id'], application.id)

        messages = client.messages_by_topic['status']
        self.assertEqual(len(messages), 1, messages)
        # "Your application has been accepted"
        self.assertEqual(messages[0]['payload'],
                         {'unseen_notification_count': 1})
Esempio n. 5
0
    def test_application_status_update(self, write_points):
        write_points.reset_mock()

        two_hours_ago = timezone.now() - relativedelta(hours=2)

        application = ApplicationFactory(group=GroupFactory(),
                                         user=UserFactory(),
                                         created_at=two_hours_ago)

        write_points.assert_called_with([{
            'measurement': 'karrot.events',
            'tags': {
                'group': str(application.group.id),
                'group_status': application.group.status,
            },
            'fields': {
                'application_pending': 1,
            },
        }])

        write_points.reset_mock()
        application.status = 'accepted'
        application.save()

        write_points.assert_called_with([{
            'measurement': 'karrot.events',
            'tags': {
                'group': str(application.group.id),
                'group_status': application.group.status,
                'application_status': application.status,
            },
            'fields': {
                'application_accepted': 1,
                'application_alive_seconds': 60 * 60 * 2,
                'application_accepted_alive_seconds': 60 * 60 * 2,
            },
        }])