예제 #1
0
 def get_data(self, start_date, end_date, venture):
     for percent, devices_list in Devices.get_data(
             start_date,
             end_date,
             venture,
     ):
         pass
     return devices_list
 def get_data(self, start_date, end_date, venture):
     for percent, devices_list in Devices.get_data(
         start_date,
         end_date,
         venture,
     ):
         pass
     return devices_list
예제 #3
0
    def test_get_report_data(self, plugin_run_mock):
        """
        Test generating data for whole report
        """
        def pl(chain, func_name, type, **kwargs):
            """
            Mock for plugin run. Should replace every schema and report plugin
            """
            data = {
                'information': {
                    'schema_devices':
                    OrderedDict([
                        ('barcode', {
                            'name': 'Barcode'
                        }),
                        ('sn', {
                            'name': 'SN'
                        }),
                        ('name', {
                            'name': 'Device name'
                        }),
                    ]),
                    'costs_per_device': {
                        self.device1.id: {
                            'sn': '1111-1111-1111',
                            'barcode': '12345',
                            'name': 'device1',
                        },
                        self.device2.id: {
                            'sn': '1111-1111-1112',
                            'barcode': '12346',
                            'name': 'device2',
                        }
                    },
                },
                'usage_plugin': {
                    'schema_devices':
                    OrderedDict([('ut1_count', {
                        'name': 'UT1 count'
                    }),
                                 ('ut1_cost', {
                                     'name': 'UT1 cost',
                                     'currency': True,
                                     'total_cost': True,
                                 })]),
                    'costs_per_device': {
                        self.device2.id: {
                            'ut1_count': 123,
                            'ut1_cost': D('23.23')
                        },
                    },
                },
                'ut3': {
                    'schema_devices':
                    OrderedDict([('ut3_count_warehouse_1', {
                        'name': 'UT3 count wh 1'
                    }), ('ut3_count_warehouse_2', {
                        'name': 'UT3 count wh 2'
                    }),
                                 ('ut3_cost_warehouse_1', {
                                     'name': 'UT3 cost wh 1',
                                     'currency': True,
                                 }),
                                 ('ut3_cost_warehouse_2', {
                                     'name': 'UT3 cost wh 2',
                                     'currency': True
                                 }),
                                 ('ut3_cost_total', {
                                     'name': 'UT3 total cost',
                                     'currency': True,
                                     'total_cost': True,
                                 })]),
                    'costs_per_device': {
                        self.device1.id: {
                            'ut3_count_warehouse_1': 267,
                            'ut3_cost_warehouse_1': D('4764.21'),
                            'ut3_count_warehouse_2': 36774,
                            'ut3_cost_warehouse_2': _('Incomplete price'),
                            'ut3_cost_total': D('4764.21'),
                        },
                        self.device2.id: {
                            'ut3_count_warehouse_1': 213,
                            'ut3_cost_warehouse_1': D('434.21'),
                            'ut3_count_warehouse_2': 3234,
                            'ut3_cost_warehouse_2': D('123.21'),
                            'ut3_cost_total': D('557.42'),
                        },
                    }
                },
            }
            if type == 'costs_per_device':
                self.assertTrue(kwargs.get('forecast'))
            result = data.get(func_name, {}).get(type)
            if result is not None:
                return result
            raise KeyError()

        plugin_run_mock.side_effect = pl
        result = None
        for percent, result in Devices.get_data(
                self.report_start,
                self.report_end,
                venture=self.venture,
                forecast=True,
        ):
            pass
        self.assertEquals(
            result,
            [
                [
                    '12345',  # barcode
                    '1111-1111-1111',  # sn
                    'device1',  # device name
                    267,  # ut3_count_warehouse_1
                    36774,  # ut3_cost_warehouse_1
                    '4764.21',  # ut3_count_warehouse_2
                    'Incomplete price',  # ut3_cost_warehouse_2
                    '4764.21',  # ut3_cost_total
                    0.0,  # ut1_count
                    '0.00',  # ut1_cost
                    '4764.21',  # total_cost
                ],
                [
                    '12346',  # barcode
                    '1111-1111-1112',  # sn
                    'device2',  # device name
                    213.00,  # ut3_count_warehouse_1
                    3234.00,  # ut3_cost_warehouse_1
                    '434.21',  # ut3_count_warehouse_2
                    '123.21',  # ut3_cost_warehouse_2
                    '557.42',  # ut3_cost_total
                    123.00,  # ut1_count
                    '23.23',  # ut1_cost
                    '580.65',  # total_cost
                ]
            ])
