| Eduardo Sousa | a011781 | 2019-02-05 15:57:09 +0000 | [diff] [blame] | 1 | # Copyright 2018 Whitestack, LLC |
| 2 | # Copyright 2018 Telefonica S.A. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | # |
| 16 | # For those usages not covered by the Apache License, Version 2.0 please |
| 17 | # contact: esousa@whitestack.com or alfonso.tiernosepulveda@telefonica.com |
| 18 | ## |
| 19 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 20 | import http |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 21 | |
| 22 | from osm_common.fsbase import FsBase, FsException |
| aticig | 3dd0db6 | 2022-03-04 19:35:45 +0300 | [diff] [blame^] | 23 | import pytest |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 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 exception_message(message): |
| 27 | return "storage exception " + message |
| 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 | @pytest.fixture |
| 31 | def fs_base(): |
| 32 | return FsBase() |
| 33 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 34 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 35 | def test_constructor(): |
| 36 | fs_base = FsBase() |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 37 | assert fs_base is not None |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 38 | assert isinstance(fs_base, FsBase) |
| 39 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 40 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 41 | def test_get_params(fs_base): |
| 42 | params = fs_base.get_params() |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 43 | assert isinstance(params, dict) |
| 44 | assert len(params) == 0 |
| 45 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 46 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 47 | def test_fs_connect(fs_base): |
| 48 | fs_base.fs_connect(None) |
| 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_fs_disconnect(fs_base): |
| 52 | fs_base.fs_disconnect() |
| 53 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 54 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 55 | def test_mkdir(fs_base): |
| 56 | with pytest.raises(FsException) as excinfo: |
| 57 | fs_base.mkdir(None) |
| garciadeblas | 2644b76 | 2021-03-24 09:21:01 +0100 | [diff] [blame] | 58 | assert str(excinfo.value).startswith( |
| 59 | exception_message("Method 'mkdir' not implemented") |
| 60 | ) |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 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_exists(fs_base): |
| 65 | with pytest.raises(FsException) as excinfo: |
| 66 | fs_base.file_exists(None) |
| garciadeblas | 2644b76 | 2021-03-24 09:21:01 +0100 | [diff] [blame] | 67 | assert str(excinfo.value).startswith( |
| 68 | exception_message("Method 'file_exists' not implemented") |
| 69 | ) |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 70 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |
| 71 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 72 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 73 | def test_file_size(fs_base): |
| 74 | with pytest.raises(FsException) as excinfo: |
| 75 | fs_base.file_size(None) |
| garciadeblas | 2644b76 | 2021-03-24 09:21:01 +0100 | [diff] [blame] | 76 | assert str(excinfo.value).startswith( |
| 77 | exception_message("Method 'file_size' not implemented") |
| 78 | ) |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 79 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |
| 80 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 81 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 82 | def test_file_extract(fs_base): |
| 83 | with pytest.raises(FsException) as excinfo: |
| 84 | fs_base.file_extract(None, None) |
| garciadeblas | 2644b76 | 2021-03-24 09:21:01 +0100 | [diff] [blame] | 85 | assert str(excinfo.value).startswith( |
| 86 | exception_message("Method 'file_extract' not implemented") |
| 87 | ) |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 88 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |
| 89 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 90 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 91 | def test_file_open(fs_base): |
| 92 | with pytest.raises(FsException) as excinfo: |
| 93 | fs_base.file_open(None, None) |
| garciadeblas | 2644b76 | 2021-03-24 09:21:01 +0100 | [diff] [blame] | 94 | assert str(excinfo.value).startswith( |
| 95 | exception_message("Method 'file_open' not implemented") |
| 96 | ) |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 97 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |
| 98 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 99 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 100 | def test_file_delete(fs_base): |
| 101 | with pytest.raises(FsException) as excinfo: |
| 102 | fs_base.file_delete(None, None) |
| garciadeblas | 2644b76 | 2021-03-24 09:21:01 +0100 | [diff] [blame] | 103 | assert str(excinfo.value).startswith( |
| 104 | exception_message("Method 'file_delete' not implemented") |
| 105 | ) |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 106 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |