def test_process_must_notify_users(self):
        scheduler = Scheduler(report='my_report_class',
                              notify_emails='[email protected],[email protected]')

        with mock.patch('onmydesk.models.send_mail') as send_mail_mocked:
            scheduler.process()
            self.assertTrue(send_mail_mocked.called)
    def test_get_params_must_return_unserialized_info(self):
        params = {'param1': 1}

        report = Scheduler()
        report.params = base64.b64encode(pickle.dumps(params))

        self.assertEqual(report.get_params(), params)
    def test_get_params_must_return_unserialized_info(self):
        params = {'param1': 1}

        report = Scheduler()
        report.params = base64.b64encode(pickle.dumps(params))

        self.assertEqual(report.get_params(), params)
    def test_get_processed_params_must_return_date_fields_processed(self):
        scheduler = Scheduler(report='my_report_class')
        scheduler.set_params({'my_date': 'D-2', 'other_filter': 'other_value'})

        reference_date = date(2016, 4, 3)
        expected_param = {'my_date': date(2016, 4, 1), 'other_filter': 'other_value'}
        self.assertEqual(scheduler.get_processed_params(reference_date), expected_param)
    def test_process_must_return_a_saved_report_with_created_by_filled(self):
        user = User.objects.create_user('Joao', '*****@*****.**', '123souwebmaster')
        scheduler = Scheduler(report='my_report_class', created_by=user)

        report = scheduler.process()

        self.assertEqual(report.created_by, user)
    def test_get_processed_params_must_return_dictionary_with_parameters(self):
        scheduler = Scheduler()

        params = {'param1': 'First value'}

        scheduler.set_params(params)

        self.assertEqual(scheduler.get_processed_params(), params)
    def test_get_processed_params_must_return_dictionary_with_parameters(self):
        scheduler = Scheduler()

        params = {'param1': 'First value'}

        scheduler.set_params(params)

        self.assertEqual(scheduler.get_processed_params(), params)
    def _create_with_periodicity(self, per):
        sched = Scheduler(
            report='some-repo',
            periodicity=per,
        )
        sched.save()

        return sched
    def test_set_params_must_serializer_info_and_store_on_params_attr(self):
        scheduler = Scheduler()

        params = {'teste': 'Alisson'}

        scheduler.set_params(params)

        expected_result = base64.b64encode(pickle.dumps(params))
        self.assertEqual(scheduler.params, expected_result)
示例#10
0
    def test_process_must_return_a_saved_report_with_created_by_filled(self):
        user = User.objects.create_user(
            'Joao', '*****@*****.**',
            '123souwebmaster')
        scheduler = Scheduler(report='my_report_class', created_by=user)

        report = scheduler.process()

        self.assertEqual(report.created_by, user)
示例#11
0
    def test_set_params_must_serializer_info_and_store_on_params_attr(self):
        scheduler = Scheduler()

        params = {'teste': 'Alisson'}

        scheduler.set_params(params)

        expected_result = base64.b64encode(pickle.dumps(params))
        self.assertEqual(scheduler.params, expected_result)
示例#12
0
    def test_to_string(self):

        scheduler = Scheduler(report='my_report_class')

        with mock.patch('onmydesk.models.my_import', return_value=self.report_class):
            self.assertEqual(str(scheduler), 'My Report')

            scheduler.save()
            self.assertEqual(str(scheduler), 'My Report #{}'.format(scheduler.id))
示例#13
0
    def test_call_must_not_out_errors(self):
        scheduler = Scheduler(report='my_report_class',
                              periodicity=Scheduler.PER_MON_SUN)
        scheduler.save()

        errout = StringIO()
        management.call_command('scheduler_process', stderr=errout)

        self.assertEqual(len(errout.getvalue()), 0, errout.getvalue())
示例#14
0
    def test_call_must_call_process_from_scheduler(self):
        with mock.patch('onmydesk.models.Scheduler.process') as process_mocked:
            scheduler = Scheduler(report='my_report_class',
                                  periodicity=Scheduler.PER_MON_SUN)
            scheduler.save()

            management.call_command('scheduler_process')

            self.assertTrue(process_mocked.called)
示例#15
0
    def test_process_must_use_given_reference_date(self):
        self._patch('onmydesk.models.Report.process')

        scheduler = Scheduler(report='my_report_class')
        scheduler.set_params({'my_date': 'D-2', 'other_filter': 'other_value'})

        my_date = date(2016, 5, 10)
        with mock.patch('onmydesk.models.Report.set_params') as set_params:
            scheduler.process(reference_date=my_date)
            set_params.assert_called_once_with({'my_date': date(2016, 5, 8), 'other_filter': 'other_value'})
示例#16
0
    def test_to_string(self):

        scheduler = Scheduler(report='my_report_class')

        with mock.patch('onmydesk.models.my_import',
                        return_value=self.report_class):
            self.assertEqual(str(scheduler), 'My Report')

            scheduler.save()
            self.assertEqual(str(scheduler),
                             'My Report #{}'.format(scheduler.id))
示例#17
0
    def test_get_processed_params_must_return_date_fields_processed(self):
        scheduler = Scheduler(report='my_report_class')
        scheduler.set_params({'my_date': 'D-2', 'other_filter': 'other_value'})

        reference_date = date(2016, 4, 3)
        expected_param = {
            'my_date': date(2016, 4, 1),
            'other_filter': 'other_value'
        }
        self.assertEqual(scheduler.get_processed_params(reference_date),
                         expected_param)
