Esempio n. 1
0
    def test_get_ventures(self):
        """
        Test if ventures are correctly filtered
        """
        get_ids = lambda l: [i.id for i in l]

        ventures1 = AllVentures._get_ventures(is_active=True)
        self.assertEquals(get_ids(ventures1),
                          get_ids([self.venture2, self.venture]))

        ventures1 = AllVentures._get_ventures(is_active=False)
        self.assertEquals(
            get_ids(ventures1),
            get_ids([self.venture2, self.venture, self.subventure]))
Esempio n. 2
0
    def test_get_ventures(self):
        """
        Test if ventures are correctly filtered
        """
        get_ids = lambda l: [i.id for i in l]

        ventures1 = AllVentures._get_ventures(is_active=True)
        self.assertEquals(get_ids(ventures1),
                          get_ids([self.venture2, self.venture]))

        ventures1 = AllVentures._get_ventures(is_active=False)
        self.assertEquals(
            get_ids(ventures1),
            get_ids([self.venture2, self.venture, self.subventure])
        )
Esempio n. 3
0
 def test_get_plugins(self):
     """
     Test plugins list based on visible usage types
     """
     plugins = AllVentures._get_plugins()
     self.assertEquals(plugins, [
         dict(name='Information', plugin_name='information'),
         dict(
             name='UT3',
             plugin_name=self.warehouse_usage_type.get_plugin_name(),
             plugin_kwargs=dict(
                 usage_type=self.warehouse_usage_type,
                 no_price_msg=True,
             ),
         ),  # order matters
         dict(
             name='UT1',
             plugin_name=self.usage_type.get_plugin_name(),
             plugin_kwargs=dict(
                 usage_type=self.usage_type,
                 no_price_msg=True,
             ),
         ),
         dict(
             name='Service1',
             plugin_name=self.service.get_plugin_name(),
             plugin_kwargs=dict(
                 service=self.service,
             ),
         ),
     ])
Esempio n. 4
0
 def test_get_plugins(self):
     """
     Test plugins list based on visible usage types
     """
     plugins = AllVentures.get_plugins()
     self.maxDiff = None
     self.assertEquals(
         plugins,
         [
             dict(name='Information', plugin_name='information'),
             dict(
                 name='UT3',
                 plugin_name=self.warehouse_usage_type.get_plugin_name(),
                 plugin_kwargs=dict(
                     usage_type=self.warehouse_usage_type,
                     no_price_msg=True,
                 ),
             ),  # order matters
             dict(
                 name='UT1',
                 plugin_name=self.usage_type.get_plugin_name(),
                 plugin_kwargs=dict(
                     usage_type=self.usage_type,
                     no_price_msg=True,
                 ),
             ),
             dict(
                 name='Service1',
                 plugin_name=self.service.get_plugin_name(),
                 plugin_kwargs=dict(service=self.service, ),
             ),
             dict(name='ExtraCostsPlugin', plugin_name='extra_cost_plugin'),
         ])
Esempio n. 5
0
 def test_get_header(self, get_schema_mock):
     """
     Test getting headers for report
     """
     get_schema_mock.return_value = utils.sample_schema()
     result = AllVentures.get_header()
     self.assertEquals(result, [[
         'Field1', 'Field2 - PLN', 'Field3', 'Field4 - PLN', 'Total cost'
     ]])
Esempio n. 6
0
 def test_get_header(self, get_schema_mock):
     """
     Test getting headers for report
     """
     get_schema_mock.return_value = self._sample_schema()
     result = AllVentures.get_header()
     self.assertEquals(
         result,
         ['Field1', 'Field2', 'Field3', 'Field4', 'Total cost']
     )
Esempio n. 7
0
 def test_prepare_field_value_not_in_venture_date(self):
     """
     Test if field is properly prepared for placing it in report. Value not
     in venture data and there is default rule.
     """
     venture_data = {}
     rules = {
         'currency': True,
         'total_cost': True,
     }
     result = AllVentures._prepare_field('field1', rules, venture_data)
     self.assertEquals(result, ('0.00 PLN', D('0')))
Esempio n. 8
0
 def test_prepare_field_value_in_venture_data(self):
     """
     Test if field is properly prepared for placing it in report. Value
     in venture data.
     """
     venture_data = {
         'field1': '1234',
     }
     rules = {
         'currency': False
     }
     result = AllVentures._prepare_field('field1', rules, venture_data)
     self.assertEquals(result, ('1234', D('0')))
