Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/plsc/sync
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@
"given_name": null,
"id": 24598,
"name": "Sarah Cross",
"scoped_affiliation": null,
"scoped_affiliation": "member@surfstar-idp.lab.surf.nl, employee@surfstar-idp.lab.surf.nl, employee@surfstar-idp.lab.surf.nl",
"sram_inactive_days": 1,
"ssh_keys": [
"some-lame-key"
Expand Down
2 changes: 1 addition & 1 deletion sbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __get_json(string):
def __put_json(data):
return json.dumps(data)

def api(self, request, method='GET', headers=None, data=None):
def api(self, request: str, method='GET', headers=None, data=None):
class SBSNoContentException(Exception):
pass

Expand Down
27 changes: 15 additions & 12 deletions tests/base_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import TestCase

from aiohttp import web
from aiohttp import web_request

from sldap import SLdap
from sbs import SBS
Expand All @@ -20,10 +21,10 @@


class APIHandler:
def __init__(self):
def __init__(self) -> None:
logger.debug("Initializng API HANDLER !")

async def __call__(self, request):
async def __call__(self, request: web_request.BaseRequest) -> web.Response:
method = getattr(self, f'do_{request.method.lower()}', None)
if method is None:
raise web.HTTPNotImplemented()
Expand All @@ -34,7 +35,7 @@ async def __call__(self, request):
return result

@staticmethod
def do_get(request):
def do_get(request: web_request.BaseRequest) -> web.Response:
try:
with open(f".{request.path}", 'r') as f:
data = f.read()
Expand All @@ -50,6 +51,8 @@ def do_get(request):


class BaseTest(TestCase):
loop: asyncio.AbstractEventLoop | None
api: threading.Thread

src_conf = {
'recorder': (os.environ.get("SBS_API_RECORDING", "NO").upper() == "YES"),
Expand All @@ -69,10 +72,10 @@ class BaseTest(TestCase):
}

@classmethod
def setUpClass(cls):
def start_server(loop):
def setUpClass(cls) -> None:
def start_server(loop: asyncio.AbstractEventLoop) -> None:

async def init_api_server(handle, host, port):
async def init_api_server(handle: APIHandler, host: str, port: int) -> web.ServerRunner:
server = web.ServerRunner(web.Server(handle))
await server.setup()

Expand All @@ -99,7 +102,7 @@ async def init_api_server(handle, host, port):
finally:
loop.close()

def check_server():
def check_server() -> None:
logger.debug("BaseTest check_server")
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
Expand All @@ -119,15 +122,15 @@ def check_server():
cls.loop = None

@classmethod
def tearDownClass(cls):
def tearDownClass(cls) -> None:
if cls.loop:
logger.debug("BaseTest tearDownClass")
for task in asyncio.all_tasks(cls.loop):
task.cancel()
cls.loop.call_soon_threadsafe(cls.loop.stop)
cls.api.join()

def setUp(self):
def setUp(self) -> None:
""" Run a complete PLSC cycle, 1st ordered structure, 2nd flat structure...
"""

Expand All @@ -136,8 +139,8 @@ def setUp(self):
logger.debug(self.src_conf)
logger.debug(self.dst_conf)

self.src = SBS(self.src_conf)
self.dst = SLdap(self.dst_conf)
self.src: SBS = SBS(self.src_conf)
self.dst: SLdap = SLdap(self.dst_conf)

logger.info("Creating: Ordered structure...")
plsc_ordered.create(self.src, self.dst)
Expand All @@ -147,5 +150,5 @@ def setUp(self):
plsc_flat.create(self.dst, self.dst)
plsc_flat.cleanup(self.dst, self.dst)

def tearDown(self):
def tearDown(self) -> None:
logger.info("BaseTest tearDown")
2 changes: 1 addition & 1 deletion tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_ldap_services(self):
"""

def object_count(rdn):
""" Return the nur of objects that exists under this rdn
""" Return the number of objects that exists under this rdn
"""

logger.info(f"*** Object count LDAP: {rdn}")
Expand Down
Loading