示例#1
0
 def test_next_month(self):
     """Test the next_month method."""
     current_month = timezone.now().replace(microsecond=0,
                                            second=0,
                                            minute=0,
                                            hour=0,
                                            day=1)
     last_month = current_month.replace(month=(current_month.month - 1))
     self.assertEqual(current_month,
                      ReportQueryHandler.next_month(last_month))
示例#2
0
 def add_data_to_tenant(self):
     """Populate tenant with data."""
     payer_account_id = self.fake.ean(length=13)  # pylint: disable=no-member
     self.payer_account_id = payer_account_id
     one_day = datetime.timedelta(days=1)
     one_hour = datetime.timedelta(minutes=60)
     this_hour = timezone.now().replace(microsecond=0, second=0, minute=0)
     yesterday = this_hour - one_day
     bill_start = this_hour.replace(microsecond=0,
                                    second=0,
                                    minute=0,
                                    hour=0,
                                    day=1)
     bill_end = ReportQueryHandler.next_month(bill_start)
     with tenant_context(self.tenant):
         bill = AWSCostEntryBill(bill_type='Anniversary',
                                 payer_account_id=payer_account_id,
                                 billing_period_start=bill_start,
                                 billing_period_end=bill_end)
         bill.save()
         rate = 0.199
         amount = 1
         cost = rate * amount
         # pylint: disable=no-member
         sku = self.fake.pystr(min_chars=12, max_chars=12).upper()
         prod_ec2 = 'Amazon Elastic Compute Cloud'
         ce_product = AWSCostEntryProduct(sku=sku,
                                          product_name=prod_ec2,
                                          product_family='Compute Instance',
                                          service_code='AmazonEC2',
                                          region='US East (N. Virginia)',
                                          instance_type='c4.xlarge',
                                          memory=7.5,
                                          vcpu=4)
         ce_product.save()
         ce_pricing = AWSCostEntryPricing(public_on_demand_cost=rate * 1,
                                          public_on_demand_rate=rate,
                                          term='OnDemand',
                                          unit='Hrs')
         ce_pricing.save()
         current = yesterday
         while current < this_hour:
             end_hour = current + one_hour
             self.create_hourly_instance_usage(payer_account_id, bill,
                                               ce_pricing, ce_product, rate,
                                               cost, current, end_hour)
             current = end_hour
示例#3
0
 def test_get_time_frame_filter_current_month(self):
     """Test _get_time_frame_filter for current month."""
     query_params = {
         'filter': {
             'resolution': 'daily',
             'time_scope_value': -1,
             'time_scope_units': 'month'
         }
     }
     handler = ReportQueryHandler(query_params, '', self.tenant,
                                  'unblended_cost', 'currency_code')
     current_month = timezone.now().replace(microsecond=0,
                                            second=0,
                                            minute=0,
                                            hour=0,
                                            day=1)
     next_month = ReportQueryHandler.next_month(current_month)
     start = handler.start_datetime
     end = handler.end_datetime
     interval = handler.time_interval
     self.assertEqual(start, current_month)
     self.assertEqual(end, next_month)
     self.assertIsInstance(interval, list)
     self.assertTrue(len(interval) >= 28)