Example #1
0
def test_db_conn_fail():
    with pytest.raises(psycopg2.OperationalError):
        fac = factory.DatabaseConnectionFactory(
            database=None,
            user=None,
            password=None,
            host=None,
            port=None,
        )
        conn = fac.make_connection()
Example #2
0
def test_scheduler_init():
    cfg_fac = fac.ConfigFactory()
    cfg = cfg_fac.make_config(config_path='./test/config_1.yaml')

    conn_fac = db_fac.DatabaseConnectionFactory()
    conn = conn_fac.make_connection()

    sched.Scheduler(
        cfg=cfg,
        conn=conn,
    )
Example #3
0
 def __init__(self):
     self.logger: logging.Logger = logging.getLogger(__name__)
     # make connection
     conn_fac = db_fac.DatabaseConnectionFactory()
     conn = conn_fac.make_connection()
     self.cache = cache.CacheController(conn=conn)
     self.monitor = monitor.ControllerMonitor(cache_controller=self.cache)
     self.comment = comment.ControllerComment(
         cache_controller=self.cache,
         connection=conn,
     )
     obs = observer.Observer(
         name='comment-controller-observer',
         callback='http://127.0.0.1:1337',
     )
     self.comment.register_observer(observer=obs)
Example #4
0
def test_scheduler_observer():
    cfg_fac = fac.ConfigFactory()
    cfg = cfg_fac.make_config(config_path='./test/config_1.yaml')

    conn_fac = db_fac.DatabaseConnectionFactory()
    conn = conn_fac.make_connection()

    scheduler = sched.Scheduler(
        cfg=cfg,
        conn=conn,
    )

    scheduler.schedule_events()

    # make and register observer
    obs = observer.Observer(
        name='schedule-observer',
        callback='http://127.0.0.1:1337',
    )
    scheduler.register_observer(observer=obs)
Example #5
0
def test_scheduler_metrics():
    cfg_fac = fac.ConfigFactory()
    cfg = cfg_fac.make_config(config_path='./test/config_1.yaml')

    conn_fac = db_fac.DatabaseConnectionFactory()
    conn = conn_fac.make_connection()

    scheduler = sched.Scheduler(
        cfg=cfg,
        conn=conn,
    )

    resp = requests.get(url='https://zeekay.dev/404', )

    with pytest.raises(json.decoder.JSONDecodeError):
        scheduler._parse_result(
            resp=resp,
            timeout=False,
            metric_id='bar',
            component_id='bar',
        )
Example #6
0
def test_scheduler_observer_call():
    def _fake_callable():
        pass

    cfg_fac = fac.ConfigFactory()
    cfg = cfg_fac.make_config(config_path='./test/config_1.yaml')

    conn_fac = db_fac.DatabaseConnectionFactory()
    conn = conn_fac.make_connection()

    scheduler = sched.Scheduler(
        cfg=cfg,
        conn=conn,
    )

    obs = observer.Observer(
        name='schedule-observer-test',
        callback='404',
    )

    scheduler.register_observer(observer=obs)
    for obs in scheduler.observer:
        obs.call_by_callable(callable=_fake_callable)
Example #7
0
                    dest='config_path',
                    type=str)
parser.add_argument('--dev', action='store_true', dest='dev')
args = parser.parse_args()

if args.dev:
    commonutil.configure_default_logging(stdout_level=logging.DEBUG)

logger.info(f'starting in {"dev" if args.dev else "prod"} mode')

# make config
cfg_fac = cfg_fac.ConfigFactory()
cfg = cfg_fac.make_config(config_path=args.config_path)

# make connection
conn_fac = db_fac.DatabaseConnectionFactory()
conn = conn_fac.make_connection()

# db operations
db_ops = common.database.operations.DatabaseOperator(connection=conn)

# write config to database
db_ops.insert_config(cfg=cfg)

# init scheduler
scheduler = scheduler.Scheduler(
    cfg=cfg,
    conn=conn,
)

# init event loop
Example #8
0
def test_db_conn_kill():
    fac = factory.DatabaseConnectionFactory()
    conn = fac.make_connection()
    conn.kill()