blob: dec65a84c6bc8abb203531458f4a11a66e7cff2a [file] [log] [blame]
Eduardo Sousa4d611d32018-05-09 19:20:37 +01001import http
2import pytest
3
4from osm_common.dbbase import DbBase, DbException
5
6def exception_message(message):
7 return "database exception " + message
8
9@pytest.fixture
10def db_base():
11 return DbBase()
12
13def test_constructor():
14 db_base = DbBase()
15
16 assert db_base != None
17 assert isinstance(db_base, DbBase)
18
19def test_db_connect(db_base):
20 db_base.db_connect(None)
21
22def test_db_disconnect(db_base):
23 db_base.db_disconnect()
24
25def test_get_list(db_base):
26 with pytest.raises(DbException) as excinfo:
27 db_base.get_list(None, None)
28 assert str(excinfo.value).startswith(exception_message("Method 'get_list' not implemented"))
29 assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
30
31def test_get_one(db_base):
32 with pytest.raises(DbException) as excinfo:
33 db_base.get_one(None, None, None, None)
34 assert str(excinfo.value).startswith(exception_message("Method 'get_one' not implemented"))
35 assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
36
37def test_create(db_base):
38 with pytest.raises(DbException) as excinfo:
39 db_base.create(None, None)
40 assert str(excinfo.value).startswith(exception_message("Method 'create' not implemented"))
41 assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
42
43def test_del_list(db_base):
44 with pytest.raises(DbException) as excinfo:
45 db_base.del_list(None, None)
46 assert str(excinfo.value).startswith(exception_message("Method 'del_list' not implemented"))
47 assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
48
49def test_del_one(db_base):
50 with pytest.raises(DbException) as excinfo:
51 db_base.del_one(None, None, None)
52 assert str(excinfo.value).startswith(exception_message("Method 'del_one' not implemented"))
53 assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND