EOX GitLab Instance

Skip to content
Snippets Groups Projects
Commit e633b466 authored by Fabian Schindler's avatar Fabian Schindler
Browse files

Adding first tests

parent 91ecbd99
No related branches found
No related tags found
No related merge requests found
......@@ -165,7 +165,7 @@ def _get_handlers(config, name):
handlers.append(
handler_cls(
*handler_def.get("args", []),
**handler_def.get("kwargs", []),
**handler_def.get("kwargs", {}),
)
)
......
import pytest
from registrar.backend import get_backends
from registrar.registrar import register_item, register_path
from testapp.backends import MyItemBackend, MyPathBackend
from testapp import handlers
TEST_ITEM = """{
"type": "Feature",
"stac_version": "1.0",
"id": "test",
"geometry": null,
"properties": {
"datetime": "2021-11-3T00:00:00Z"
},
"links": {
},
"assets": {
}
}"""
def test_get_backends():
config = {
"sources": [
{
"name": "my-local-source",
"type": "local",
"kwargs": {"root_directory": "/opt/data"},
}
],
"backends": [
{"path": "testapp.backends.MyItemBackend", "kwargs": {"exists": True}}
],
}
backends = get_backends(config)
assert len(backends) == 1
assert isinstance(backends[0], MyItemBackend)
assert backends[0].exists
def test_register_item(mocker):
mocker.patch("testapp.backends.MyItemBackend.item_exists")
mocker.patch("testapp.backends.MyItemBackend.register_item")
config = {
"sources": [
{
"name": "my-local-source",
"type": "local",
"kwargs": {"root_directory": "/opt/data"},
}
],
"backends": [
{"path": "testapp.backends.MyItemBackend", "kwargs": {"exists": True}}
],
}
register_item(config, TEST_ITEM, True)
MyItemBackend.item_exists.assert_called_once()
MyItemBackend.register_item.assert_called_once()
def test_handlers(mocker):
mocker.patch("testapp.handlers.pre_handler.__call__")
mocker.patch("testapp.handlers.post_handler.__call__")
mocker.patch("testapp.handlers.error_handler.__call__")
config = {
"sources": [
{
"name": "my-local-source",
"type": "local",
"kwargs": {"root_directory": "/opt/data"},
}
],
"backends": [],
"pre_handlers": [{"path": "testapp.handlers.pre_handler"}],
"post_handlers": [{"path": "testapp.handlers.post_handler"}],
"error_handlers": [{"path": "testapp.handlers.error_handler"}],
}
register_item(config, TEST_ITEM, False)
handlers.pre_handler.__call__.assert_called_once()
def test_skeleton():
assert True
from typing import Optional
from pystac import Item
from registrar.backend.abc import PathBackend, ItemBackend
from registrar.source import Source
class MyPathBackend(PathBackend):
def __init__(self, exists: False):
self.exists = exists
def path_exists(self, source: Optional[Source], path: str) -> bool:
return self.exists
def register_path(self, source: Optional[Source], path: str, replace: bool):
...
def deregister_path(self, source: Optional[Source], path: str) -> Optional[str]:
return path
class MyItemBackend(ItemBackend):
def __init__(self, exists: False):
self.exists = exists
def item_exists(self, source: Optional[Source], item: "Item") -> bool:
return self.exists
def register_item(self, source: Optional[Source], item: "Item", replace: bool):
...
def deregister_identifier(self, identifier: str) -> Optional[str]:
return identifier
class pre_handler():
def __call__(self, *args, **kwargs):
pass
class post_handler():
def __call__(self, *args, **kwargs):
pass
class error_handler():
def __call__(self, *args, **kwargs):
pass
class path_pre_handler():
def __call__(self, *args, **kwargs):
pass
class path_post_handler():
def __call__(self, *args, **kwargs):
pass
class path_error_handler():
def __call__(self, *args, **kwargs):
pass
class deregister_pre_handler():
def __call__(self, *args, **kwargs):
pass
class deregister_post_handler():
def __call__(self, *args, **kwargs):
pass
class deregister_error_handler():
def __call__(self, *args, **kwargs):
pass
class deregister_path_pre_handler():
def __call__(self, *args, **kwargs):
pass
class deregister_path_post_handler():
def __call__(self, *args, **kwargs):
pass
class deregister_path_error_handler():
def __call__(self, *args, **kwargs):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment