# Path: next/logging_client/LoggerAPI.py
# class LoggerAPI(DatabaseAPI):
#     def __init__(self, mongo_host=constants.MONGODB_HOST, mongo_port=constants.MONGODB_PORT,
#                     database_name=constants.logs_database_id):
#         super(LoggerAPI, self).__init__(mongo_host, mongo_port, database_name)
# 
# 
#     def _normalize_logentry(self, log):
#         if log.get('timestamp') and isinstance(log.get('timestamp'), datetime.datetime):
#             log['timestamp'] = str(log['timestamp'])
# 
#         return log
# 
#     def log(self,bucket_id,log_dict):
#         """
#         Saves log_dict to PermStore as an individual document for later recall. 
#         
#         Inputs: 
#             (string) bucket_id, (dict with string values) log_dict
#         """
#         self.set_doc(bucket_id, None, log_dict)
# 
#     def get_logs_with_filter(self,bucket_id,pattern_dict):
#         """
#         Retrieves all logs in bucket_id that match (i.e. contain) pattern_dict
#         
#         Inputs: 
#             (string) bucket_id, (dict of string values) pattern_dict
#         """
#         return [self._normalize_logentry(d)
#             for d in self.get_docs_with_filter(bucket_id, pattern_dict)]
# 
#     def delete_logs_with_filter(self,bucket_id,pattern_dict):
#         """
#         Deletes all logs in bucket_id that match (i.e. contain) pattern_dict
#         
#         Inputs: 
#             (string) bucket_id, (dict of string values) pattern_dict
#         """
#         self.delete_docs_with_filter(bucket_id, pattern_dict)


import pytest
import datetime
import next.utils as utils
from next.logging_client.LoggerAPI import LoggerAPI


# IMPORTANT NOTE: only uses the `test_logger_data` database; it gets cleared after each test session
MONGO_HOST, MONGO_PORT = 'localhost', 27017
MONGO_DB = 'test_logger_data'

# === fixtures ===
@pytest.fixture(scope='module')
def lapi():
    lapi = LoggerAPI(MONGO_HOST, MONGO_PORT, MONGO_DB)
    yield lapi
    lapi.client.drop_database(MONGO_DB)
    lapi.client.close()

# === tests ===
def test_log(lapi):
    B = 'test_log'

    now = utils.datetimeNow()
    log_entry = {'a': 2, 'timestamp': now}

    lapi.log(B, log_entry)
    assert lapi._bucket(B).find_one({'timestamp': now}).get('a') == 2

def test_get_logs_with_filter(lapi):
    B = 'test_get_logs_with_filter'


# Path: next/logging_client/LoggerAPI.py
# class LoggerAPI(DatabaseAPI):
#     def __init__(self, mongo_host=constants.MONGODB_HOST, mongo_port=constants.MONGODB_PORT,
#                     database_name=constants.logs_database_id):
#         super(LoggerAPI, self).__init__(mongo_host, mongo_port, database_name)
# 
# 
#     def _normalize_logentry(self, log):
#         if log.get('timestamp') and isinstance(log.get('timestamp'), datetime.datetime):
#             log['timestamp'] = str(log['timestamp'])
# 
#         return log
# 
#     def log(self,bucket_id,log_dict):
#         """
#         Saves log_dict to PermStore as an individual document for later recall. 
#         
#         Inputs: 
#             (string) bucket_id, (dict with string values) log_dict
#         """
#         self.set_doc(bucket_id, None, log_dict)
# 
#     def get_logs_with_filter(self,bucket_id,pattern_dict):
#         """
#         Retrieves all logs in bucket_id that match (i.e. contain) pattern_dict
#         
#         Inputs: 
#             (string) bucket_id, (dict of string values) pattern_dict
#         """
#         return [self._normalize_logentry(d)
#             for d in self.get_docs_with_filter(bucket_id, pattern_dict)]
# 
#     def delete_logs_with_filter(self,bucket_id,pattern_dict):
#         """
#         Deletes all logs in bucket_id that match (i.e. contain) pattern_dict
#         
#         Inputs: 
#             (string) bucket_id, (dict of string values) pattern_dict
#         """
#         self.delete_docs_with_filter(bucket_id, pattern_dict)


# Path: next/logging_client/test_loggerapi.py
import pytest
import datetime
import next.utils as utils
from next.logging_client.LoggerAPI import LoggerAPI



# IMPORTANT NOTE: only uses the `test_logger_data` database; it gets cleared after each test session
MONGO_HOST, MONGO_PORT = 'localhost', 27017
MONGO_DB = 'test_logger_data'

# === fixtures ===
@pytest.fixture(scope='module')
def lapi():
    lapi = LoggerAPI(MONGO_HOST, MONGO_PORT, MONGO_DB)
    yield lapi
    lapi.client.drop_database(MONGO_DB)
    lapi.client.close()

# === tests ===
def test_log(lapi):
    B = 'test_log'

    now = utils.datetimeNow()
    log_entry = {'a': 2, 'timestamp': now}

    lapi.log(B, log_entry)
    assert lapi._bucket(B).find_one({'timestamp': now}).get('a') == 2

def test_get_logs_with_filter(lapi):
    B = 'test_get_logs_with_filter'


    now = utils.datetimeNow()