Ejemplo n.º 1
0
    def setUp(self):
        """Set up each test."""
        super().setUp()

        billing_start = self.date_accessor.today_with_timezone('UTC').replace(
            day=1)
        self.manifest_dict = {
            'assembly_id': '1234',
            'billing_period_start_datetime': billing_start,
            'num_total_files': 1,
            'provider_uuid': self.azure_provider_uuid,
        }

        self.provider_accessor = ProviderDBAccessor(
            provider_uuid=self.azure_test_provider_uuid)
        provider_uuid = self.provider_accessor.get_provider().uuid

        self.updater = AzureReportChargeUpdater(schema=self.schema,
                                                provider_uuid=provider_uuid)

        today = DateAccessor().today_with_timezone('UTC')
        bill = self.creator.create_azure_cost_entry_bill(
            provider_uuid=provider_uuid, bill_date=today)
        product = self.creator.create_azure_cost_entry_product(
            provider_uuid=provider_uuid)
        meter = self.creator.create_azure_meter(provider_uuid=provider_uuid)
        self.creator.create_azure_cost_entry_line_item(bill, product, meter)

        self.manifest = self.manifest_accessor.add(**self.manifest_dict)
        self.manifest_accessor.commit()

        with ProviderDBAccessor(
                self.azure_test_provider_uuid) as provider_accessor:
            self.provider = provider_accessor.get_provider()
    def setUp(self):
        """Set up each test."""
        super().setUp()

        billing_start = self.date_accessor.today_with_timezone("UTC").replace(
            day=1)
        self.manifest_dict = {
            "assembly_id": "1234",
            "billing_period_start_datetime": billing_start,
            "num_total_files": 1,
            "provider_uuid": self.azure_provider_uuid,
        }

        with ProviderDBAccessor(
                self.azure_test_provider_uuid) as provider_accessor:
            self.provider = provider_accessor.get_provider()

        self.updater = AzureReportChargeUpdater(schema=self.schema,
                                                provider=self.provider)

        today = DateAccessor().today_with_timezone("UTC")
        bill = self.creator.create_azure_cost_entry_bill(
            provider_uuid=self.provider.uuid, bill_date=today)
        product = self.creator.create_azure_cost_entry_product(
            provider_uuid=self.provider.uuid)
        meter = self.creator.create_azure_meter(
            provider_uuid=self.provider.uuid)
        self.creator.create_azure_cost_entry_line_item(bill, product, meter)

        self.manifest = self.manifest_accessor.add(**self.manifest_dict)
Ejemplo n.º 3
0
    def _set_updater(self):
        """
        Create the report charge updater object.

        Object is specific to the report provider.

        Args:
            None

        Returns:
            (Object) : Provider-specific report summary updater

        """
        if self._provider in (AMAZON_WEB_SERVICES, AWS_LOCAL_SERVICE_PROVIDER):
            return AWSReportChargeUpdater(self._schema, self._provider_uuid)
        if self._provider in (AZURE, AZURE_LOCAL_SERVICE_PROVIDER):
            return AzureReportChargeUpdater(self._schema, self._provider_uuid)
        if self._provider in (OPENSHIFT_CONTAINER_PLATFORM, ):
            return OCPReportChargeUpdater(self._schema, self._provider_uuid)

        return None
Ejemplo n.º 4
0
    def _set_updater(self):
        """
        Create the report charge updater object.

        Object is specific to the report provider.

        Args:
            None

        Returns:
            (Object) : Provider-specific report summary updater

        """
        if self._provider.type in (Provider.PROVIDER_AWS,
                                   Provider.PROVIDER_AWS_LOCAL):
            return AWSReportChargeUpdater(self._schema, self._provider)
        if self._provider.type in (Provider.PROVIDER_AZURE,
                                   Provider.PROVIDER_AZURE_LOCAL):
            return AzureReportChargeUpdater(self._schema, self._provider)
        if self._provider.type in (Provider.PROVIDER_OCP, ):
            return OCPReportChargeUpdater(self._schema, self._provider)

        return None
class AzureReportChargeUpdaterTest(MasuTestCase):
    """Test Cases for the AzureReportChargeUpdater object."""
    @classmethod
    def setUpClass(cls):
        """Set up the test class with required objects."""
        super().setUpClass()
        with ReportingCommonDBAccessor() as report_common_db:
            cls.column_map = report_common_db.column_map

        cls.accessor = AzureReportDBAccessor('acct10001', cls.column_map)

        cls.report_schema = cls.accessor.report_schema

        cls.all_tables = list(AZURE_REPORT_TABLE_MAP.values())

        cls.creator = ReportObjectCreator(cls.schema, cls.column_map)

        cls.date_accessor = DateAccessor()
        cls.manifest_accessor = ReportManifestDBAccessor()

    def setUp(self):
        """Set up each test."""
        super().setUp()

        billing_start = self.date_accessor.today_with_timezone('UTC').replace(
            day=1)
        self.manifest_dict = {
            'assembly_id': '1234',
            'billing_period_start_datetime': billing_start,
            'num_total_files': 1,
            'provider_id': self.azure_provider.id,
        }

        self.provider_accessor = ProviderDBAccessor(
            provider_uuid=self.azure_test_provider_uuid)
        provider_id = self.provider_accessor.get_provider().id

        self.updater = AzureReportChargeUpdater(
            schema=self.schema,
            provider_uuid=self.azure_test_provider_uuid,
            provider_id=provider_id)

        today = DateAccessor().today_with_timezone('UTC')
        bill = self.creator.create_azure_cost_entry_bill(
            provider_id=provider_id, bill_date=today)
        product = self.creator.create_azure_cost_entry_product()
        meter = self.creator.create_azure_meter()
        service = self.creator.create_azure_service()
        self.creator.create_azure_cost_entry_line_item(bill, product, meter,
                                                       service)

        self.manifest = self.manifest_accessor.add(**self.manifest_dict)
        self.manifest_accessor.commit()

        with ProviderDBAccessor(
                self.azure_test_provider_uuid) as provider_accessor:
            self.provider = provider_accessor.get_provider()

    def test_azure_update_summary_charge_info(self):
        """Test to verify Azure derived cost summary is calculated."""
        start_date = self.date_accessor.today_with_timezone('UTC')
        bill_date = start_date.replace(day=1).date()

        self.updater.update_summary_charge_info()

        with AzureReportDBAccessor(self.schema, self.column_map) as accessor:
            bill = accessor.get_cost_entry_bills_by_date(bill_date)[0]
            self.assertIsNotNone(bill.derived_cost_datetime)