예제 #4
0
    def test_get_report_data(self, plugin_run_mock):
        """
        Test generating data for whole report
        """
        def pl(chain, func_name, type, **kwargs):
            """
            Mock for plugin run. Should replace every schema and report plugin
            """
            data = {
                'information': {
                    'schema_devices': OrderedDict([
                        ('barcode', {'name': 'Barcode'}),
                        ('sn', {'name': 'SN'}),
                        ('name', {'name': 'Device name'}),
                    ]),
                    'costs_per_device': {
                        self.device1.id: {
                            'sn': '1111-1111-1111',
                            'barcode': '12345',
                            'name': 'device1',
                        },
                        self.device2.id: {
                            'sn': '1111-1111-1112',
                            'barcode': '12346',
                            'name': 'device2',
                        }
                    },
                },
                'usage_plugin': {
                    'schema_devices': OrderedDict([
                        ('ut1_count', {'name': 'UT1 count'}),
                        ('ut1_cost', {
                            'name': 'UT1 cost',
                            'currency': True,
                            'total_cost': True,
                        })
                    ]),
                    'costs_per_device': {
                        self.device2.id: {
                            'ut1_count': 123,
                            'ut1_cost': D('23.23')
                        },
                    },
                },
                'ut3': {
                    'schema_devices': OrderedDict([
                        ('ut3_count_warehouse_1', {'name': 'UT3 count wh 1'}),
                        ('ut3_count_warehouse_2', {'name': 'UT3 count wh 2'}),
                        ('ut3_cost_warehouse_1', {
                            'name': 'UT3 cost wh 1',
                            'currency': True,
                        }),
                        ('ut3_cost_warehouse_2', {
                            'name': 'UT3 cost wh 2',
                            'currency': True
                        }),
                        ('ut3_cost_total', {
                            'name': 'UT3 total cost',
                            'currency': True,
                            'total_cost': True,
                        })
                    ]),
                    'costs_per_device': {
                        self.device1.id: {
                            'ut3_count_warehouse_1': 267,
                            'ut3_cost_warehouse_1': D('4764.21'),
                            'ut3_count_warehouse_2': 36774,
                            'ut3_cost_warehouse_2': _('Incomplete price'),
                            'ut3_cost_total': D('4764.21'),
                        },
                        self.device2.id: {
                            'ut3_count_warehouse_1': 213,
                            'ut3_cost_warehouse_1': D('434.21'),
                            'ut3_count_warehouse_2': 3234,
                            'ut3_cost_warehouse_2': D('123.21'),
                            'ut3_cost_total': D('557.42'),
                        },
                    }
                },
            }
            if type == 'costs_per_device':
                self.assertTrue(kwargs.get('forecast'))
            result = data.get(func_name, {}).get(type)
            if result is not None:
                return result
            raise KeyError()

        plugin_run_mock.side_effect = pl
        result = None
        for percent, result in Devices.get_data(
            self.report_start,
            self.report_end,
            venture=self.venture,
            forecast=True,
        ):
            pass
        self.assertEquals(result, [
            [
                '12345',  # barcode
                '1111-1111-1111',  # sn
                'device1',  # device name
                267,  # ut3_count_warehouse_1
                36774,  # ut3_cost_warehouse_1
                '4764.21',  # ut3_count_warehouse_2
                'Incomplete price',  # ut3_cost_warehouse_2
                '4764.21',  # ut3_cost_total
                0.0,  # ut1_count
                '0.00',  # ut1_cost
                '4764.21',  # total_cost
            ],
            [
                '12346',  # barcode
                '1111-1111-1112',  # sn
                'device2',  # device name
                213.00,  # ut3_count_warehouse_1
                3234.00,  # ut3_cost_warehouse_1
                '434.21',  # ut3_count_warehouse_2
                '123.21',  # ut3_cost_warehouse_2
                '557.42',  # ut3_cost_total
                123.00,  # ut1_count
                '23.23',  # ut1_cost
                '580.65',  # total_cost
            ]
        ])