Esempio n. 9
0
 def test_prepare_field_value_in_venture_data_currency(self):
     """
     Test if field is properly prepared for placing it in report. Value
     in venture data.
     """
     venture_data = {
         'field1': 1234,
     }
     rules = {
         'currency': True,
         'total_cost': True,
     }
     result = AllVentures._prepare_field('field1', rules, venture_data)
     self.assertEquals(result, ('1234.00 PLN', D('1234')))
Esempio n. 10
0
 def test_prepare_field_value_basestring(self):
     """
     Test if field is properly prepared for placing it in report. Value is
     string.
     """
     venture_data = {
         'field1': '123'
     }
     rules = {
         'currency': True,
         'total_cost': True,
     }
     result = AllVentures._prepare_field('field1', rules, venture_data)
     self.assertEquals(result, ('123', D('0')))
Esempio n. 11
0
 def test_prepare_row(self, get_schema_mock):
     """
     Test if whole row is properly prepared for placing it in report
     """
     venture_data = {
         'field1': 123,
         'field2': D('3'),
         'field3': 3123,
         'field4': 33
     }
     get_schema_mock.return_value = self._sample_schema()
     result = AllVentures._prepare_venture_row(venture_data)
     self.assertEquals(
         result,
         [123, '3.00 PLN', 3123, '33.00 PLN', '36.00 PLN']
     )
Esempio n. 12
0
 def test_get_as_currency_total_cost(self):
     """
     Test if total cost decimal is properly 'transformed' to currency
     """
     currency = AllVentures._get_as_currency(1234, True)
     self.assertEquals(currency, ('1234.00 PLN', D('1234')))
Esempio n. 13
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':
                    OrderedDict([
                        ('venture_id', {
                            'name': 'ID'
                        }),
                        ('venture', {
                            'name': 'Venture'
                        }),
                        ('department', {
                            'name': 'Department'
                        }),
                    ]),
                    'costs': {
                        1: {
                            'venture_id': 1,
                            'venture': 'b',
                            'department': 'aaaa',
                        },
                        3: {
                            'venture_id': 3,
                            'venture': 'a',
                            'department': 'bbbb',
                        }
                    },
                },
                'usage_plugin': {
                    'schema':
                    OrderedDict([('ut1_count', {
                        'name': 'UT1 count'
                    }),
                                 ('ut1_cost', {
                                     'name': 'UT1 cost',
                                     'currency': True,
                                     'total_cost': True,
                                 })]),
                    'costs': {
                        1: {
                            'ut1_count': 123,
                            'ut1_cost': D('23.23')
                        },
                    },
                },
                'ut3': {
                    'schema':
                    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': {
                        1: {
                            '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'),
                        },
                        3: {
                            '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'),
                        }
                    }
                },
                'service_plugin': {
                    'schema':
                    OrderedDict([('sut_3_count', {
                        'name': 'UT3 count'
                    }),
                                 ('sut_3_cost', {
                                     'name': 'UT3 cost wh 1',
                                     'currency': True,
                                 }), ('sut_4_count', {
                                     'name': 'UT4 count'
                                 }),
                                 ('sut_4_cost', {
                                     'name': 'UT4 cost',
                                     'currency': True
                                 }),
                                 ('1_service_cost', {
                                     'name': 'Service1 cost',
                                     'currency': True,
                                     'total_cost': True,
                                 })]),
                    'costs': {
                        1: {
                            'sut_4_count': 40.0,
                            'sut_4_cost': D('2212.11'),
                            '1_service_cost': D('2212.11'),
                        },
                        3: {
                            'sut_3_count': 10.0,
                            'sut_3_cost': D('20.22'),
                            'sut_4_count': 20.0,
                            'sut_4_cost': D('1212.11'),
                            '1_service_cost': D('1232.33'),
                        },
                    }
                }
            }
            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 AllVentures.get_data(
                self.report_start,
                self.report_end,
                is_active=True,
        ):
            pass
        self.assertEquals(
            result,
            [
                [
                    3,  # venture_id
                    'a',  # venture_name
                    'bbbb',  # department
                    # 1,  # asset_count
                    # '23.00 PLN',  # asset_cost
                    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
                    10.0,  # sut_3_count
                    '20.22',  # sut_3_cost,
                    20.0,  # sut_4_count
                    '1212.11',  # sut_4_count
                    '1232.33',  # 1_sercive_cost
                    '5996.54',  # total_cost
                ],
                [
                    1,  # venture_id
                    'b',  # venture_name
                    'aaaa',  # department
                    # 12,  # asset_count
                    # '213.00 PLN',  # asset_cost
                    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
                    0.0,  # sut_3_count
                    '0.00',  # sut_3_cost,
                    40.0,  # sut_4_count
                    '2212.11',  # sut_4_count
                    '2212.11',  # 1_sercive_cost
                    '2792.76',  # total_cost
                ]
            ])
Esempio n. 14
0
     kwargs={'team': None, 'daterange': None},
 ),
 url(
     r'^teams/(?P<team>[^/]+)/$',
     login_required(Teams.as_view()),
     name='teams',
     kwargs={'daterange': None},
 ),
 url(
     r'^teams/(?P<team>[^/]+)/(?P<daterange>[^/]+)/$',
     login_required(TeamsPercent.as_view()),
     name='teams',
 ),
 url(
     r'^all-ventures/$',
     login_required(AllVentures.as_view()),
     name='all_ventures',
 ),
 url(
     r'^ventures-daily-usages-report/$',
     login_required(VenturesDailyUsages.as_view()),
     name='ventures_daily_usages',
 ),
 url(
     r'^ventures-changes/$',
     login_required(VenturesChanges.as_view()),
     name='ventures_changes',
 ),
 url(
     r'^devices/$',
     login_required(Devices.as_view()),
Esempio n. 15
0
 def test_ventures_all(self):
     day = datetime.date(2013, 4, 25)
     venture = models.Venture(venture_id=3, name='a')
     venture.save()
     device = models.Device(
         device_id=3,
         asset_id=5,
     )
     device.save()
     daily = models.DailyDevice(
         pricing_device=device,
         date=day,
         name='ziew',
         price='1337',
         pricing_venture=venture,
     )
     daily.save()
     subventure = models.Venture(venture_id=2, parent=venture, name='b')
     subventure.save()
     other_device = models.Device(
         device_id=2,
         asset_id=3,
     )
     other_device.save()
     other_daily = models.DailyDevice(
         pricing_device=other_device,
         date=day,
         name='ziew',
         price='833833',
         pricing_venture=subventure,
     )
     other_daily.save()
     usage_type = models.UsageType(name='waciki')
     usage_type.save()
     daily_usage = models.DailyUsage(
         type=usage_type,
         value=32,
         date=day,
         pricing_venture=venture,
     )
     daily_usage.save()
     extra_cost_type = models.ExtraCostType(name='waciki')
     extra_cost_type.save()
     extra_cost = models.ExtraCost(
         pricing_venture=venture,
         start=day,
         end=day,
         type=extra_cost_type,
         price='65535',
     )
     extra_cost.save()
     view = TopVentures()
     for progress, data in view.get_data(day, day, show_in_ralph=True):
         pass
     self.assertEquals(
         data,
         [
             [
                 3,                 # id
                 'a',               # path
                 True,              # show_in_ralph
                 '',                # department
                 '',                # business segment
                 '',                # Profit center
                 2.0,               # assets count
                 '835 170.00 PLN',  # assets price
                 '0.00 PLN',        # assets cost
                 32.0,              # usage count
                 '0.00 PLN',        # usage price
                 '65 535.00 PLN',   # extra cost
             ],
         ],
     )
     view = AllVentures()
     for progress, data in view.get_data(day, day, show_in_ralph=True):
         pass
     self.assertEquals(
         data,
         [
             [
                 3,
                 'a',
                 True,  # show_in_ralph
                 '',
                 '',
                 '',
                 1.0,
                 '1 337.00 PLN',
                 '0.00 PLN',
                 32.0,
                 'NO PRICE',
                 '65 535.00 PLN',
             ],
             [
                 2,
                 'a/b',
                 True,  # show_in_ralph
                 '',
                 '',
                 '',
                 1.0,
                 '833 833.00 PLN',
                 '0.00 PLN',
                 0,
                 '0.00 PLN',
                 '0.00 PLN',
             ],
         ],
     )
Esempio n. 16
0
     name='extra_costs',
 ),
 url(
     r'^usages/$',
     login_required(Usages.as_view()),
     name='usages',
     kwargs={'usage': None},
 ),
 url(
     r'^usages/(?P<usage>[^/]+)/$',
     login_required(Usages.as_view()),
     name='usages',
 ),
 url(
     r'^all-ventures/$',
     login_required(AllVentures.as_view()),
     name='all_ventures',
 ),
 url(
     r'^top-ventures/$',
     login_required(TopVentures.as_view()),
     name='top_ventures',
 ),
 url(
     r'^devices/$',
     login_required(Devices.as_view()),
     name='devices',
 ),
 url(
     r'^devices/(?P<venture>\d+)/$',
     login_required(Devices.as_view()),
Esempio n. 17
0
 def test_get_as_currency(self):
     """
     Test if decimal is properly 'transformed' to currency
     """
     currency = AllVentures._get_as_currency('1234', False)
     self.assertEquals(currency, ('1234.00 PLN', D('0')))
Esempio n. 18
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': OrderedDict([
                        ('venture_id', {'name': 'ID'}),
                        ('venture', {'name': 'Venture'}),
                        ('department', {'name': 'Department'}),
                    ]),
                    'usages': {
                        1: {
                            'venture_id': 1,
                            'venture': 'b',
                            'department': 'aaaa',
                        },
                        3: {
                            'venture_id': 3,
                            'venture': 'a',
                            'department': 'bbbb',
                        }
                    },
                },
                'usage_plugin': {
                    'schema': OrderedDict([
                        ('ut1_count', {'name': 'UT1 count'}),
                        ('ut1_cost', {
                            'name': 'UT1 cost',
                            'currency': True,
                            'total_cost': True,
                        })
                    ]),
                    'usages': {
                        1: {'ut1_count': 123, 'ut1_cost': D('23.23')},
                    },
                },
                'ut3': {
                    'schema': 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,
                        })
                    ]),
                    'usages': {
                        1: {
                            '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'),
                        },
                        3: {
                            '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'),
                        }
                    }
                },
                'service_plugin': {
                    'schema': OrderedDict([
                        ('sut_3_count', {'name': 'UT3 count'}),
                        ('sut_3_cost', {
                            'name': 'UT3 cost wh 1',
                            'currency': True,
                        }),
                        ('sut_4_count', {'name': 'UT4 count'}),

                        ('sut_4_cost', {
                            'name': 'UT4 cost',
                            'currency': True
                        }),
                        ('1_service_cost', {
                            'name': 'Service1 cost',
                            'currency': True,
                            'total_cost': True,
                        })
                    ]),
                    'usages': {
                        1: {
                            'sut_4_count': 40.0,
                            'sut_4_cost': D('2212.11'),
                            '1_service_cost': D('2212.11'),
                        },
                        3: {
                            'sut_3_count': 10.0,
                            'sut_3_cost': D('20.22'),
                            'sut_4_count': 20.0,
                            'sut_4_cost': D('1212.11'),
                            '1_service_cost': D('1232.33'),
                        },
                    }
                }
            }
            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 AllVentures.get_data(
            self.report_start,
            self.report_end,
            is_active=True,
        ):
            pass
        self.assertEquals(result, [
            [
                3,  # venture_id
                'a',  # venture_name
                'bbbb',  # department
                # 1,  # asset_count
                # '23.00 PLN',  # asset_cost
                267,  # ut3_count_warehouse_1
                36774,  # ut3_cost_warehouse_1
                '4764.21 PLN',  # ut3_count_warehouse_2
                'Incomplete price',  # ut3_cost_warehouse_2
                '4764.21 PLN',  # ut3_cost_total
                0.0,  # ut1_count
                '0.00 PLN',  # ut1_cost
                10.0,  # sut_3_count
                '20.22 PLN',  # sut_3_cost,
                20.0,  # sut_4_count
                '1212.11 PLN',  # sut_4_count
                '1232.33 PLN',  # 1_sercive_cost
                '5996.54 PLN',  # total_cost
            ],
            [
                1,  # venture_id
                'b',  # venture_name
                'aaaa',  # department
                # 12,  # asset_count
                # '213.00 PLN',  # asset_cost
                213,  # ut3_count_warehouse_1
                3234,  # ut3_cost_warehouse_1
                '434.21 PLN',  # ut3_count_warehouse_2
                '123.21 PLN',  # ut3_cost_warehouse_2
                '557.42 PLN',  # ut3_cost_total
                123,  # ut1_count
                '23.23 PLN',  # ut1_cost
                0.0,  # sut_3_count
                '0.00 PLN',  # sut_3_cost,
                40.0,  # sut_4_count
                '2212.11 PLN',  # sut_4_count
                '2212.11 PLN',  # 1_sercive_cost
                '2792.76 PLN',  # total_cost
            ]
        ])