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})
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, }, }])