| 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 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame^] | 6 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 7 | def exception_message(message): |
| 8 | return "database exception " + message |
| 9 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame^] | 10 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 11 | @pytest.fixture |
| 12 | def db_base(): |
| 13 | return DbBase() |
| 14 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame^] | 15 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 16 | def test_constructor(): |
| 17 | db_base = DbBase() |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame^] | 18 | assert db_base is not None |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 19 | assert isinstance(db_base, DbBase) |
| 20 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame^] | 21 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 22 | def test_db_connect(db_base): |
| 23 | db_base.db_connect(None) |
| 24 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame^] | 25 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 26 | def test_db_disconnect(db_base): |
| 27 | db_base.db_disconnect() |
| 28 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame^] | 29 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 30 | def 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 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame^] | 36 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 37 | def 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 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame^] | 43 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 44 | def 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 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame^] | 50 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 51 | def 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 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame^] | 57 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 58 | def 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 |