Adding tests for base classes 07/6107/2
authorEduardo Sousa <eduardosousa@av.it.pt>
Wed, 9 May 2018 18:20:37 +0000 (19:20 +0100)
committerEduardo Sousa <eduardosousa@av.it.pt>
Mon, 14 May 2018 13:19:40 +0000 (14:19 +0100)
Change-Id: Ic5c482838d77e8dd16ea913a1caa35ed10a53739
Signed-off-by: Eduardo Sousa <eduardosousa@av.it.pt>
osm_common/tests/test_dbbase.py [new file with mode: 0644]
osm_common/tests/test_fsbase.py [new file with mode: 0644]
osm_common/tests/test_msgbase.py [new file with mode: 0644]

diff --git a/osm_common/tests/test_dbbase.py b/osm_common/tests/test_dbbase.py
new file mode 100644 (file)
index 0000000..dec65a8
--- /dev/null
@@ -0,0 +1,53 @@
+import http
+import pytest
+
+from osm_common.dbbase import DbBase, DbException
+
+def exception_message(message):
+    return "database exception " + message
+
+@pytest.fixture
+def db_base():
+    return DbBase()
+
+def test_constructor():
+    db_base = DbBase()
+
+    assert db_base != None
+    assert isinstance(db_base, DbBase)
+
+def test_db_connect(db_base):
+    db_base.db_connect(None)
+
+def test_db_disconnect(db_base):
+    db_base.db_disconnect()
+
+def test_get_list(db_base):
+    with pytest.raises(DbException) as excinfo:
+        db_base.get_list(None, None)
+    assert str(excinfo.value).startswith(exception_message("Method 'get_list' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
+
+def test_get_one(db_base):
+    with pytest.raises(DbException) as excinfo:
+        db_base.get_one(None, None, None, None)
+    assert str(excinfo.value).startswith(exception_message("Method 'get_one' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
+
+def test_create(db_base):
+    with pytest.raises(DbException) as excinfo:
+        db_base.create(None, None)
+    assert str(excinfo.value).startswith(exception_message("Method 'create' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
+
+def test_del_list(db_base):
+    with pytest.raises(DbException) as excinfo:
+        db_base.del_list(None, None)
+    assert str(excinfo.value).startswith(exception_message("Method 'del_list' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
+
+def test_del_one(db_base):
+    with pytest.raises(DbException) as excinfo:
+        db_base.del_one(None, None, None)
+    assert str(excinfo.value).startswith(exception_message("Method 'del_one' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
diff --git a/osm_common/tests/test_fsbase.py b/osm_common/tests/test_fsbase.py
new file mode 100644 (file)
index 0000000..a789297
--- /dev/null
@@ -0,0 +1,65 @@
+import http
+import pytest
+
+from osm_common.fsbase import FsBase, FsException
+
+def exception_message(message):
+    return "storage exception " + message
+
+@pytest.fixture
+def fs_base():
+    return FsBase()
+
+def test_constructor():
+    fs_base = FsBase()
+
+    assert fs_base != None
+    assert isinstance(fs_base, FsBase)
+
+def test_get_params(fs_base):
+    params = fs_base.get_params()
+
+    assert isinstance(params, dict)
+    assert len(params) == 0
+
+def test_fs_connect(fs_base):
+    fs_base.fs_connect(None)
+
+def test_fs_disconnect(fs_base):
+    fs_base.fs_disconnect()
+
+def test_mkdir(fs_base):
+    with pytest.raises(FsException) as excinfo:
+        fs_base.mkdir(None)
+    assert str(excinfo.value).startswith(exception_message("Method 'mkdir' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
+
+def test_file_exists(fs_base):
+    with pytest.raises(FsException) as excinfo:
+        fs_base.file_exists(None)
+    assert str(excinfo.value).startswith(exception_message("Method 'file_exists' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
+
+def test_file_size(fs_base):
+    with pytest.raises(FsException) as excinfo:
+        fs_base.file_size(None)
+    assert str(excinfo.value).startswith(exception_message("Method 'file_size' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
+
+def test_file_extract(fs_base):
+    with pytest.raises(FsException) as excinfo:
+        fs_base.file_extract(None, None)
+    assert str(excinfo.value).startswith(exception_message("Method 'file_extract' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
+
+def test_file_open(fs_base):
+    with pytest.raises(FsException) as excinfo:
+        fs_base.file_open(None, None)
+    assert str(excinfo.value).startswith(exception_message("Method 'file_open' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
+
+def test_file_delete(fs_base):
+    with pytest.raises(FsException) as excinfo:
+        fs_base.file_delete(None, None)
+    assert str(excinfo.value).startswith(exception_message("Method 'file_delete' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
diff --git a/osm_common/tests/test_msgbase.py b/osm_common/tests/test_msgbase.py
new file mode 100644 (file)
index 0000000..c3b9726
--- /dev/null
@@ -0,0 +1,48 @@
+import http
+import pytest
+
+from osm_common.msgbase import MsgBase, MsgException
+
+
+def exception_message(message):
+    return "messaging exception " + message
+
+@pytest.fixture
+def msg_base():
+    return MsgBase()
+
+def test_constructor():
+    msgbase = MsgBase()
+
+    assert msgbase != None
+    assert isinstance(msgbase, MsgBase)
+
+def test_connect(msg_base):
+    msg_base.connect()
+
+def test_disconnect(msg_base):
+    msg_base.disconnect()
+
+def test_write(msg_base):
+    with pytest.raises(MsgException) as excinfo:
+        msg_base.write("test", "test", "test")
+    assert str(excinfo.value).startswith(exception_message("Method 'write' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
+
+def test_read(msg_base):
+    with pytest.raises(MsgException) as excinfo:
+        msg_base.read("test")
+    assert str(excinfo.value).startswith(exception_message("Method 'read' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
+
+def test_aiowrite(msg_base, event_loop):
+    with pytest.raises(MsgException) as excinfo:
+        event_loop.run_until_complete(msg_base.aiowrite("test", "test", "test", event_loop))
+    assert str(excinfo.value).startswith(exception_message("Method 'aiowrite' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
+
+def test_aioread(msg_base, event_loop):
+    with pytest.raises(MsgException) as excinfo:
+        event_loop.run_until_complete(msg_base.aioread("test", event_loop))
+    assert str(excinfo.value).startswith(exception_message("Method 'aioread' not implemented"))
+    assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR