blob: c2af52f6bcb1aeb78ac372b70ca07d386b693f72 [file] [log] [blame]
Eduardo Sousa4d611d32018-05-09 19:20:37 +01001import http
2import pytest
3
4from osm_common.dbbase import DbBase, DbException
5
tiernob20a9022018-05-22 12:07:05 +02006
Eduardo Sousa4d611d32018-05-09 19:20:37 +01007def exception_message(message):
8 return "database exception " + message
9
tiernob20a9022018-05-22 12:07:05 +020010
Eduardo Sousa4d611d32018-05-09 19:20:37 +010011@pytest.fixture
12def db_base():
13 return DbBase()
14
tiernob20a9022018-05-22 12:07:05 +020015
Eduardo Sousa4d611d32018-05-09 19:20:37 +010016def test_constructor():
17 db_base = DbBase()
tiernob20a9022018-05-22 12:07:05 +020018 assert db_base is not None
Eduardo Sousa4d611d32018-05-09 19:20:37 +010019 assert isinstance(db_base, DbBase)
20
tiernob20a9022018-05-22 12:07:05 +020021
Eduardo Sousa4d611d32018-05-09 19:20:37 +010022def test_db_connect(db_base):
23 db_base.db_connect(None)
24
tiernob20a9022018-05-22 12:07:05 +020025
Eduardo Sousa4d611d32018-05-09 19:20:37 +010026def test_db_disconnect(db_base):
27 db_base.db_disconnect()
28
tiernob20a9022018-05-22 12:07:05 +020029
Eduardo Sousa4d611d32018-05-09 19:20:37 +010030def test_get_list(db_base):
31 with pytest.raises(DbException) as excinfo:
32 db_base.get_list(None, None)
33 assert str(excinfo.value).startswith(exception_message("Method 'get_list' not implemented"))
34 assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
35
tiernob20a9022018-05-22 12:07:05 +020036
Eduardo Sousa4d611d32018-05-09 19:20:37 +010037def test_get_one(db_base):
38 with pytest.raises(DbException) as excinfo:
39 db_base.get_one(None, None, None, None)
40 assert str(excinfo.value).startswith(exception_message("Method 'get_one' not implemented"))
41 assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
42
tiernob20a9022018-05-22 12:07:05 +020043
Eduardo Sousa4d611d32018-05-09 19:20:37 +010044def test_create(db_base):
45 with pytest.raises(DbException) as excinfo:
46 db_base.create(None, None)
47 assert str(excinfo.value).startswith(exception_message("Method 'create' not implemented"))
48 assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
49
tiernob20a9022018-05-22 12:07:05 +020050
Eduardo Sousa4d611d32018-05-09 19:20:37 +010051def test_del_list(db_base):
52 with pytest.raises(DbException) as excinfo:
53 db_base.del_list(None, None)
54 assert str(excinfo.value).startswith(exception_message("Method 'del_list' not implemented"))
55 assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND
56
tiernob20a9022018-05-22 12:07:05 +020057
Eduardo Sousa4d611d32018-05-09 19:20:37 +010058def test_del_one(db_base):
59 with pytest.raises(DbException) as excinfo:
60 db_base.del_one(None, None, None)
61 assert str(excinfo.value).startswith(exception_message("Method 'del_one' not implemented"))
62 assert excinfo.value.http_code == http.HTTPStatus.NOT_FOUND