Ejemplo n.º 1
0
    def setUp(self):
        self.components = ComponentsContent()
        self.se1 = ServiceEnvironmentFactory()
        self.se2 = ServiceEnvironmentFactory(service=self.se1.service, )
        self.se3 = ServiceEnvironmentFactory()
        self.today = datetime.date(2014, 10, 11)
        self.tomorrow = datetime.date(2014, 10, 12)
        self.today_accepted = CostDateStatusFactory(date=self.today,
                                                    accepted=True)

        self.ut1 = UsageTypeFactory()
        self.ut2 = PricingServiceFactory()

        self.dpo1, self.dpo2 = DailyAssetInfoFactory.create_batch(
            2,
            service_environment=self.se1,
            pricing_object__service_environment=self.se1,
            date=self.today,
        )
        self.dpo3 = DailyAssetInfoFactory(
            service_environment=self.se2,
            pricing_object__service_environment=self.se2,
            date=self.today,
        )
        self.dpo3 = DailyAssetInfoFactory(
            service_environment=self.se3,
            pricing_object__service_environment=self.se3,
            date=self.today,
        )
        self.dpo4 = DailyAssetInfoFactory(
            service_environment=self.se1,
            pricing_object__service_environment=self.se1,
            date=self.tomorrow,
        )
        self.dc1 = DailyCostFactory(
            type=self.ut1,
            pricing_object=self.dpo1.pricing_object,
            service_environment=self.se1,
            date=self.today,
            value=10,
            cost=20,
        )
        self.dc2 = DailyCostFactory(
            type=self.ut1,
            pricing_object=self.dpo1.pricing_object,
            service_environment=self.se1,
            date=self.today,
            value=20,
            cost=30,
        )
        self.dc3 = DailyCostFactory(
            type=self.ut2,
            pricing_object=self.dpo1.pricing_object,
            service_environment=self.se1,
            date=self.today,
            value=25,
            cost=35,
        )
        self.maxDiff = None
Ejemplo n.º 2
0
 def test_virtual(self):
     service_environment = ServiceEnvironmentFactory.create()
     asset_info = AssetInfoFactory.create(device_id=1)
     DailyAssetInfoFactory.create(asset_info=asset_info, date=self.today)
     virtual.ServiceEnvironment.objects.get = (
         lambda *args, **kwargs: service_environment)
     self.assertEqual(
         virtual.virtual(today=self.today),
         (True, 'Virtual: None new, 1 updated, 1 total'),
     )
Ejemplo n.º 3
0
 def test_share(self):
     DailyAssetInfoFactory.create(
         pricing_object=self.asset_info,
         asset_info=self.asset_info,
         date=self.date,
     )
     share.get_shares = lambda service_uid, include_virtual: [self.data]
     self.assertEqual(
         share.share(today=self.date),
         (True, 'None new, 1 updated, 1 total'),
     )
Ejemplo n.º 4
0
 def test_share(self):
     DailyAssetInfoFactory.create(
         pricing_object=self.asset_info,
         asset_info=self.asset_info,
         date=self.date,
     )
     share.get_shares = lambda service_uid, include_virtual: [self.data]
     self.assertEqual(
         share.share(today=self.date),
         (True, 'None new, 1 updated, 1 total'),
     )
Ejemplo n.º 5
0
 def test_virtual(self):
     service_environment = ServiceEnvironmentFactory.create()
     asset_info = AssetInfoFactory.create(device_id=1)
     DailyAssetInfoFactory.create(asset_info=asset_info, date=self.today)
     virtual.ServiceEnvironment.objects.get = (
         lambda *args, **kwargs: service_environment
     )
     self.assertEqual(
         virtual.virtual(today=self.today),
         (True, 'Virtual: None new, 1 updated, 1 total'),
     )
Ejemplo n.º 6
0
 def setUp(self):
     self.today = date(2014, 10, 12)
     self.daily_asset1 = DailyAssetInfoFactory()
     self.daily_asset2 = DailyAssetInfoFactory()
     self.daily_asset3 = DailyAssetInfoFactory.build()
     self.data = {
         'support_id': 1,
         'assets': [
             self.daily_asset1.asset_info.asset_id,
         ],
         'date_from': date(2014, 10, 1),
         'date_to': date(2014, 10, 30),
         'price': 30,
         'name': 'support1',
     }
