Пример #1
0
    def test_commands(self):
        """
        Ensure that the bot can handle the following commands:
        /staffbot staff <task_id>
        /staffbot restaff <task_id> <username>

        This test only validates that the commands are processed, other
        tests verify the functionality of the command execution.
        """
        bot = StaffBot()

        # Test staff command
        mock_slack_data = get_mock_slack_data(
            text='staff 5',
            user_id=self.worker.slack_user_id)

        response = bot.dispatch(mock_slack_data)
        self.assertFalse(bot.default_error_text in response.get('text', ''))

        # Test the restaff command
        mock_slack_data['text'] = 'restaff 5 username'
        response = bot.dispatch(mock_slack_data)
        self.assertFalse(bot.default_error_text in response.get('text', ''))

        # Test we fail gracefully
        mock_slack_data['text'] = 'invalid command'
        response = bot.dispatch(mock_slack_data)
        self.assertTrue(bot.default_error_text in response.get('text', ''))
Пример #2
0
    def test_commands(self):
        """
        Ensure that the bot can handle the following commands:
        /staffbot staff <task_id>
        /staffbot restaff <task_id> <username>

        This test only validates that the commands are processed, other
        tests verify the functionality of the command execution.
        """
        bot = StaffBot()

        # Test staff command
        mock_slack_data = get_mock_slack_data(
            text='staff 5', user_id=self.worker.slack_user_id)

        response = bot.dispatch(mock_slack_data)
        self.assertFalse(bot.default_error_text in response.get('text', ''))

        # Test the restaff command
        mock_slack_data['text'] = 'restaff 5 username'
        response = bot.dispatch(mock_slack_data)
        self.assertFalse(bot.default_error_text in response.get('text', ''))

        # Test we fail gracefully
        mock_slack_data['text'] = 'invalid command'
        response = bot.dispatch(mock_slack_data)
        self.assertTrue(bot.default_error_text in response.get('text', ''))
Пример #3
0
    def test_staff_command_errors(self):
        """
        Test that the staffing logic errors are raised during
        staff command.
        """
        bot = StaffBot()
        data = get_mock_slack_data(
            text='staff 999999999999',
            user_id=self.worker.slack_user_id)

        response = bot.dispatch(data)
        self.assertEqual(response['attachments'][0]['text'],
                         bot.task_does_not_exist_error.format('999999999999'))

        data['text'] = 'staff'
        response = bot.dispatch(data)
        self.assertTrue(bot.default_error_text in response.get('text'))

        task = TaskFactory(status=Task.Status.COMPLETE)
        data['text'] = 'staff {}'.format(task.id)
        response = bot.dispatch(data)
        self.assertEquals(response['attachments'][0]['text'],
                          bot.task_assignment_error
                          .format(task.id,
                                  'Status incompatible with new assignment'))
Пример #4
0
    def test_staff_command_errors(self):
        """
        Test that the staffing logic errors are raised during
        staff command.
        """
        bot = StaffBot()
        data = get_mock_slack_data(
            text='staff 999999999999',
            user_id=self.worker.slack_user_id)

        response = bot.dispatch(data)
        self.assertEqual(response['attachments'][0]['text'],
                         bot.task_does_not_exist_error.format('999999999999'))

        data['text'] = 'staff'
        response = bot.dispatch(data)
        self.assertTrue(bot.default_error_text in response.get('text'))

        task = TaskFactory(status=Task.Status.COMPLETE)
        data['text'] = 'staff {}'.format(task.id)
        response = bot.dispatch(data)
        self.assertEquals(response['attachments'][0]['text'],
                          bot.task_assignment_error
                          .format(task.id,
                                  'Status incompatible with new assignment'))
Пример #5
0
    def test_restaff_command_errors(self):
        """
        Test that the staffing logic errors are raised during
        staff command.
        """
        bot = StaffBot()
        data = get_mock_slack_data(
            text='restaff 999999999999 unknown',
            user_id=self.worker.slack_user_id)

        response = bot.dispatch(data)
        self.assertEqual(response.get('text'),
                         bot.worker_does_not_exist.format('unknown'))

        worker = WorkerFactory(user__username='******')
        data['text'] = 'restaff 999999999999 slackusername'
        response = bot.dispatch(data)
        self.assertEqual(response.get('text'),
                         bot.task_does_not_exist_error.format('999999999999'))

        data['text'] = 'restaff'
        response = bot.dispatch(data)
        self.assertTrue(bot.default_error_text in response.get('text'))

        task = TaskFactory(status=Task.Status.COMPLETE)
        command = 'restaff {} {}'.format(task.id, worker.user.username)

        data['text'] = command
        response = bot.dispatch(data)
        self.assertEquals(response.get('text'),
                          (bot.task_assignment_does_not_exist_error
                           .format(worker.user.username, task.id)))
Пример #6
0
    def test_restaff_command_errors(self):
        """
        Test that the staffing logic errors are raised during
        staff command.
        """
        bot = StaffBot()
        command = 'restaff 999999999999 unknown'
        data = get_mock_slack_data(
            text=command,
            user_id=self.worker.slack_user_id)

        response = bot.dispatch(data)
        self.assertEqual(response.get('text'),
                         command)

        self.assertEqual(response['attachments'][0]['text'],
                         bot.worker_does_not_exist.format('unknown'))

        worker = WorkerFactory(user__username='******')
        data['text'] = 'restaff 999999999999 username'
        response = bot.dispatch(data)
        self.assertEqual(response['attachments'][0]['text'],
                         bot.task_does_not_exist_error.format('999999999999'))

        # making sure it works with slack username as well.
        worker.slack_username = '******'
        worker.save()
        data['text'] = 'restaff 999999999999 slackusername'
        response = bot.dispatch(data)
        self.assertEqual(response['attachments'][0]['text'],
                         bot.task_does_not_exist_error.format('999999999999'))

        data['text'] = 'restaff'
        response = bot.dispatch(data)
        self.assertTrue(bot.default_error_text in response.get('text'))

        task = TaskFactory(status=Task.Status.COMPLETE)
        command = 'restaff {} {}'.format(task.id, worker.user.username)

        data['text'] = command
        response = bot.dispatch(data)
        self.assertEquals(response['attachments'][0]['text'],
                          (bot.task_assignment_does_not_exist_error
                           .format(worker.user.username, task.id)))
Пример #7
0
 def _test_staffing_requests(self, worker, task, command,
                             can_slack=False, can_mail=False):
     StaffBotRequest.objects.all().delete()
     bot = StaffBot()
     communication_type = (CommunicationPreference.CommunicationType
                           .NEW_TASK_AVAILABLE.value)
     communication_preference = CommunicationPreference.objects.get(
         worker=worker,
         communication_type=communication_type)
     communication_preference.methods.slack = can_slack
     communication_preference.methods.email = can_mail
     communication_preference.save()
     data = get_mock_slack_data(
         text=command,
         user_id=self.worker.slack_user_id)
     bot.dispatch(data)
     send_staffing_requests(worker_batch_size=20)
     self.assertEquals(StaffingRequestInquiry.objects.filter(
         communication_preference__worker_id=worker,
         request__task=task).count(), can_slack + can_mail)
Пример #8
0
 def _test_staffing_requests(self, worker, task, command,
                             can_slack=False, can_mail=False):
     StaffBotRequest.objects.all().delete()
     bot = StaffBot()
     communication_type = (CommunicationPreference.CommunicationType
                           .NEW_TASK_AVAILABLE.value)
     communication_preference = CommunicationPreference.objects.get(
         worker=worker,
         communication_type=communication_type)
     communication_preference.methods.slack = can_slack
     communication_preference.methods.email = can_mail
     communication_preference.save()
     data = get_mock_slack_data(
         text=command,
         user_id=self.worker.slack_user_id)
     bot.dispatch(data)
     send_staffing_requests(worker_batch_size=20,
                            frequency=timedelta(minutes=0))
     self.assertEquals(StaffingRequestInquiry.objects.filter(
         communication_preference__worker_id=worker,
         request__task=task).count(), can_slack + can_mail)
Пример #9
0
 def test_assert_validate_error(self):
     bot = StaffBot()
     with self.assertRaises(SlackUserUnauthorized):
         mock_slack_data = get_mock_slack_data(text='staff 5')
         bot.dispatch(mock_slack_data)
Пример #10
0
 def test_assert_validate_error(self):
     bot = StaffBot()
     with self.assertRaises(SlackUserUnauthorized):
         mock_slack_data = get_mock_slack_data(text='staff 5')
         bot.dispatch(mock_slack_data)