Ejemplo n.º 1
0
    def test_get_params_must_return_unserialized_info(self):
        params = {'param1': 1, 'somedate': datetime.now()}

        report = Report(report='my_report_class')
        report.params = base64.b64encode(pickle.dumps(params))

        self.assertEqual(report.get_params(), params)
Ejemplo n.º 2
0
    def test_get_params_must_return_unserialized_info(self):
        params = {'param1': 1, 'somedate': datetime.now()}

        report = Report(report='my_report_class')
        report.params = base64.b64encode(pickle.dumps(params))

        self.assertEqual(report.get_params(), params)
Ejemplo n.º 3
0
    def test_to_string(self):
        report = Report(report='my_report_class')
        self.assertEqual(str(report), self.report_instance.name)

        report.save()

        self.assertEqual(str(report), '{} #{}'.format(self.report_instance.name, report.id))
Ejemplo n.º 4
0
    def test_process_must_call_process_from_report_class(self):
        report = Report(report='my_report_class')
        report.save()
        report.process()

        self.my_import_mocked.assert_called_once_with(report.report)
        self.assertTrue(self.report_instance.process.called)
Ejemplo n.º 5
0
    def test_process_must_set_status_as_processed_after_report_process(self):
        report = Report(report='my_report_class')
        report.save()
        report.process()

        report = Report.objects.get(id=report.id)
        self.assertEqual(report.status, Report.STATUS_PROCESSED)
Ejemplo n.º 6
0
    def test_process_must_set_status_as_error_if_some_exception_is_raised(self):
        self.report_instance.process.side_effect = Exception()

        report = Report(report='my_report_class')
        report.save()

        self.assertRaises(Exception, report.process)
        self.assertEqual(report.status, Report.STATUS_ERROR)
Ejemplo n.º 7
0
    def test_to_string(self):
        report = Report(report='my_report_class')
        self.assertEqual(str(report), self.report_instance.name)

        report.save()

        self.assertEqual(str(report),
                         '{} #{}'.format(self.report_instance.name, report.id))
Ejemplo n.º 8
0
    def test_process_must_set_status_as_error_if_some_exception_is_raised(
            self):
        self.report_instance.process.side_effect = Exception()

        report = Report(report='my_report_class')
        report.save()

        self.assertRaises(Exception, report.process)
        self.assertEqual(report.status, Report.STATUS_ERROR)
Ejemplo n.º 9
0
    def test_results_as_list_must_return_a_list(self):
        expected_results = [
            '/tmp/flunfa-2.tsv',
            '/tmp/flunfa-3.tsv',
        ]

        report = Report(report='my_report_class')
        report.results = ';'.join(expected_results)

        self.assertEqual(report.results_as_list, expected_results)
Ejemplo n.º 10
0
    def test_results_as_list_must_return_a_list(self):
        expected_results = [
            '/tmp/flunfa-2.tsv',
            '/tmp/flunfa-3.tsv',
        ]

        report = Report(report='my_report_class')
        report.results = ';'.join(expected_results)

        self.assertEqual(report.results_as_list, expected_results)
Ejemplo n.º 11
0
    def test_process_must_set_process_time(self):
        getcontext().prec = 5
        start = Decimal(10.0000)
        end = Decimal(15.1234)
        self.patch('onmydesk.models.timer', side_effect=[start, end])

        report = Report(report='my_report_class')
        report.save()
        report.process()

        self.assertEqual(report.process_time, end - start)
Ejemplo n.º 12
0
    def test_set_params_must_serializer_info_and_store_on_params_attr(self):
        report = Report(report='my_report_class')

        self.assertIsNone(report.params)

        params = {'param1': 1, 'somedate': datetime.now()}
        expected_result = base64.b64encode(pickle.dumps(params))

        report.set_params(params)

        self.assertEqual(report.params, expected_result)
Ejemplo n.º 13
0
    def test_set_params_must_serializer_info_and_store_on_params_attr(self):
        report = Report(report='my_report_class')

        self.assertIsNone(report.params)

        params = {'param1': 1, 'somedate': datetime.now()}
        expected_result = base64.b64encode(pickle.dumps(params))

        report.set_params(params)

        self.assertEqual(report.params, expected_result)
Ejemplo n.º 14
0
    def test_process_must_store_filepaths_result(self):
        self.report_instance.output_filepaths = [
            '/tmp/flunfa-2.tsv',
            '/tmp/flunfa-3.tsv',
        ]

        report = Report(report='my_report_class')
        report.save()
        report.process()

        self.assertEqual(
            report.results, ';'.join(self.report_instance.output_filepaths))
Ejemplo n.º 15
0
    def test_process_must_set_status_as_processing_when_start(self):
        self.patch('onmydesk.models.my_import', side_effect=Exception)

        report = Report(report='my_report_class')
        report.save()

        self.assertEqual(report.status, Report.STATUS_PENDING)

        try:
            report.process()
        except Exception:
            pass

        report = Report.objects.get(id=report.id)
        self.assertEqual(report.status, Report.STATUS_PROCESSING)
Ejemplo n.º 16
0
    def test_result_links(self):
        self.report_instance.output_filepaths = [
            '/tmp/flunfa-2.tsv',
            '/tmp/flunfa-3.tsv',
        ]

        report = Report(report='my_report_class')

        report.save()
        report.process()

        def my_handler(filepath):
            url_example = 'http://someplace.com/somepath{}'
            return url_example.format(filepath)

        with mock.patch('onmydesk.models.my_import', return_value=my_handler):
            links = report.result_links
            self.assertEqual(links, [my_handler(i) for i in self.report_instance.output_filepaths])
Ejemplo n.º 17
0
    def test_process_with_params_must_call_report_constructor_with_these_params(
            self):
        report = Report(report='my_report_class')

        params = {'type': 'whatever'}

        report.set_params(params)
        report.save()

        report.process()

        self.report_class.assert_called_once_with(params=params)
Ejemplo n.º 18
0
    def test_process_must_call_process_from_report_class(self):
        report = Report(report='my_report_class')
        report.save()
        report.process()

        self.my_import_mocked.assert_called_once_with(report.report)
        self.assertTrue(self.report_instance.process.called)
Ejemplo n.º 19
0
    def test_process_must_set_status_as_processed_after_report_process(self):
        report = Report(report='my_report_class')
        report.save()
        report.process()

        report = Report.objects.get(id=report.id)
        self.assertEqual(report.status, Report.STATUS_PROCESSED)
Ejemplo n.º 20
0
    def test_process_with_params_must_call_report_constructor_with_these_params(self):
        report = Report(report='my_report_class')

        params = {'type': 'whatever'}

        report.set_params(params)
        report.save()

        report.process()

        self.report_class.assert_called_once_with(params=params)
Ejemplo n.º 21
0
    def test_process_must_set_process_time(self):
        getcontext().prec = 5
        start = Decimal(10.0000)
        end = Decimal(15.1234)
        self.patch('onmydesk.models.timer', side_effect=[start, end])

        report = Report(report='my_report_class')
        report.save()
        report.process()

        self.assertEqual(report.process_time, end - start)
Ejemplo n.º 22
0
    def test_process_must_store_filepaths_result(self):
        self.report_instance.output_filepaths = [
            '/tmp/flunfa-2.tsv',
            '/tmp/flunfa-3.tsv',
        ]

        report = Report(report='my_report_class')
        report.save()
        report.process()

        self.assertEqual(report.results,
                         ';'.join(self.report_instance.output_filepaths))
Ejemplo n.º 23
0
    def test_process_must_set_status_as_processing_when_start(self):
        self.patch('onmydesk.models.my_import', side_effect=Exception)

        report = Report(report='my_report_class')
        report.save()

        self.assertEqual(report.status, Report.STATUS_PENDING)

        try:
            report.process()
        except Exception:
            pass

        report = Report.objects.get(id=report.id)
        self.assertEqual(report.status, Report.STATUS_PROCESSING)
Ejemplo n.º 24
0
    def test_result_links(self):
        self.report_instance.output_filepaths = [
            '/tmp/flunfa-2.tsv',
            '/tmp/flunfa-3.tsv',
        ]

        report = Report(report='my_report_class')

        report.save()
        report.process()

        def my_handler(filepath):
            url_example = 'http://someplace.com/somepath{}'
            return url_example.format(filepath)

        with mock.patch('onmydesk.models.my_import', return_value=my_handler):
            links = report.result_links
            self.assertEqual(
                links,
                [my_handler(i) for i in self.report_instance.output_filepaths])
Ejemplo n.º 25
0
    def test_results_as_list_must_return_empty_list_if_field_is_empty(self):
        report = Report(report='my_report_class')
        report.results = ''

        self.assertEqual(report.results_as_list, [])
Ejemplo n.º 26
0
    def test_get_params_returns_none_if_params_is_none(self):
        report = Report(report='my_report_class')
        report.params = None

        self.assertIsNone(report.get_params())
Ejemplo n.º 27
0
    def test_get_params_returns_none_if_params_is_none(self):
        report = Report(report='my_report_class')
        report.params = None

        self.assertIsNone(report.get_params())
Ejemplo n.º 28
0
 def test_to_string_with_empty_report_must_return_generic_name(self):
     report = Report()
     self.assertEqual(str(report), 'Report object')
Ejemplo n.º 29
0
    def test_results_as_list_must_return_empty_list_if_field_is_empty(self):
        report = Report(report='my_report_class')
        report.results = ''

        self.assertEqual(report.results_as_list, [])
Ejemplo n.º 30
0
 def test_process_with_not_saved_report_must_raise_a_exception(self):
     report = Report(report='my_report_class')
     self.assertRaises(ReportNotSavedException, report.process)