| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 1 | import http |
| 2 | import pytest |
| 3 | |
| 4 | from osm_common.dbbase import DbBase, DbException |
| 5 | |
| 6 | def exception_message(message): |
| 7 | return "database exception " + message |
| 8 | |
| 9 | @pytest.fixture |
| 10 | def db_base(): |
| 11 | return DbBase() |
| 12 | |
| 13 | def test_constructor(): |
| 14 | db_base = DbBase() |
| 15 | |
| 16 | assert db_base != None |
| 17 | assert isinstance(db_base, DbBase) |
| 18 | |
| 19 | def test_db_connect(db_base): |
| 20 | db_base.db_connect(None) |
| 21 | |
| 22 | def test_db_disconnect(db_base): |
| 23 | db_base.db_disconnect() |
| 24 | |
| 25 | def 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 | |
| 31 | def 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 | |
| 37 | def 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 | |
| 43 | def 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 | |
| 49 | def 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 |