Beispiel #1
0
    def test_process_gzip(self):
        """Test the processing of a gzip compressed file."""
        counts = {}
        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report_gzip,
            compression=GZIP_COMPRESSED,
            provider_uuid=self.aws_provider_uuid,
        )
        report_db = self.accessor
        report_schema = report_db.report_schema
        for table_name in self.report_tables:
            table = getattr(report_schema, table_name)
            with schema_context(self.schema):
                count = table.objects.count()
            counts[table_name] = count

        processor.process()

        for table_name in self.report_tables:
            table = getattr(report_schema, table_name)
            with schema_context(self.schema):
                count = table.objects.count()

            if table_name in (
                'reporting_awscostentryreservation',
                'reporting_ocpawscostlineitem_daily_summary',
                'reporting_ocpawscostlineitem_project_daily_summary',
            ):
                self.assertTrue(count >= counts[table_name])
            else:
                self.assertTrue(count > counts[table_name])
Beispiel #2
0
    def setUp(self):
        """Set up shared variables."""
        super().setUp()

        self.temp_dir = tempfile.mkdtemp()
        self.test_report = f'{self.temp_dir}/test_cur.csv'
        self.test_report_gzip = f'{self.temp_dir}/test_cur.csv.gz'

        shutil.copy2(self.test_report_test_path, self.test_report)
        shutil.copy2(self.test_report_gzip_test_path, self.test_report_gzip)

        self.processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
        )

        billing_start = self.date_accessor.today_with_timezone('UTC').replace(
            year=2018, month=6, day=1, hour=0, minute=0, second=0
        )
        self.assembly_id = '1234'
        self.manifest_dict = {
            'assembly_id': self.assembly_id,
            'billing_period_start_datetime': billing_start,
            'num_total_files': 2,
            'provider_uuid': self.aws_provider_uuid,
        }

        self.accessor = AWSReportDBAccessor(self.schema, self.column_map)
        self.report_schema = self.accessor.report_schema
        self.manifest = self.manifest_accessor.add(**self.manifest_dict)
Beispiel #3
0
    def test_process_no_file_on_disk(self):
        """Test the processing of when the file is not found on disk."""
        counts = {}
        base_name = "test_no_cur.csv"
        no_report = f"{self.temp_dir}/{base_name}"
        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=no_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
            manifest_id=self.manifest.id,
        )
        report_db = self.accessor
        report_schema = report_db.report_schema
        for table_name in self.report_tables:
            table = getattr(report_schema, table_name)
            with schema_context(self.schema):
                count = table.objects.count()
            counts[table_name] = count

        expected = ("INFO:masu.processor.aws.aws_report_processor:"
                    f"Skip processing for file: {base_name} and "
                    f"schema: {self.schema} as it was not found on disk.")
        logging.disable(
            logging.NOTSET
        )  # We are currently disabling all logging below CRITICAL in masu/__init__.py
        with self.assertLogs("masu.processor.aws.aws_report_processor",
                             level="INFO") as logger:
            processor.process()
            self.assertIn(expected, logger.output)
    def test_process_gzip(self):
        """Test the processing of a gzip compressed file."""
        counts = {}
        processor = AWSReportProcessor(
            schema_name='acct10001',
            report_path=self.test_report_gzip,
            compression=GZIP_COMPRESSED,
            provider_id=1
        )
        report_db = self.accessor
        report_schema = report_db.report_schema
        for table_name in self.report_tables:
            table = getattr(report_schema, table_name)
            count = report_db._session.query(table).count()
            counts[table_name] = count

        processor.process()

        for table_name in self.report_tables:
            table = getattr(report_schema, table_name)
            count = report_db._session.query(table).count()

            if table_name in ('reporting_awscostentryreservation',
                              'reporting_ocpawscostlineitem_daily_summary',
                              'reporting_ocpawscostlineitem_project_daily_summary'):
                self.assertTrue(count >= counts[table_name])
            else:
                self.assertTrue(count > counts[table_name])
Beispiel #5
0
    def test_delete_line_items_success(self):
        """Test that data is deleted before processing a manifest."""
        manifest = CostUsageReportManifest.objects.filter(
            provider__uuid=self.aws_provider_uuid,
            billing_period_start_datetime=DateHelper().this_month_start).first(
            )
        manifest.num_processed_files = 0
        manifest.save()
        bill_date = manifest.billing_period_start_datetime
        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
            manifest_id=manifest.id,
        )

        with schema_context(self.schema):
            bills = self.accessor.get_cost_entry_bills_by_date(bill_date)
            bill_ids = [bill.id for bill in bills]

        for bill_id in bill_ids:
            with schema_context(self.schema):
                before_count = self.accessor.get_lineitem_query_for_billid(
                    bill_id).count()
            result = processor._delete_line_items(AWSReportDBAccessor)

            with schema_context(self.schema):
                line_item_query = self.accessor.get_lineitem_query_for_billid(
                    bill_id)
                self.assertTrue(result)
                self.assertLess(line_item_query.count(), before_count)
    def test_process_default(self):
        """Test the processing of an uncompressed file."""
        counts = {}
        processor = AWSReportProcessor(
            schema_name='acct10001',
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_id=1,
            manifest_id=self.manifest.id
        )
        report_db = self.accessor
        report_schema = report_db.report_schema
        for table_name in self.report_tables:
            table = getattr(report_schema, table_name)
            count = report_db._session.query(table).count()
            counts[table_name] = count

        bill_date = self.manifest.billing_period_start_datetime.date()
        expected = f'INFO:masu.processor.aws.aws_report_processor:Deleting data for schema: acct10001 and bill date: {bill_date}'
        logging.disable(logging.NOTSET) # We are currently disabling all logging below CRITICAL in masu/__init__.py
        with self.assertLogs('masu.processor.aws.aws_report_processor', level='INFO') as logger:
            processor.process()
            self.assertIn(expected, logger.output)

        for table_name in self.report_tables:
            table = getattr(report_schema, table_name)
            count = report_db._session.query(table).count()

            if table_name in ('reporting_awscostentryreservation',
                              'reporting_ocpawscostlineitem_daily_summary',
                              'reporting_ocpawscostlineitem_project_daily_summary'):
                self.assertTrue(count >= counts[table_name])
            else:
                self.assertTrue(count > counts[table_name])
    def test_delete_line_items_not_first_file_in_manifest(self):
        """Test that data is not deleted once a file has been processed."""
        manifest_helper = ManifestCreationHelper(self.manifest.id,
                                                 self.manifest.num_total_files,
                                                 self.manifest.assembly_id)

        report_file = manifest_helper.generate_one_test_file()
        manifest_helper.mark_report_file_as_completed(report_file)

        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
            manifest_id=self.manifest.id,
        )
        processor.process()
        result = processor._delete_line_items(AWSReportDBAccessor)
        with schema_context(self.schema):
            bills = self.accessor.get_cost_entry_bills()
            for bill_id in bills.values():
                line_item_query = self.accessor.get_lineitem_query_for_billid(
                    bill_id)
                self.assertFalse(result)
                self.assertNotEqual(line_item_query.count(), 0)
Beispiel #8
0
    def test_check_for_finalized_bill_bill_is_finalized(self):
        """Verify that a file with invoice_id is marked as finalzed."""
        data = []

        with open(self.test_report, 'r') as f:
            reader = csv.DictReader(f)
            for row in reader:
                data.append(row)

        for row in data:
            row['bill/InvoiceId'] = '12345'

        tmp_file = '/tmp/test_process_finalized_rows.csv'
        field_names = data[0].keys()

        with open(tmp_file, 'w') as f:
            writer = csv.DictWriter(f, fieldnames=field_names)
            writer.writeheader()
            writer.writerows(data)

        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=tmp_file,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
        )

        result = processor._check_for_finalized_bill()

        self.assertTrue(result)
Beispiel #9
0
    def test_should_process_full_month_no_manifest(self):
        """Test that we process this manifest completely."""
        processor = AWSReportProcessor(schema_name=self.schema,
                                       report_path=self.test_report,
                                       compression=UNCOMPRESSED,
                                       provider_uuid=self.aws_provider_uuid)

        self.assertTrue(processor._should_process_full_month())
Beispiel #10
0
    def test_delete_line_items_use_data_cutoff_date(self, mock_should_process):
        """Test that only three days of data are deleted."""
        mock_should_process.return_value = True

        today = self.date_accessor.today_with_timezone("UTC").replace(
            hour=0, minute=0, second=0, microsecond=0)
        first_of_month = today.replace(day=1)

        self.manifest.billing_period_start_datetime = first_of_month
        self.manifest.save()

        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path="",
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
            manifest_id=self.manifest.id,
        )

        # Get latest data date.
        bill_ids = []
        with schema_context(self.schema):
            bills = self.accessor.get_cost_entry_bills()
            for key, value in bills.items():
                if key[1] == DateHelper().this_month_start:
                    bill_ids.append(value)

        for bill_id in bill_ids:
            with schema_context(self.schema):
                line_item_query = self.accessor.get_lineitem_query_for_billid(
                    bill_id)
                undeleted_max_date = line_item_query.aggregate(
                    max_date=Max("usage_start"))

            mock_should_process.return_value = False
            processor._delete_line_items(AWSReportDBAccessor,
                                         is_finalized=False)

            with schema_context(self.schema):
                # bills = self.accessor.get_cost_entry_bills()
                # for bill_id in bills.values():
                line_item_query = self.accessor.get_lineitem_query_for_billid(
                    bill_id)
                if today.day <= 3:
                    self.assertEqual(line_item_query.count(), 0)
                else:
                    max_date = line_item_query.aggregate(
                        max_date=Max("usage_start"))
                    self.assertLess(
                        max_date.get("max_date").date(),
                        processor.data_cutoff_date)
                    self.assertLess(
                        max_date.get("max_date").date(),
                        undeleted_max_date.get("max_date").date())
                    self.assertNotEqual(line_item_query.count(), 0)
Beispiel #11
0
    def test_get_date_column_filter(self):
        """Test that the Azure specific filter is returned."""
        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
            manifest_id=self.manifest.id,
        )
        date_filter = processor.get_date_column_filter()

        self.assertIn('usage_start__gte', date_filter)
Beispiel #12
0
    def test_check_for_finalized_bill_bill_not_finalized(self):
        """Verify that a file without invoice_id is not marked as finalzed."""
        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
        )

        result = processor._check_for_finalized_bill()

        self.assertFalse(result)
    def test_process_default(self):
        """Test the processing of an uncompressed file."""
        counts = {}
        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
            manifest_id=self.manifest.id,
        )
        report_db = self.accessor
        report_schema = report_db.report_schema
        for table_name in self.report_tables:
            table = getattr(report_schema, table_name)
            with schema_context(self.schema):
                count = table.objects.count()
            counts[table_name] = count

        bill_date = self.manifest.billing_period_start_datetime.date()

        expected = (
            f'INFO:masu.processor.report_processor_base:Processing bill starting on {bill_date}.\n'
            f' Processing entire month.\n'
            f' schema_name: {self.schema},\n'
            f' provider_uuid: {self.aws_provider_uuid},\n'
            f' manifest_id: {self.manifest.id}'
        )
        logging.disable(
            logging.NOTSET
        )  # We are currently disabling all logging below CRITICAL in masu/__init__.py
        with self.assertLogs(
            'masu.processor.report_processor_base', level='INFO'
        ) as logger:
            processor.process()
            self.assertIn(expected, logger.output)

        for table_name in self.report_tables:
            table = getattr(report_schema, table_name)
            with schema_context(self.schema):
                count = table.objects.count()

            if table_name in (
                'reporting_awscostentryreservation',
                'reporting_ocpawscostlineitem_daily_summary',
                'reporting_ocpawscostlineitem_project_daily_summary',
            ):
                self.assertTrue(count >= counts[table_name])
            else:
                self.assertTrue(count > counts[table_name])

        self.assertFalse(os.path.exists(self.test_report))
    def test_process_finalized_rows(self):
        """Test that a finalized bill is processed properly."""
        data = []
        table_name = AWS_CUR_TABLE_MAP['line_item']

        with open(self.test_report, 'r') as f:
            reader = csv.DictReader(f)
            for row in reader:
                data.append(row)

        for row in data:
            row['bill/InvoiceId'] = '12345'

        tmp_file = '/tmp/test_process_finalized_rows.csv'
        field_names = data[0].keys()

        with open(tmp_file, 'w') as f:
            writer = csv.DictWriter(f, fieldnames=field_names)
            writer.writeheader()
            writer.writerows(data)

        processor = AWSReportProcessor(
            schema_name='acct10001',
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_id=1
        )

        # Process for the first time
        processor.process()
        report_db = self.accessor
        report_schema = report_db.report_schema

        bill_table_name = AWS_CUR_TABLE_MAP['bill']
        bill_table = getattr(report_schema, bill_table_name)
        bill = report_db._session.query(bill_table).first()
        self.assertIsNone(bill.finalized_datetime)

        table = getattr(report_schema, table_name)
        orig_count = report_db._session.query(table).count()

        # Wipe stale data
        self.accessor._get_db_obj_query(table_name).delete()

        processor = AWSReportProcessor(
            schema_name='acct10001',
            report_path=tmp_file,
            compression=UNCOMPRESSED,
            provider_id=1
        )
        # Process for the second time
        processor.process()

        count = report_db._session.query(table).count()
        self.assertTrue(count == orig_count)
        count = report_db._session.query(table).filter(table.invoice_id != None).count()
        self.assertTrue(count == orig_count)

        report_db._session.commit()
        self.assertIsNotNone(bill.finalized_datetime)
Beispiel #15
0
    def test_check_for_finalized_bill_empty_bill(self):
        """Verify that an empty file is not marked as finalzed."""
        tmp_file = "/tmp/test_process_finalized_rows.csv"

        with open(tmp_file, "w"):
            pass

        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=tmp_file,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
        )
        result = processor._check_for_finalized_bill()
        self.assertFalse(result)
    def test_should_process_full_month_manifest_for_not_current_month(self, mock_manifest_accessor):
        """Test that we process this manifest completely."""
        mock_manifest = Mock()
        last_month = self.date_accessor.today_with_timezone('UTC') - relativedelta(months=1)
        mock_manifest.billing_period_start_datetime = last_month
        mock_manifest_accessor.return_value.__enter__.return_value.get_manifest_by_id.return_value = mock_manifest
        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
            manifest_id=self.manifest.id,
        )

        self.assertTrue(processor._should_process_full_month())
 def test_delete_line_items_no_manifest(self):
     """Test that no data is deleted without a manifest id."""
     processor = AWSReportProcessor(
         schema_name='acct10001',
         report_path=self.test_report,
         compression=UNCOMPRESSED,
         provider_id=1
     )
     processor.process()
     result = processor._delete_line_items()
     bills = self.accessor.get_cost_entry_bills()
     for bill_id in bills.values():
         line_item_query = self.accessor.get_lineitem_query_for_billid(bill_id)
         self.assertFalse(result)
         self.assertNotEqual(line_item_query.count(), 0)
Beispiel #18
0
    def setUpClass(cls):
        """Set up the test class with required objects."""
        cls.test_report = './tests/data/test_cur.csv'
        cls.test_report_gzip = './tests/data/test_cur.csv.gz'

        cls.processor = AWSReportProcessor(
            schema_name='acct10001',
            report_path=cls.test_report,
            compression=UNCOMPRESSED,
            provider_id=1,
        )

        cls.date_accessor = DateAccessor()
        billing_start = cls.date_accessor.today_with_timezone('UTC').replace(
            year=2018, month=6, day=1, hour=0, minute=0, second=0)
        cls.manifest_dict = {
            'assembly_id': '1234',
            'billing_period_start_datetime': billing_start,
            'num_total_files': 2,
            'provider_id': 1,
        }
        cls.manifest_accessor = ReportManifestDBAccessor()

        with ReportingCommonDBAccessor() as report_common_db:
            cls.column_map = report_common_db.column_map

        _report_tables = copy.deepcopy(AWS_CUR_TABLE_MAP)
        _report_tables.pop('line_item_daily', None)
        _report_tables.pop('line_item_daily_summary', None)
        _report_tables.pop('tags_summary', None)
        cls.report_tables = list(_report_tables.values())
        # Grab a single row of test data to work with
        with open(cls.test_report, 'r') as f:
            reader = csv.DictReader(f)
            cls.row = next(reader)
 def test_initializer_unsupported_compression(self):
     """Assert that an error is raised for an invalid compression."""
     with self.assertRaises(MasuProcessingError):
         AWSReportProcessor(schema_name='acct10001',
                            report_path=self.test_report,
                            compression='unsupported',
                            provider_id=1)
Beispiel #20
0
    def test_should_process_row_within_cuttoff_date(self):
        """Test that we correctly determine a row should be processed."""
        today = self.date_accessor.today_with_timezone('UTC')
        row = {'lineItem/UsageStartDate': today.isoformat()}

        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
            manifest_id=self.manifest.id,
        )

        should_process = processor._should_process_row(row, 'lineItem/UsageStartDate', False)

        self.assertTrue(should_process)
Beispiel #21
0
    def _set_processor(self):
        """
        Create the report processor object.

        Processor is specific to the provider's cloud service.

        Args:
            None

        Returns:
            (Object) : Provider-specific report processor

        """
        if self.provider_type in (AMAZON_WEB_SERVICES,
                                  AWS_LOCAL_SERVICE_PROVIDER):
            return AWSReportProcessor(schema_name=self.schema_name,
                                      report_path=self.report_path,
                                      compression=self.compression,
                                      provider_id=self.provider_id,
                                      manifest_id=self.manifest_id)

        if self.provider_type in (AZURE, AZURE_LOCAL_SERVICE_PROVIDER):
            return AzureReportProcessor(schema_name=self.schema_name,
                                        report_path=self.report_path,
                                        compression=self.compression,
                                        provider_id=self.provider_id,
                                        manifest_id=self.manifest_id)

        if self.provider_type in (OPENSHIFT_CONTAINER_PLATFORM, ):
            return OCPReportProcessor(schema_name=self.schema_name,
                                      report_path=self.report_path,
                                      compression=self.compression,
                                      provider_id=self.provider_id)

        return None
Beispiel #22
0
    def _set_processor(self):
        """
        Create the report processor object.

        Processor is specific to the provider's cloud service.

        Args:
            None

        Returns:
            (Object) : Provider-specific report processor

        """
        if enable_trino_processing(self.provider_uuid):
            return ParquetReportProcessor(
                schema_name=self.schema_name,
                report_path=self.report_path,
                compression=self.compression,
                provider_uuid=self.provider_uuid,
                provider_type=self.provider_type,
                manifest_id=self.manifest_id,
                context=self.context,
            )
        if self.provider_type in (Provider.PROVIDER_AWS,
                                  Provider.PROVIDER_AWS_LOCAL):
            return AWSReportProcessor(
                schema_name=self.schema_name,
                report_path=self.report_path,
                compression=self.compression,
                provider_uuid=self.provider_uuid,
                manifest_id=self.manifest_id,
            )

        if self.provider_type in (Provider.PROVIDER_AZURE,
                                  Provider.PROVIDER_AZURE_LOCAL):
            return AzureReportProcessor(
                schema_name=self.schema_name,
                report_path=self.report_path,
                compression=self.compression,
                provider_uuid=self.provider_uuid,
                manifest_id=self.manifest_id,
            )

        if self.provider_type in (Provider.PROVIDER_OCP, ):
            return OCPReportProcessor(
                schema_name=self.schema_name,
                report_path=self.report_path,
                compression=self.compression,
                provider_uuid=self.provider_uuid,
            )
        if self.provider_type in (Provider.PROVIDER_GCP,
                                  Provider.PROVIDER_GCP_LOCAL):
            return GCPReportProcessor(
                schema_name=self.schema_name,
                report_path=self.report_path,
                compression=self.compression,
                provider_uuid=self.provider_uuid,
                manifest_id=self.manifest_id,
            )
        return None
    def test_delete_line_items_success(self):
        """Test that data is deleted before processing a manifest."""
        processor = AWSReportProcessor(
            schema_name='acct10001',
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_id=1,
            manifest_id=self.manifest.id
        )
        processor.process()
        result = processor._delete_line_items()

        bills = self.accessor.get_cost_entry_bills()
        for bill_id in bills.values():
            line_item_query = self.accessor.get_lineitem_query_for_billid(bill_id)
            self.assertTrue(result)
            self.assertEqual(line_item_query.count(), 0)
Beispiel #24
0
    def test_should_process_is_full_month(self):
        """Test that we correctly determine a row should be processed."""
        today = self.date_accessor.today_with_timezone('UTC')
        usage_start = today - relativedelta(days=10)
        row = {'lineItem/UsageStartDate': usage_start.isoformat()}

        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
            manifest_id=self.manifest.id,
        )

        should_process = processor._should_process_row(row, 'lineItem/UsageStartDate', True)

        self.assertTrue(should_process)
Beispiel #25
0
    def test_delete_line_items_success(self):
        """Test that data is deleted before processing a manifest."""
        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
            manifest_id=self.manifest.id,
        )
        processor.process()
        result = processor._delete_line_items(AWSReportDBAccessor, self.column_map)

        with schema_context(self.schema):
            bills = self.accessor.get_cost_entry_bills()
            for bill_id in bills.values():
                line_item_query = self.accessor.get_lineitem_query_for_billid(bill_id)
                self.assertTrue(result)
                self.assertEqual(line_item_query.count(), 0)
 def test_delete_line_items_not_first_file_in_manifest(self):
     """Test that data is not deleted once a file has been processed."""
     self.manifest.num_processed_files = 1
     self.manifest_accessor.commit()
     processor = AWSReportProcessor(
         schema_name='acct10001',
         report_path=self.test_report,
         compression=UNCOMPRESSED,
         provider_id=1,
         manifest_id=self.manifest.id
     )
     processor.process()
     result = processor._delete_line_items()
     bills = self.accessor.get_cost_entry_bills()
     for bill_id in bills.values():
         line_item_query = self.accessor.get_lineitem_query_for_billid(bill_id)
         self.assertFalse(result)
         self.assertNotEqual(line_item_query.count(), 0)
Beispiel #27
0
    def test_should_process_row_outside_cuttoff_date(self):
        """Test that we correctly determine a row should be processed."""
        today = self.date_accessor.today_with_timezone("UTC")
        usage_start = today - relativedelta(days=10)
        row = {"lineItem/UsageStartDate": usage_start.isoformat()}

        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
            manifest_id=self.manifest.id,
        )

        should_process = processor._should_process_row(
            row, "lineItem/UsageStartDate", False)

        self.assertFalse(should_process)
Beispiel #28
0
 def test_initializer_unsupported_compression(self):
     """Assert that an error is raised for an invalid compression."""
     with self.assertRaises(MasuProcessingError):
         AWSReportProcessor(
             schema_name=self.schema,
             report_path=self.test_report,
             compression="unsupported",
             provider_uuid=self.aws_provider_uuid,
         )
    def test_should_process_full_month_not_first_manifest_for_bill(self, mock_manifest_accessor):
        """Test that we process a window of data for the bill/manifest."""
        mock_manifest = Mock()
        today = self.date_accessor.today_with_timezone('UTC')
        mock_manifest.billing_period_start_datetime = today
        mock_manifest.num_processed_files = 1
        mock_manifest.num_total_files = 1
        mock_manifest_accessor.return_value.__enter__.return_value.get_manifest_by_id.return_value = mock_manifest
        mock_manifest_accessor.return_value.__enter__.return_value.get_manifest_list_for_provider_and_bill_date.return_value = [mock_manifest, mock_manifest]
        processor = AWSReportProcessor(
            schema_name=self.schema,
            report_path=self.test_report,
            compression=UNCOMPRESSED,
            provider_uuid=self.aws_provider_uuid,
            manifest_id=self.manifest.id,
        )

        self.assertFalse(processor._should_process_full_month())
Beispiel #30
0
 def test_delete_line_items_not_first_file_in_manifest(self):
     """Test that data is not deleted once a file has been processed."""
     self.manifest.num_processed_files = 1
     self.manifest.save()
     processor = AWSReportProcessor(
         schema_name=self.schema,
         report_path=self.test_report,
         compression=UNCOMPRESSED,
         provider_uuid=self.aws_provider_uuid,
         manifest_id=self.manifest.id,
     )
     processor.process()
     result = processor._delete_line_items(AWSReportDBAccessor, self.column_map)
     with schema_context(self.schema):
         bills = self.accessor.get_cost_entry_bills()
         for bill_id in bills.values():
             line_item_query = self.accessor.get_lineitem_query_for_billid(bill_id)
             self.assertFalse(result)
             self.assertNotEqual(line_item_query.count(), 0)