def test_should_not_delete_inbound_sms_before_seven_days(sample_service): yesterday = datetime.utcnow() - timedelta(days=1) just_before_seven_days = datetime.utcnow() - timedelta(days=6, hours=23, minutes=59, seconds=59) older_than_seven_days = datetime.utcnow() - timedelta(days=7, seconds=1) create_inbound_sms(sample_service, created_at=yesterday) create_inbound_sms(sample_service, created_at=just_before_seven_days) create_inbound_sms(sample_service, created_at=older_than_seven_days) delete_inbound_sms_created_more_than_a_week_ago() assert len(InboundSms.query.all()) == 2
def delete_inbound_sms_older_than_seven_days(): try: start = datetime.utcnow() deleted = delete_inbound_sms_created_more_than_a_week_ago() current_app.logger.info( "Delete inbound sms job started {} finished {} deleted {} inbound sms notifications" .format(start, datetime.utcnow(), deleted)) except SQLAlchemyError: current_app.logger.exception( "Failed to delete inbound sms notifications") raise
def test_should_delete_inbound_sms_older_than_seven_days(sample_service): older_than_seven_days = datetime.utcnow() - timedelta(days=7, seconds=1) create_inbound_sms(sample_service, created_at=older_than_seven_days) delete_inbound_sms_created_more_than_a_week_ago() assert len(InboundSms.query.all()) == 0