Ejemplo n.º 7
0
    def test_update_usage(self):
        daily_asset_info = DailyAssetInfoFactory(date=self.today)
        self.assertTrue(
            update_usage(
                daily_asset_info,
                self.today,
                1,
                self.blade_server_usage_type,
            ))
        self.assertEquals(self.blade_server_usage_type.dailyusage_set.count(),
                          1)
        daily_usage = self.blade_server_usage_type.dailyusage_set.all()[0]
        self.assertEquals(daily_usage.date, self.today)
        self.assertEquals(daily_usage.service_environment,
                          daily_asset_info.service_environment)
        self.assertEquals(daily_usage.type, self.blade_server_usage_type)
        self.assertEquals(daily_usage.value, 1)

        # update
        self.assertFalse(
            update_usage(
                daily_asset_info,
                self.today,
                2,
                self.blade_server_usage_type,
            ))
        self.assertEquals(self.blade_server_usage_type.dailyusage_set.count(),
                          1)
        daily_usage = self.blade_server_usage_type.dailyusage_set.all()[0]
        self.assertEquals(daily_usage.value, 2)
Ejemplo n.º 8
0
    def setUp(self):
        self.components = ComponentsContent()
        self.se1 = ServiceEnvironmentFactory()
        self.se2 = ServiceEnvironmentFactory(
            service=self.se1.service,
        )
        self.se3 = ServiceEnvironmentFactory()
        self.today = datetime.date(2014, 10, 11)

        self.dpo1, self.dpo2 = DailyAssetInfoFactory.create_batch(
            2,
            service_environment=self.se1,
            pricing_object__service_environment=self.se1,
            date=self.today,
        )
        self.dpo3 = DailyAssetInfoFactory(
            service_environment=self.se2,
            pricing_object__service_environment=self.se2,
            date=self.today,
        )
        self.dpo3 = DailyAssetInfoFactory(
            service_environment=self.se3,
            pricing_object__service_environment=self.se3,
            date=self.today,
        )
        self.maxDiff = None
Ejemplo n.º 9
0
 def test_update_virtual_virtual_info_with_hypervisor(self):
     service_env = ServiceEnvironmentFactory.create()
     hypervisor = DailyAssetInfoFactory(date=self.today)
     data = AttributeDict(
         device_id=1,
         name='sample',
         service_id=service_env.service.ci_id,
         environment_id=service_env.environment.ci_id,
         model_id=1,
         hypervisor_id=hypervisor.asset_info.device_id,
         model_name='sample model',
     )
     daily_virtual_info = virtual.update_virtual_info(
         'virtual_group',
         data,
         self.today,
         service_env,
     )
     self._compare_daily_virtual_info(
         daily_virtual_info,
         data,
         service_env,
         'virtual_group',
     )
     self.assertEqual(hypervisor.asset_info.device_id,
                      daily_virtual_info.hypervisor.asset_info.device_id)
Ejemplo n.º 10
0
 def test_update_blade_server_no_asset_info(self):
     daily_asset_info = DailyAssetInfoFactory.build(date=self.today)
     with self.assertRaises(AssetInfoNotFoundError):
         update_blade_server(
             {'id': 1, 'device_id': daily_asset_info.asset_info.device_id},
             self.today,
             self.blade_server_usage_type
         )
Ejemplo n.º 11
0
 def test_update_blade_server_no_asset_info(self):
     daily_asset_info = DailyAssetInfoFactory.build(date=self.today)
     with self.assertRaises(AssetInfoNotFoundError):
         update_blade_server(
             {
                 'id': 1,
                 'device_id': daily_asset_info.asset_info.device_id
             }, self.today, self.blade_server_usage_type)
Ejemplo n.º 12
0
 def test_update_blade_server_no_daily_asset_info(self):
     daily_asset_info = DailyAssetInfoFactory(date=self.today)
     with self.assertRaises(DailyAssetInfoNotFoundError):
         update_blade_server(
             {
                 'id': 1,
                 'device_id': daily_asset_info.asset_info.device_id
             }, self.today + datetime.timedelta(days=1),
             self.blade_server_usage_type)
 def _create_asset_info(self):
     self.ai = AssetInfoFactory(
         service_environment=self.se1,
         barcode='123',
         sn='987654321',
     )
     self.dai1 = DailyAssetInfoFactory(
         service_environment=self.se1,
         pricing_object=self.ai,
         asset_info=self.ai,
         date=self.today,
     )
     self.dai2 = DailyAssetInfoFactory(
         service_environment=self.se2,
         pricing_object=self.ai,
         asset_info=self.ai,
         date=self.yesterday,
     )
Ejemplo n.º 14
0
 def test_update_usage(self):
     DailyAssetInfoFactory.create(
         pricing_object=self.asset_info,
         asset_info=self.asset_info,
         date=self.date,
     )
     share.update_usage(
         self.asset_info,
         self.usage_type,
         self.data,
         self.date,
     )
     self.assertEqual(DailyUsage.objects.count(), 1)
     daily_usage = DailyUsage.objects.get()
     self.assertEqual(daily_usage.value, self.data['size'])
     self.assertEqual(daily_usage.type, self.usage_type)
     self.assertEqual(daily_usage.service_environment,
                      self.asset_info.service_environment)
Ejemplo n.º 15
0
 def test_update_usage(self):
     asset.update_usage(
         DailyAssetInfoFactory(),
         self.warehouse,
         UsageTypeFactory(),
         self.value,
         self.date,
     )
     self.assertEqual(DailyUsage.objects.all().count(), 1)
Ejemplo n.º 16
0
 def test_update_usage(self):
     DailyAssetInfoFactory.create(
         pricing_object=self.asset_info,
         asset_info=self.asset_info,
         date=self.date,
     )
     share.update_usage(
         self.asset_info,
         self.usage_type,
         self.data,
         self.date,
     )
     self.assertEqual(DailyUsage.objects.count(), 1)
     daily_usage = DailyUsage.objects.get()
     self.assertEqual(daily_usage.value, self.data['size'])
     self.assertEqual(daily_usage.type, self.usage_type)
     self.assertEqual(
         daily_usage.service_environment,
         self.asset_info.service_environment
     )
Ejemplo n.º 17
0
 def setUp(self):
     self.today = date(2014, 10, 12)
     self.daily_asset1 = DailyAssetInfoFactory()
     self.daily_asset2 = DailyAssetInfoFactory()
     self.daily_asset3 = DailyAssetInfoFactory.build()
     self.data = {
         'support_id': 1,
         'assets': [
             self.daily_asset1.asset_info.asset_id,
         ],
         'date_from': date(2014, 10, 1),
         'date_to': date(2014, 10, 30),
         'price': 30,
         'name': 'support1',
     }
Ejemplo n.º 18
0
    def setUp(self):
        self.components = ComponentsContent()
        self.se1 = ServiceEnvironmentFactory()
        self.se2 = ServiceEnvironmentFactory(service=self.se1.service, )
        self.se3 = ServiceEnvironmentFactory()
        self.today = datetime.date(2014, 10, 11)

        self.dpo1, self.dpo2 = DailyAssetInfoFactory.create_batch(
            2,
            service_environment=self.se1,
            pricing_object__service_environment=self.se1,
            date=self.today,
        )
        self.dpo3 = DailyAssetInfoFactory(
            service_environment=self.se2,
            pricing_object__service_environment=self.se2,
            date=self.today,
        )
        self.dpo3 = DailyAssetInfoFactory(
            service_environment=self.se3,
            pricing_object__service_environment=self.se3,
            date=self.today,
        )
        self.maxDiff = None
Ejemplo n.º 19
0
 def test_update_blade_server(self, update_usage_mock):
     update_usage_mock.return_value = True
     daily_asset_info = DailyAssetInfoFactory(date=self.today)
     self.assertTrue(
         update_blade_server(
             {
                 'id': 1,
                 'device_id': daily_asset_info.asset_info.device_id
             }, self.today, self.blade_server_usage_type))
     update_usage_mock.assert_called_with(
         daily_asset_info,
         self.today,
         1,
         self.blade_server_usage_type,
     )
Ejemplo n.º 20
0
    def setUp(self):
        self.components = ComponentsContent()
        self.se1 = ServiceEnvironmentFactory()
        self.se2 = ServiceEnvironmentFactory(
            service=self.se1.service,
        )
        self.se3 = ServiceEnvironmentFactory()
        self.today = datetime.date(2014, 10, 11)
        self.tomorrow = datetime.date(2014, 10, 12)
        self.today_accepted = CostDateStatusFactory(
            date=self.today,
            accepted=True
        )

        self.ut1 = UsageTypeFactory()
        self.ut2 = PricingServiceFactory()

        self.dpo1, self.dpo2 = DailyAssetInfoFactory.create_batch(
            2,
            service_environment=self.se1,
            pricing_object__service_environment=self.se1,
            date=self.today,
        )
        self.dpo3 = DailyAssetInfoFactory(
            service_environment=self.se2,
            pricing_object__service_environment=self.se2,
            date=self.today,
        )
        self.dpo3 = DailyAssetInfoFactory(
            service_environment=self.se3,
            pricing_object__service_environment=self.se3,
            date=self.today,
        )
        self.dpo4 = DailyAssetInfoFactory(
            service_environment=self.se1,
            pricing_object__service_environment=self.se1,
            date=self.tomorrow,
        )
        self.dc1 = DailyCostFactory(
            type=self.ut1,
            pricing_object=self.dpo1.pricing_object,
            service_environment=self.se1,
            date=self.today,
            value=10,
            cost=20,
        )
        self.dc2 = DailyCostFactory(
            type=self.ut1,
            pricing_object=self.dpo1.pricing_object,
            service_environment=self.se1,
            date=self.today,
            value=20,
            cost=30,
        )
        self.dc3 = DailyCostFactory(
            type=self.ut2,
            pricing_object=self.dpo1.pricing_object,
            service_environment=self.se1,
            date=self.today,
            value=25,
            cost=35,
        )
        self.maxDiff = None