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': 2, 'provider_uuid': self.aws_provider_uuid, } with ProviderDBAccessor(self.aws_provider_uuid) as provider_accessor: self.provider = provider_accessor.get_provider() self.updater = AWSReportChargeUpdater( schema=self.schema, provider=self.provider, ) today = DateAccessor().today_with_timezone('UTC') bill = self.creator.create_cost_entry_bill(provider_uuid=self.provider.uuid, bill_date=today) cost_entry = self.creator.create_cost_entry(bill, today) product = self.creator.create_cost_entry_product() pricing = self.creator.create_cost_entry_pricing() reservation = self.creator.create_cost_entry_reservation() self.creator.create_cost_entry_line_item( bill, cost_entry, product, pricing, reservation ) self.manifest = self.manifest_accessor.add(**self.manifest_dict)
def setUp(self): """Set up each test.""" super().setUp() if self.accessor._conn.closed: self.accessor._conn = self.accessor._db.connect() if self.accessor._pg2_conn.closed: self.accessor._pg2_conn = self.accessor._get_psycopg2_connection() if self.accessor._cursor.closed: self.accessor._cursor = self.accessor._get_psycopg2_cursor() self.provider_accessor = ProviderDBAccessor( provider_uuid=self.aws_test_provider_uuid) provider_id = self.provider_accessor.get_provider().id self.provider_accessor = ProviderDBAccessor( provider_uuid=self.aws_test_provider_uuid) self.updater = AWSReportChargeUpdater( schema=self.test_schema, provider_uuid=self.aws_test_provider_uuid, provider_id=provider_id, ) today = DateAccessor().today_with_timezone('UTC') bill = self.creator.create_cost_entry_bill(today) cost_entry = self.creator.create_cost_entry(bill, today) product = self.creator.create_cost_entry_product() pricing = self.creator.create_cost_entry_pricing() reservation = self.creator.create_cost_entry_reservation() self.creator.create_cost_entry_line_item(bill, cost_entry, product, pricing, reservation) self.manifest = self.manifest_accessor.add(**self.manifest_dict) self.manifest_accessor.commit() with ProviderDBAccessor( self.aws_test_provider_uuid) as provider_accessor: self.provider = provider_accessor.get_provider()
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, self._provider_id) if self._provider in (OPENSHIFT_CONTAINER_PLATFORM, OCP_LOCAL_SERVICE_PROVIDER): return OCPReportChargeUpdater(self._schema, self._provider_uuid, self._provider_id) return None
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 AWSReportChargeUpdaterTest(MasuTestCase): """Test Cases for the AWSReportChargeUpdater 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 = AWSReportDBAccessor('acct10001', cls.column_map) cls.report_schema = cls.accessor.report_schema cls.all_tables = list(AWS_CUR_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': 2, 'provider_uuid': self.aws_provider_uuid, } with ProviderDBAccessor(self.aws_provider_uuid) as provider_accessor: self.provider = provider_accessor.get_provider() self.updater = AWSReportChargeUpdater( schema=self.schema, provider=self.provider, ) today = DateAccessor().today_with_timezone('UTC') bill = self.creator.create_cost_entry_bill(provider_uuid=self.provider.uuid, bill_date=today) cost_entry = self.creator.create_cost_entry(bill, today) product = self.creator.create_cost_entry_product() pricing = self.creator.create_cost_entry_pricing() reservation = self.creator.create_cost_entry_reservation() self.creator.create_cost_entry_line_item( bill, cost_entry, product, pricing, reservation ) self.manifest = self.manifest_accessor.add(**self.manifest_dict) @patch('masu.database.cost_model_db_accessor.CostModelDBAccessor.get_markup') def test_update_summary_charge_info(self, mock_markup): """Test to verify AWS derived cost summary is calculated.""" markup = {'value': 10, 'unit': 'percent'} mock_markup.return_value = markup start_date = self.date_accessor.today_with_timezone('UTC') bill_date = start_date.replace(day=1).date() self.updater.update_summary_charge_info() with AWSReportDBAccessor('acct10001', self.column_map) as accessor: bill = accessor.get_cost_entry_bills_by_date(bill_date)[0] self.assertIsNotNone(bill.derived_cost_datetime)
class AWSReportChargeUpdaterTest(MasuTestCase): """Test Cases for the AWSReportChargeUpdater 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 = AWSReportDBAccessor('acct10001', cls.column_map) cls.report_schema = cls.accessor.report_schema cls.session = cls.accessor._session cls.all_tables = list(AWS_CUR_TABLE_MAP.values()) cls.creator = ReportObjectCreator(cls.accessor, cls.column_map, cls.report_schema.column_types) cls.date_accessor = DateAccessor() billing_start = cls.date_accessor.today_with_timezone('UTC').replace( day=1) cls.manifest_dict = { 'assembly_id': '1234', 'billing_period_start_datetime': billing_start, 'num_total_files': 2, 'provider_id': 1, } cls.manifest_accessor = ReportManifestDBAccessor() @classmethod def tearDownClass(cls): """Tear down the test class.""" cls.manifest_accessor.close_session() cls.accessor.close_connections() cls.accessor.close_session() super().tearDownClass() def setUp(self): """Set up each test.""" super().setUp() if self.accessor._conn.closed: self.accessor._conn = self.accessor._db.connect() if self.accessor._pg2_conn.closed: self.accessor._pg2_conn = self.accessor._get_psycopg2_connection() if self.accessor._cursor.closed: self.accessor._cursor = self.accessor._get_psycopg2_cursor() self.provider_accessor = ProviderDBAccessor( provider_uuid=self.aws_test_provider_uuid) provider_id = self.provider_accessor.get_provider().id self.provider_accessor = ProviderDBAccessor( provider_uuid=self.aws_test_provider_uuid) self.updater = AWSReportChargeUpdater( schema=self.test_schema, provider_uuid=self.aws_test_provider_uuid, provider_id=provider_id, ) today = DateAccessor().today_with_timezone('UTC') bill = self.creator.create_cost_entry_bill(today) cost_entry = self.creator.create_cost_entry(bill, today) product = self.creator.create_cost_entry_product() pricing = self.creator.create_cost_entry_pricing() reservation = self.creator.create_cost_entry_reservation() self.creator.create_cost_entry_line_item(bill, cost_entry, product, pricing, reservation) self.manifest = self.manifest_accessor.add(**self.manifest_dict) self.manifest_accessor.commit() with ProviderDBAccessor( self.aws_test_provider_uuid) as provider_accessor: self.provider = provider_accessor.get_provider() def tearDown(self): """Return the database to a pre-test state.""" super().tearDown() # self.session.rollback() for table_name in self.all_tables: tables = self.accessor._get_db_obj_query(table_name).all() for table in tables: self.accessor._session.delete(table) self.accessor.commit() manifests = self.manifest_accessor._get_db_obj_query().all() for manifest in manifests: self.manifest_accessor.delete(manifest) self.manifest_accessor.commit() def test_update_summary_charge_info(self): """Test to verify AWS 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 AWSReportDBAccessor('acct10001', self.column_map) as accessor: bill = accessor.get_cost_entry_bills_by_date(bill_date)[0] self.assertIsNotNone(bill.derived_cost_datetime)