示例#18
0
    def test_call_must_create_correct_report(self):
        scheduler = Scheduler(report='my_report_class',
                              periodicity=Scheduler.PER_MON_SUN)
        scheduler.save()

        self.assertEqual(Report.objects.all().count(), 0)

        out = StringIO()
        management.call_command('scheduler_process', stdout=out)

        self.assertEqual(Report.objects.all().count(), 1)

        repo = Report.objects.all().first()
        self.assertEqual(repo.report, 'my_report_class')
示例#19
0
    def test_call_must_have_first_and_last_message_correct(self):
        scheduler = Scheduler(report='my_report_class',
                              periodicity=Scheduler.PER_MON_SUN)
        scheduler.save()

        out = StringIO()
        management.call_command('scheduler_process', stdout=out)

        first_line, *_, last_line, blank_line = out.getvalue().split('\n')

        first_message = 'Starting scheduler process'
        last_message = 'Scheduler #{} processed'.format(scheduler.id)

        self.assertEqual(first_line, first_message)
        self.assertEqual(last_line, last_message)
示例#20
0
    def test_call_must_not_process_schedulers_from_other_day(self):
        # Forcing a date on sunday
        sunday_date = date(2016, 5, 15)
        date_mocked = mock.MagicMock()
        date_mocked.today.return_value = sunday_date
        with mock.patch('onmydesk.management.commands.scheduler_process.date',
                        return_value=date_mocked):
            # Creating a report scheduled to monday
            scheduler = Scheduler(report='my_report_class',
                                  periodicity=Scheduler.PER_MON)
            scheduler.save()

            self.assertEqual(Report.objects.all().count(), 0)
            management.call_command('scheduler_process')
            self.assertEqual(Report.objects.all().count(), 0)
示例#21
0
    def test_process_must_use_given_reference_date(self):
        self._patch('onmydesk.models.Report.process')

        scheduler = Scheduler(report='my_report_class')
        scheduler.set_params({'my_date': 'D-2', 'other_filter': 'other_value'})

        my_date = date(2016, 5, 10)
        with mock.patch('onmydesk.models.Report.set_params') as set_params:
            scheduler.process(reference_date=my_date)
            set_params.assert_called_once_with({
                'my_date': date(2016, 5, 8),
                'other_filter': 'other_value'
            })
示例#22
0
    def test_get_processed_params_must_return_none_if_params_is_none(self):
        scheduler = Scheduler(report='my_report_class')
        scheduler.params = None

        self.assertIsNone(scheduler.get_processed_params())
示例#23
0
    def test_process_must_not_notify_if_scheduler_has_no_emails(self):
        scheduler = Scheduler(report='my_report_class')

        with mock.patch('onmydesk.models.send_mail') as send_mail_mocked:
            scheduler.process()
            self.assertFalse(send_mail_mocked.called)
示例#24
0
    def test_process_must_not_notify_if_scheduler_has_no_emails(self):
        scheduler = Scheduler(report='my_report_class')

        with mock.patch('onmydesk.models.send_mail') as send_mail_mocked:
            scheduler.process()
            self.assertFalse(send_mail_mocked.called)
    def _create_with_periodicity(self, per):
        sched = Scheduler(report='some-repo',
                          periodicity=per,)
        sched.save()

        return sched
示例#26
0
    def test_process_must_call_report_process(self):
        scheduler = Scheduler(report='my_report_class')

        with mock.patch('onmydesk.models.Report.process') as process_mocked:
            scheduler.process()
            self.assertTrue(process_mocked.called)
示例#27
0
    def test_process_must_notify_users(self):
        scheduler = Scheduler(report='my_report_class', notify_emails='[email protected],[email protected]')

        with mock.patch('onmydesk.models.send_mail') as send_mail_mocked:
            scheduler.process()
            self.assertTrue(send_mail_mocked.called)
示例#28
0
    def test_to_string_with_empty_report_returns_generic_name(self):
        scheduler = Scheduler()

        self.assertEqual(str(scheduler), 'Scheduler object')
示例#29
0
    def test_process_must_return_a_saved_report(self):
        scheduler = Scheduler(report='my_report_class')
        report = scheduler.process()

        self.assertIsNotNone(report.id)
示例#30
0
    def test_process_must_return_a_saved_report(self):
        scheduler = Scheduler(report='my_report_class')
        report = scheduler.process()

        self.assertIsNotNone(report.id)
示例#31
0
    def test_process_must_return_report(self):
        scheduler = Scheduler(report='my_report_class')
        result = scheduler.process()

        self.assertIsInstance(result, Report)
示例#32
0
    def test_get_processed_params_must_return_none_if_params_is_none(self):
        scheduler = Scheduler(report='my_report_class')
        scheduler.params = None

        self.assertIsNone(scheduler.get_processed_params())
示例#33
0
    def test_process_must_return_report(self):
        scheduler = Scheduler(report='my_report_class')
        result = scheduler.process()

        self.assertIsInstance(result, Report)
示例#34
0
    def test_process_must_call_report_process(self):
        scheduler = Scheduler(report='my_report_class')

        with mock.patch('onmydesk.models.Report.process') as process_mocked:
            scheduler.process()
            self.assertTrue(process_mocked.called)