Skip to content

Commit

Permalink
Archive services integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nkongenelly committed Aug 9, 2024
1 parent fc239d9 commit 4421f55
Show file tree
Hide file tree
Showing 7 changed files with 421 additions and 57 deletions.
8 changes: 8 additions & 0 deletions arteria/handlers/archive_services_handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from aiohttp import web
from arteria.handlers.base import base_routes

archive_services_routes = web.RouteTableDef()



routes = [base_routes, archive_services_routes]
15 changes: 15 additions & 0 deletions arteria/services/archive_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import argparse

from aiohttp import web
from arteria.services.base_service import BaseService

parser = argparse.ArgumentParser(description="archive-services server")
parser.add_argument('--config_file')

base_service = BaseService()
def main():
config = base_service.get_config()
app = base_service.get_app(config)

web.run_app(app, port=config.get("port"))

48 changes: 4 additions & 44 deletions arteria/services/arteria_runfolder.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,15 @@
import yaml
import argparse
import logging.config

from aiohttp import web
from arteria.models.config import Config
from arteria.handlers.arteria_runfolder_handlers import routes

from arteria.services.base_service import BaseService

parser = argparse.ArgumentParser(description="arteria-runfolder server")
parser.add_argument('--config_file')


base_service = BaseService()
def main():
config = get_config()
app = get_app(config)
config = base_service.get_config()
app = base_service.get_app(config)

web.run_app(app, port=config.get("port"))


def get_config():
"""
Retrieves passed config file name
Loads the config dictionary to Config
"""
args = parser.parse_args()
config_file = args.config_file
return Config().from_yaml(config_file)


def get_app(config):
"""
Creates an Application instance
Sets up logger from configuration file specified in the config
Registers the request handler
"""
app = web.Application()
inistialize_logger(config)
[app.router.add_routes(route) for route in routes]
return app


def inistialize_logger(config):
"""
Sets up logger from configuration file
"""
logger_file = config.get("logger_config_file")
try:
# When config file has section headers i.e [version]..
logging.config.fileConfig(logger_file)
except RuntimeError:
# When config file has yaml format (without section headers)
with open(logger_file, 'r') as stream:
config = yaml.load(stream, Loader=yaml.FullLoader)
logging.config.dictConfig(config)
56 changes: 56 additions & 0 deletions arteria/services/base_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import yaml
import argparse
import logging.config

from aiohttp import web
from arteria.models.config import Config
from arteria.handlers.arteria_runfolder_handlers import routes


parser = argparse.ArgumentParser(description="arteria-runfolder server")
parser.add_argument('--config_file')


class BaseService:
def main(self):
config = self.get_config()
app = self.get_app(config)

web.run_app(app, port=config.get("port"))


def get_config(self):
"""
Retrieves passed config file name
Loads the config dictionary to Config
"""
args = parser.parse_args()
config_file = args.config_file
return Config().from_yaml(config_file)


def get_app(self, config):
"""
Creates an Application instance
Sets up logger from configuration file specified in the config
Registers the request handler
"""
app = web.Application()
self.inistialize_logger(config)
[app.router.add_routes(route) for route in routes]
return app


def inistialize_logger(self, config):
"""
Sets up logger from configuration file
"""
logger_file = config.get("logger_config_file")
try:
# When config file has section headers i.e [version]..
logging.config.fileConfig(logger_file)
except RuntimeError:
# When config file has yaml format (without section headers)
with open(logger_file, 'r') as stream:
config = yaml.load(stream, Loader=yaml.FullLoader)
logging.config.dictConfig(config)
14 changes: 14 additions & 0 deletions tests/fixtures/integration_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import tempfile

import pytest

from arteria.services.base_service import BaseService


@pytest.fixture()
async def client(aiohttp_client, config):
"""
Instantiate a web client with a specific config.
"""
base_service = BaseService()
return await aiohttp_client(base_service.get_app(config))
Loading

0 comments on commit 4421f55

Please sign in to comment.