| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 1 | import http |
| 2 | import pytest |
| 3 | |
| 4 | from osm_common.fsbase import FsBase, FsException |
| 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 "storage 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 fs_base(): |
| 13 | return FsBase() |
| 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 | fs_base = FsBase() |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 18 | assert fs_base is not None |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 19 | assert isinstance(fs_base, FsBase) |
| 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_get_params(fs_base): |
| 23 | params = fs_base.get_params() |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 24 | assert isinstance(params, dict) |
| 25 | assert len(params) == 0 |
| 26 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 27 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 28 | def test_fs_connect(fs_base): |
| 29 | fs_base.fs_connect(None) |
| 30 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 31 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 32 | def test_fs_disconnect(fs_base): |
| 33 | fs_base.fs_disconnect() |
| 34 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 35 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 36 | def test_mkdir(fs_base): |
| 37 | with pytest.raises(FsException) as excinfo: |
| 38 | fs_base.mkdir(None) |
| 39 | assert str(excinfo.value).startswith(exception_message("Method 'mkdir' not implemented")) |
| 40 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |
| 41 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 42 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 43 | def test_file_exists(fs_base): |
| 44 | with pytest.raises(FsException) as excinfo: |
| 45 | fs_base.file_exists(None) |
| 46 | assert str(excinfo.value).startswith(exception_message("Method 'file_exists' not implemented")) |
| 47 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |
| 48 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 49 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 50 | def test_file_size(fs_base): |
| 51 | with pytest.raises(FsException) as excinfo: |
| 52 | fs_base.file_size(None) |
| 53 | assert str(excinfo.value).startswith(exception_message("Method 'file_size' not implemented")) |
| 54 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |
| 55 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 56 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 57 | def test_file_extract(fs_base): |
| 58 | with pytest.raises(FsException) as excinfo: |
| 59 | fs_base.file_extract(None, None) |
| 60 | assert str(excinfo.value).startswith(exception_message("Method 'file_extract' not implemented")) |
| 61 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |
| 62 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 63 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 64 | def test_file_open(fs_base): |
| 65 | with pytest.raises(FsException) as excinfo: |
| 66 | fs_base.file_open(None, None) |
| 67 | assert str(excinfo.value).startswith(exception_message("Method 'file_open' not implemented")) |
| 68 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |
| 69 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 70 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 71 | def test_file_delete(fs_base): |
| 72 | with pytest.raises(FsException) as excinfo: |
| 73 | fs_base.file_delete(None, None) |
| 74 | assert str(excinfo.value).startswith(exception_message("Method 'file_delete' not implemented")) |
| 75 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |