def test_clean_volume(self, mock_date, mock_config): """Test that the clean volume function is cleaning the appropriate files""" # create a manifest mock_date.return_value = ["2020-02-01"] manifest_dict = { "assembly_id": "1234", "billing_period_start_datetime": "2020-02-01", "num_total_files": 2, "provider_uuid": self.aws_provider_uuid, } manifest_accessor = ReportManifestDBAccessor() manifest = manifest_accessor.add(**manifest_dict) # create two files on the temporary volume one with a matching prefix id # as the assembly_id in the manifest above with tempfile.TemporaryDirectory() as tmpdirname: mock_config.PVC_DIR = tmpdirname mock_config.VOLUME_FILE_RETENTION = 60 * 60 * 24 old_matching_file = os.path.join(tmpdirname, "%s.csv" % manifest.assembly_id) new_no_match_file = os.path.join(tmpdirname, "newfile.csv") old_no_match_file = os.path.join(tmpdirname, "oldfile.csv") filepaths = [old_matching_file, new_no_match_file, old_no_match_file] for path in filepaths: open(path, "a").close() self.assertEqual(os.path.exists(path), True) # Update timestame for oldfile.csv datehelper = DateHelper() now = datehelper.now old_datetime = now - timedelta(seconds=mock_config.VOLUME_FILE_RETENTION * 2) oldtime = old_datetime.timestamp() os.utime(old_matching_file, (oldtime, oldtime)) os.utime(old_no_match_file, (oldtime, oldtime)) # now run the clean volume task tasks.clean_volume() # make sure that the file with the matching id still exists and that # the file with the other id is gone self.assertEqual(os.path.exists(old_matching_file), True) self.assertEqual(os.path.exists(new_no_match_file), True) self.assertEqual(os.path.exists(old_no_match_file), False) # now edit the manifest to say that all the files have been processed # and rerun the clean_volumes task manifest.num_processed_files = manifest_dict.get("num_total_files") manifest_helper = ManifestCreationHelper( manifest.id, manifest_dict.get("num_total_files"), manifest_dict.get("assembly_id") ) manifest_helper.generate_test_report_files() manifest_helper.process_all_files() manifest.save() tasks.clean_volume() # ensure that the original file is deleted from the volume self.assertEqual(os.path.exists(old_matching_file), False) self.assertEqual(os.path.exists(new_no_match_file), True) # assert the tempdir is cleaned up self.assertEqual(os.path.exists(tmpdirname), False) # test no files found for codecov tasks.clean_volume()
def setUp(self): """Set up GCP tests.""" super().setUp() self.temp_dir = tempfile.mkdtemp() self.test_report = f"{self.temp_dir}/202011_30c31bca571d9b7f3b2c8459dd8bc34a_2020-11-08:2020-11-11.csv" shutil.copy2(self.test_report_path, self.test_report) gcp_auth = ProviderAuthentication.objects.create( credentials={"project-id": fake.word()}) gcp_billing_source = ProviderBillingSource.objects.create( data_source={"bucket": fake.word()}) with patch("masu.celery.tasks.check_report_updates"): self.gcp_provider = Provider.objects.create( uuid=uuid.uuid4(), name="Test Provider", type=Provider.PROVIDER_GCP, authentication=gcp_auth, billing_source=gcp_billing_source, customer=self.customer, setup_complete=True, ) start_time = "2020-11-08 23:00:00+00:00" report_date_range = utils.month_date_range(parser.parse(start_time)) start_date, end_date = report_date_range.split("-") self.start_date_utc = parser.parse(start_date).replace(hour=0, minute=0, tzinfo=pytz.UTC) self.end_date_utc = parser.parse(end_date).replace(hour=0, minute=0, tzinfo=pytz.UTC) self.assembly_id = "1234" self.manifest_dict = { "assembly_id": self.assembly_id, "billing_period_start_datetime": self.start_date_utc, "num_total_files": 1, "provider_uuid": self.gcp_provider.uuid, } manifest_accessor = ReportManifestDBAccessor() self.manifest = manifest_accessor.add(**self.manifest_dict) self.processor = GCPReportProcessor( schema_name=self.schema, report_path=self.test_report, compression=UNCOMPRESSED, provider_uuid=self.gcp_provider.uuid, manifest_id=self.manifest.id, ) self.accessor = GCPReportDBAccessor(self.schema)
def setUp(self): """Set up GCP tests.""" super().setUp() self.temp_dir = tempfile.mkdtemp() self.test_report = f'{self.temp_dir}/evidence-2019-06-03.csv' shutil.copy2(self.test_report_path, self.test_report) gcp_auth = ProviderAuthentication.objects.create( credentials={'project-id': fake.word()}) gcp_billing_source = ProviderBillingSource.objects.create( data_source={'bucket': fake.word()}) self.gcp_provider = Provider.objects.create( uuid=uuid.uuid4(), name='Test Provider', type=Provider.PROVIDER_GCP, authentication=gcp_auth, billing_source=gcp_billing_source, customer=self.customer, setup_complete=True, ) start_time = '2019-09-17T00:00:00-07:00' report_date_range = utils.month_date_range(parser.parse(start_time)) start_date, end_date = report_date_range.split('-') self.start_date_utc = parser.parse(start_date).replace(hour=0, minute=0, tzinfo=pytz.UTC) self.end_date_utc = parser.parse(end_date).replace(hour=0, minute=0, tzinfo=pytz.UTC) self.assembly_id = '1234' self.manifest_dict = { 'assembly_id': self.assembly_id, 'billing_period_start_datetime': self.start_date_utc, 'num_total_files': 1, 'provider_uuid': self.gcp_provider.uuid, } manifest_accessor = ReportManifestDBAccessor() self.manifest = manifest_accessor.add(**self.manifest_dict) self.processor = GCPReportProcessor( schema_name=self.schema, report_path=self.test_report, compression=UNCOMPRESSED, provider_uuid=self.gcp_provider.uuid, manifest_id=self.manifest.id, ) self.accessor = GCPReportDBAccessor(self.schema, self.column_map)
class ReportManifestDBAccessorTest(IamTestCase): """Test cases for the ReportManifestDBAccessor.""" def setUp(self): """Set up the test class.""" super().setUp() self.schema = self.schema_name billing_start = DateAccessor().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.provider_uuid, } self.manifest_accessor = ReportManifestDBAccessor() def tearDown(self): """Tear down the test class.""" super().tearDown() with schema_context(self.schema): manifests = self.manifest_accessor._get_db_obj_query().all() for manifest in manifests: self.manifest_accessor.delete(manifest) def test_initializer(self): """Test the initializer.""" accessor = ReportManifestDBAccessor() self.assertIsNotNone(accessor._table) def test_get_manifest(self): """Test that the right manifest is returned.""" with schema_context(self.schema): added_manifest = self.manifest_accessor.add(**self.manifest_dict) assembly_id = self.manifest_dict.get('assembly_id') provider_uuid = self.manifest_dict.get('provider_uuid') manifest = self.manifest_accessor.get_manifest( assembly_id, provider_uuid) self.assertIsNotNone(manifest) self.assertEqual(added_manifest, manifest) self.assertEqual(manifest.assembly_id, assembly_id) self.assertEqual(manifest.provider_id, provider_uuid) self.assertEqual(manifest.num_total_files, self.manifest_dict.get('num_total_files')) def test_get_manifest_by_id(self): """Test that the right manifest is returned by id.""" with schema_context(self.schema): added_manifest = self.manifest_accessor.add(**self.manifest_dict) manifest = self.manifest_accessor.get_manifest_by_id( added_manifest.id) self.assertIsNotNone(manifest) self.assertEqual(added_manifest, manifest) def test_mark_manifest_as_updated(self): """Test that the manifest is marked updated.""" with schema_context(self.schema): manifest = self.manifest_accessor.add(**self.manifest_dict) now = DateAccessor().today_with_timezone('UTC') self.manifest_accessor.mark_manifest_as_updated(manifest) self.assertGreater(manifest.manifest_updated_datetime, now) def test_mark_manifest_as_completed(self): """Test that the manifest is marked updated.""" manifest = self.manifest_accessor.add(**self.manifest_dict) now = DateAccessor().today_with_timezone('UTC') self.manifest_accessor.mark_manifest_as_completed(manifest) self.assertGreater(manifest.manifest_completed_datetime, now) def test_get_manifest_list_for_provider_and_bill_date(self): """Test that all manifests are returned for a provider and bill.""" bill_date = self.manifest_dict['billing_period_start_datetime'].date() manifest_dict = copy.deepcopy(self.manifest_dict) self.manifest_accessor.add(**manifest_dict) result = self.manifest_accessor.get_manifest_list_for_provider_and_bill_date( self.provider_uuid, bill_date) self.assertEqual(len(result), 1) manifest_dict['assembly_id'] = '2345' self.manifest_accessor.add(**manifest_dict) result = self.manifest_accessor.get_manifest_list_for_provider_and_bill_date( self.provider_uuid, bill_date) self.assertEqual(len(result), 2) manifest_dict['assembly_id'] = '3456' self.manifest_accessor.add(**manifest_dict) result = self.manifest_accessor.get_manifest_list_for_provider_and_bill_date( self.provider_uuid, bill_date) self.assertEqual(len(result), 3) def test_get_last_report_completed_datetime(self): """Test that the last completed report datetime is returned.""" manifest = self.manifest_accessor.add(**self.manifest_dict) earlier_time = DateAccessor().today_with_timezone('UTC') later_time = earlier_time + datetime.timedelta(hours=1) ReportStatsDBAccessor( 'earlier_report', manifest.id).update(last_completed_datetime=earlier_time) ReportStatsDBAccessor( 'later_report', manifest.id).update(last_completed_datetime=later_time) result = self.manifest_accessor.get_last_report_completed_datetime( manifest.id) self.assertEqual(result, later_time)
class ReportManifestDBAccessorTest(IamTestCase): """Test cases for the ReportManifestDBAccessor.""" def setUp(self): """Set up the test class.""" super().setUp() self.schema = self.schema_name self.billing_start = DateAccessor().today_with_timezone("UTC").replace( day=1) self.manifest_dict = { "assembly_id": "1234", "billing_period_start_datetime": self.billing_start, "num_total_files": 2, "provider_uuid": self.provider_uuid, } self.manifest_accessor = ReportManifestDBAccessor() def tearDown(self): """Tear down the test class.""" super().tearDown() with schema_context(self.schema): manifests = self.manifest_accessor._get_db_obj_query().all() for manifest in manifests: self.manifest_accessor.delete(manifest) def test_initializer(self): """Test the initializer.""" accessor = ReportManifestDBAccessor() self.assertIsNotNone(accessor._table) def test_get_manifest(self): """Test that the right manifest is returned.""" with schema_context(self.schema): added_manifest = self.manifest_accessor.add(**self.manifest_dict) assembly_id = self.manifest_dict.get("assembly_id") provider_uuid = self.manifest_dict.get("provider_uuid") manifest = self.manifest_accessor.get_manifest( assembly_id, provider_uuid) self.assertIsNotNone(manifest) self.assertEqual(added_manifest, manifest) self.assertEqual(manifest.assembly_id, assembly_id) self.assertEqual(manifest.provider_id, provider_uuid) self.assertEqual(manifest.num_total_files, self.manifest_dict.get("num_total_files")) def test_get_manifest_by_id(self): """Test that the right manifest is returned by id.""" with schema_context(self.schema): added_manifest = self.manifest_accessor.add(**self.manifest_dict) manifest = self.manifest_accessor.get_manifest_by_id( added_manifest.id) self.assertIsNotNone(manifest) self.assertEqual(added_manifest, manifest) def test_mark_manifest_as_updated(self): """Test that the manifest is marked updated.""" with schema_context(self.schema): manifest = self.manifest_accessor.add(**self.manifest_dict) now = DateAccessor().today_with_timezone("UTC") self.manifest_accessor.mark_manifest_as_updated(manifest) self.assertGreater(manifest.manifest_updated_datetime, now) def test_mark_manifest_as_updated_none_manifest(self): """Test that a none manifest doesn't update failure.""" try: self.manifest_accessor.mark_manifest_as_updated(None) except Exception as err: self.fail(f"Test failed with error: {err}") def test_mark_manifest_as_completed_none_manifest(self): """Test that a none manifest doesn't complete failure.""" try: self.manifest_accessor.mark_manifest_as_completed(None) except Exception as err: self.fail(f"Test failed with error: {err}") def test_get_manifest_list_for_provider_and_bill_date(self): """Test that all manifests are returned for a provider and bill.""" bill_date = self.manifest_dict["billing_period_start_datetime"].date() manifest_dict = copy.deepcopy(self.manifest_dict) self.manifest_accessor.add(**manifest_dict) result = self.manifest_accessor.get_manifest_list_for_provider_and_bill_date( self.provider_uuid, bill_date) self.assertEqual(len(result), 1) manifest_dict["assembly_id"] = "2345" self.manifest_accessor.add(**manifest_dict) result = self.manifest_accessor.get_manifest_list_for_provider_and_bill_date( self.provider_uuid, bill_date) self.assertEqual(len(result), 2) manifest_dict["assembly_id"] = "3456" self.manifest_accessor.add(**manifest_dict) result = self.manifest_accessor.get_manifest_list_for_provider_and_bill_date( self.provider_uuid, bill_date) self.assertEqual(len(result), 3) def test_get_last_seen_manifest_ids(self): """Test that get_last_seen_manifest_ids returns the appropriate assembly_ids.""" # test that the most recently seen manifests that haven't been processed are returned manifest_dict2 = { "assembly_id": "5678", "billing_period_start_datetime": self.billing_start, "num_total_files": 1, "provider_uuid": "00000000-0000-0000-0000-000000000002", } manifest = self.manifest_accessor.add(**self.manifest_dict) manifest2 = self.manifest_accessor.add(**manifest_dict2) assembly_ids = self.manifest_accessor.get_last_seen_manifest_ids( self.billing_start) self.assertEqual(assembly_ids, [manifest.assembly_id, manifest2.assembly_id]) # test that when the manifest's files have been processed - it is no longer returned manifest2_helper = ManifestCreationHelper( manifest2.id, manifest_dict2.get("num_total_files"), manifest_dict2.get("assembly_id")) manifest2_helper.generate_test_report_files() manifest2_helper.process_all_files() assembly_ids = self.manifest_accessor.get_last_seen_manifest_ids( self.billing_start) self.assertEqual(assembly_ids, [manifest.assembly_id]) # test that of two manifests with the same provider_ids - that only the most recently # seen is returned manifest_dict3 = { "assembly_id": "91011", "billing_period_start_datetime": self.billing_start, "num_total_files": 1, "provider_uuid": self.provider_uuid, } manifest3 = self.manifest_accessor.add(**manifest_dict3) assembly_ids = self.manifest_accessor.get_last_seen_manifest_ids( self.billing_start) self.assertEqual(assembly_ids, [manifest3.assembly_id]) # test that manifests for a different billing month are not returned current_month = self.billing_start calculated_month = current_month + relativedelta(months=-2) manifest3.billing_period_start_datetime = calculated_month manifest3.save() assembly_ids = self.manifest_accessor.get_last_seen_manifest_ids( self.billing_start) self.assertEqual(assembly_ids, [manifest.assembly_id]) def test_is_last_completed_datetime_null(self): """Test is last completed datetime is null.""" manifest_id = 123456789 self.assertTrue( ReportManifestDBAccessor().is_last_completed_datetime_null( manifest_id)) baker.make(CostUsageReportManifest, id=manifest_id) baker.make(CostUsageReportStatus, manifest_id=manifest_id, last_completed_datetime=None) self.assertTrue( ReportManifestDBAccessor().is_last_completed_datetime_null( manifest_id)) CostUsageReportStatus.objects.filter(manifest_id=manifest_id).update( last_completed_datetime=FAKE.date()) self.assertFalse( ReportManifestDBAccessor().is_last_completed_datetime_null( manifest_id))
class ReportManifestDBAccessorTest(IamTestCase): """Test cases for the ReportManifestDBAccessor.""" def setUp(self): """Set up the test class.""" super().setUp() self.schema = self.schema_name billing_start = DateAccessor().today_with_timezone('UTC').replace( day=1) self.manifest_dict = { 'assembly_id': '1234', 'billing_period_start_datetime': billing_start, 'num_total_files': 2, 'provider_id': 1, } self.manifest_accessor = ReportManifestDBAccessor() def tearDown(self): """Tear down the test class.""" super().tearDown() with schema_context(self.schema): manifests = self.manifest_accessor._get_db_obj_query().all() for manifest in manifests: self.manifest_accessor.delete(manifest) def test_initializer(self): """Test the initializer.""" accessor = ReportManifestDBAccessor() self.assertIsNotNone(accessor._table) def test_get_manifest(self): """Test that the right manifest is returned.""" with schema_context(self.schema): added_manifest = self.manifest_accessor.add(**self.manifest_dict) assembly_id = self.manifest_dict.get('assembly_id') provider_id = self.manifest_dict.get('provider_id') manifest = self.manifest_accessor.get_manifest( assembly_id, provider_id) self.assertIsNotNone(manifest) self.assertEqual(added_manifest, manifest) self.assertEqual(manifest.assembly_id, assembly_id) self.assertEqual(manifest.provider_id, provider_id) self.assertEqual(manifest.num_total_files, self.manifest_dict.get('num_total_files')) def test_get_manifest_by_id(self): """Test that the right manifest is returned by id.""" with schema_context(self.schema): added_manifest = self.manifest_accessor.add(**self.manifest_dict) manifest = self.manifest_accessor.get_manifest_by_id( added_manifest.id) self.assertIsNotNone(manifest) self.assertEqual(added_manifest, manifest) def test_mark_manifest_as_updated(self): """Test that the manifest is marked updated.""" with schema_context(self.schema): manifest = self.manifest_accessor.add(**self.manifest_dict) now = DateAccessor().today_with_timezone('UTC') self.manifest_accessor.mark_manifest_as_updated(manifest) self.assertGreater(manifest.manifest_updated_datetime, now)
class ReportStatsDBAccessorTest(MasuTestCase): """Test Cases for the ReportStatsDBAccessor object.""" def setUp(self): """Set up the test class.""" super().setUp() billing_start = datetime.utcnow().replace(day=1) manifest_dict = { "assembly_id": "1234", "billing_period_start_datetime": billing_start, "num_total_files": 2, "provider_uuid": self.aws_provider_uuid, } self.manifest_accessor = ReportManifestDBAccessor() manifest = self.manifest_accessor.add(**manifest_dict) self.manifest_id = manifest.id def test_initializer(self): """Test Initializer.""" saver = ReportStatsDBAccessor("myreport", self.manifest_id) self.assertIsNotNone(saver._obj) def test_initializer_preexisting_report(self): """Test getting a new accessor stats on a preexisting report.""" saver = ReportStatsDBAccessor("myreport", self.manifest_id) saver.update( cursor_position=33, last_completed_datetime="2011-1-1 11:11:11", last_started_datetime="2022-2-2 22:22:22", etag="myetag", ) self.assertIsNotNone(saver._obj) # Get another accessor for the same report and verify we get back the right information. saver2 = ReportStatsDBAccessor("myreport", self.manifest_id) last_completed = saver2.get_last_completed_datetime() self.assertEqual(last_completed.year, 2011) self.assertEqual(last_completed.month, 1) self.assertEqual(last_completed.day, 1) self.assertEqual(last_completed.hour, 11) self.assertEqual(last_completed.minute, 11) self.assertEqual(last_completed.second, 11) self.assertEqual(saver.get_etag(), "myetag") def test_add_remove(self): """Test basic add/remove logic.""" saver = ReportStatsDBAccessor("myreport", self.manifest_id) self.assertTrue(saver.does_db_entry_exist()) returned_obj = saver._get_db_obj_query() self.assertEqual(returned_obj.first().report_name, "myreport") saver.delete() returned_obj = saver._get_db_obj_query() self.assertIsNone(returned_obj.first()) def test_update(self): """Test updating an existing row.""" saver = ReportStatsDBAccessor("myreport", self.manifest_id) returned_obj = saver._get_db_obj_query() self.assertEqual(returned_obj.first().report_name, "myreport") saver.update( cursor_position=33, last_completed_datetime=parser.parse("2011-1-1 11:11:11"), last_started_datetime=parser.parse("2022-2-2 22:22:22"), etag="myetag", ) last_completed = saver.get_last_completed_datetime() self.assertEqual(last_completed.year, 2011) self.assertEqual(last_completed.month, 1) self.assertEqual(last_completed.day, 1) self.assertEqual(last_completed.hour, 11) self.assertEqual(last_completed.minute, 11) self.assertEqual(last_completed.second, 11) last_started = saver.get_last_started_datetime() self.assertEqual(last_started.year, 2022) self.assertEqual(last_started.month, 2) self.assertEqual(last_started.day, 2) self.assertEqual(last_started.hour, 22) self.assertEqual(last_started.minute, 22) self.assertEqual(last_started.second, 22) self.assertEqual(saver.get_etag(), "myetag") saver.delete() returned_obj = saver._get_db_obj_query() self.assertIsNone(returned_obj.first()) def test_log_last_started_datetime(self): """Test convience function for last started processing time.""" initial_count = CostUsageReportStatus.objects.count() saver = ReportStatsDBAccessor("myreport", self.manifest_id) saver.log_last_started_datetime() self.assertIsNotNone(saver.get_last_started_datetime()) saver.delete() self.assertEqual(CostUsageReportStatus.objects.count(), initial_count) def test_log_last_completed_datetime(self): """Test convience function for last completed processing time.""" initial_count = CostUsageReportStatus.objects.count() saver = ReportStatsDBAccessor("myreport", self.manifest_id) saver.log_last_completed_datetime() self.assertIsNotNone(saver.get_last_completed_datetime()) saver.delete() self.assertEqual(CostUsageReportStatus.objects.count(), initial_count) def test_clear_last_started_date(self): """Test convience function for clear last started date.""" saver = ReportStatsDBAccessor("myreport", self.manifest_id) saver.log_last_started_datetime() self.assertIsNotNone(saver.get_last_started_datetime()) saver.clear_last_started_datetime() self.assertIsNone(saver.get_last_started_datetime())
class ReportStatsDBAccessorTest(MasuTestCase): """Test Cases for the ReportStatsDBAccessor object.""" def setUp(self): """Set up the test class.""" super().setUp() billing_start = datetime.utcnow().replace(day=1) manifest_dict = { 'assembly_id': '1234', 'billing_period_start_datetime': billing_start, 'num_total_files': 2, 'provider_uuid': self.aws_provider_uuid, } self.manifest_accessor = ReportManifestDBAccessor() manifest = self.manifest_accessor.add(**manifest_dict) self.manifest_accessor.commit() self.manifest_id = manifest.id def tearDown(self): """Tear down the test class.""" manifests = self.manifest_accessor._get_db_obj_query().all() for manifest in manifests: self.manifest_accessor.delete(manifest) self.manifest_accessor.commit() self.manifest_accessor.close_session() def test_initializer(self): """Test Initializer""" saver = ReportStatsDBAccessor('myreport', self.manifest_id) self.assertIsNotNone(saver._obj) def test_initializer_preexisting_report(self): """Test getting a new accessor stats on a preexisting report.""" saver = ReportStatsDBAccessor('myreport', self.manifest_id) saver.update( cursor_position=33, last_completed_datetime='2011-1-1 11:11:11', last_started_datetime='2022-2-2 22:22:22', etag='myetag', ) saver.commit() self.assertIsNotNone(saver._obj) # Get another accessor for the same report and verify we get back the right information. saver2 = ReportStatsDBAccessor('myreport', self.manifest_id) last_completed = saver2.get_last_completed_datetime() self.assertEqual(last_completed.year, 2011) self.assertEqual(last_completed.month, 1) self.assertEqual(last_completed.day, 1) self.assertEqual(last_completed.hour, 11) self.assertEqual(last_completed.minute, 11) self.assertEqual(last_completed.second, 11) self.assertEqual(saver.get_etag(), 'myetag') def test_add_remove(self): """Test basic add/remove logic.""" saver = ReportStatsDBAccessor('myreport', self.manifest_id) saver.commit() self.assertTrue(saver.does_db_entry_exist()) returned_obj = saver._get_db_obj_query() self.assertEqual(returned_obj.first().report_name, 'myreport') saver.delete() saver.commit() returned_obj = saver._get_db_obj_query() self.assertIsNone(returned_obj.first()) saver.close_session() def test_update(self): """Test updating an existing row.""" saver = ReportStatsDBAccessor('myreport', self.manifest_id) saver.commit() returned_obj = saver._get_db_obj_query() self.assertEqual(returned_obj.first().report_name, 'myreport') saver.update( cursor_position=33, last_completed_datetime=parser.parse('2011-1-1 11:11:11'), last_started_datetime=parser.parse('2022-2-2 22:22:22'), etag='myetag', ) saver.commit() last_completed = saver.get_last_completed_datetime() self.assertEqual(last_completed.year, 2011) self.assertEqual(last_completed.month, 1) self.assertEqual(last_completed.day, 1) self.assertEqual(last_completed.hour, 11) self.assertEqual(last_completed.minute, 11) self.assertEqual(last_completed.second, 11) last_started = saver.get_last_started_datetime() self.assertEqual(last_started.year, 2022) self.assertEqual(last_started.month, 2) self.assertEqual(last_started.day, 2) self.assertEqual(last_started.hour, 22) self.assertEqual(last_started.minute, 22) self.assertEqual(last_started.second, 22) self.assertEqual(saver.get_etag(), 'myetag') saver.delete() saver.commit() returned_obj = saver._get_db_obj_query() self.assertIsNone(returned_obj.first()) saver.close_session() def test_log_last_started_datetime(self): """Test convience function for last started processing time.""" saver = ReportStatsDBAccessor('myreport', self.manifest_id) saver.log_last_started_datetime() saver.commit() # FIXME: missing asserts saver.delete() saver.commit() saver.close_session() def test_log_last_completed_datetime(self): """Test convience function for last completed processing time.""" saver = ReportStatsDBAccessor('myreport', self.manifest_id) saver.log_last_completed_datetime() saver.commit() # FIXME: missing asserts saver.delete() saver.commit() saver.close_session()