diff options
Diffstat (limited to 'templates')
6 files changed, 48 insertions, 15 deletions
diff --git a/templates/cookiecutter.json b/templates/cookiecutter.json new file mode 100644 index 0000000..c4afdd6 --- /dev/null +++ b/templates/cookiecutter.json @@ -0,0 +1,8 @@ +{ + "services_dir": "services", + "tests_dir": "tests", + "service_slug": "service", + "aglsystemdservice": "agl-service-something", + "classname": "NewService", + "api": "serviceapi" +} diff --git a/templates/service/cookiecutter.json b/templates/service/cookiecutter.json deleted file mode 100644 index f37ea1f..0000000 --- a/templates/service/cookiecutter.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "aglsystemdservice": "agl-service-something", - "classname": "NewService", - "api": "serviceapi", - "verblist": ["subscribe", "unsubscribe"] -}
\ No newline at end of file diff --git a/templates/service/{{cookiecutter.file_name}}.py b/templates/service/{{cookiecutter.file_name}}.py deleted file mode 100644 index 6defd28..0000000 --- a/templates/service/{{cookiecutter.file_name}}.py +++ /dev/null @@ -1,9 +0,0 @@ -from aglbaseservice import AGLBaseService, AFBResponse -import asyncio -import os - -class {{cookiecutter.classname}}(AGLBaseService): - - def __init__(self, ip, port=None, service='{{cookiecutter.aglsystemdservice}}'): - super().__init__(api='{{cookiecutter.api}}', ip=ip, port=port, service=service) - diff --git a/templates/test/{{cookiecutter.file_name}}.py b/templates/test/{{cookiecutter.file_name}}.py deleted file mode 100644 index e69de29..0000000 --- a/templates/test/{{cookiecutter.file_name}}.py +++ /dev/null diff --git a/templates/{{cookiecutter.services_dir}}/{{cookiecutter.service_slug}}.py b/templates/{{cookiecutter.services_dir}}/{{cookiecutter.service_slug}}.py new file mode 100644 index 0000000..dab3a68 --- /dev/null +++ b/templates/{{cookiecutter.services_dir}}/{{cookiecutter.service_slug}}.py @@ -0,0 +1,17 @@ +from pyagl.services.base import AGLBaseService, AFBResponse +import asyncio +import os + + +class {{cookiecutter.classname}}(AGLBaseService): + service = '{{cookiecutter.aglsystemdservice}}' + parser = AGLBaseService.getparser() + + def __init__(self, ip, port=None, service='{{cookiecutter.aglsystemdservice}}'): + super().__init__(api='{{cookiecutter.api}}', ip=ip, port=port, service=service) + # more init stuff specific to the new service + +async def main(loop): + args = {{cookiecutter.classname}}.parser.parse_args() + svc = {{cookiecutter.classname}}(args.ipaddr) + diff --git a/templates/{{cookiecutter.tests_dir}}/test_{{cookiecutter.service_slug}}.py b/templates/{{cookiecutter.tests_dir}}/test_{{cookiecutter.service_slug}}.py new file mode 100644 index 0000000..e193205 --- /dev/null +++ b/templates/{{cookiecutter.tests_dir}}/test_{{cookiecutter.service_slug}}.py @@ -0,0 +1,23 @@ +import asyncio +import os +import pytest +import logging +from pyagl.services.base import AFBResponse, AFBT +from concurrent.futures import TimeoutError + +from pyagl.services.{{cookiecutter.service_slug}} import {{cookiecutter.classname}} +pytestmark = pytest.mark.asyncio + +@pytest.fixture(scope='module') +def event_loop(): + loop = asyncio.get_event_loop() + yield loop + loop.close() + +@pytest.fixture(scope='module') +async def service(): + address = os.environ.get('AGL_TGT_IP', 'localhost') + port = os.environ.get('AGL_TGT_PORT', None) + svc = await {{cookiecutter.classname}}(ip=address, port=port) + yield svc + await svc.websocket.close() |