test_backends.py 1.17 KB
Newer Older
Michael Thies's avatar
Michael Thies committed
1
from typing import List
2
3
import unittest

4
from aas.backend import backends
Michael Thies's avatar
Michael Thies committed
5
from aas.model import Referable
6
7


Michael Thies's avatar
Michael Thies committed
8
9
class ExampleBackend(backends.Backend):
    @classmethod
10
    def commit_object(cls, committed_object: Referable, store_object: Referable, relative_path: List[str]) -> None:
Michael Thies's avatar
Michael Thies committed
11
12
13
        raise NotImplementedError("This is a mock")

    @classmethod
14
    def update_object(cls, updated_object: Referable, store_object: Referable, relative_path: List[str]) -> None:
Michael Thies's avatar
Michael Thies committed
15
16
17
        raise NotImplementedError("This is a mock")


18
19
class BackendsTest(unittest.TestCase):
    def test_backend_store(self):
Michael Thies's avatar
Michael Thies committed
20
21
        backends.register_backend("mockScheme", ExampleBackend)
        self.assertIs(backends.get_backend("mockScheme:x-test:test_backend"), ExampleBackend)
22

Michael Thies's avatar
Michael Thies committed
23
24
25
26
        backends.register_backend("<this is totally a valid uri>", ExampleBackend)
        with self.assertRaises(ValueError) as cm:
            backends.get_backend("<this is totally a valid uri>")
        self.assertEqual("<this is totally a valid uri> is not a valid URL with URI scheme.", str(cm.exception))
27

Michael Thies's avatar
Michael Thies committed
28
29
        with self.assertRaises(backends.UnknownBackendException):
            backends.get_backend("some-unkown-scheme://example.com")