blob: 4decad08d0fcbb51dd42041ccc1cc5b0335e6b6b [file] [log] [blame]
Eduardo Sousaa0117812019-02-05 15:57:09 +00001# 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 Sousa4d611d32018-05-09 19:20:37 +010020import http
21import pytest
22
23from osm_common.fsbase import FsBase, FsException
24
tiernob20a9022018-05-22 12:07:05 +020025
Eduardo Sousa4d611d32018-05-09 19:20:37 +010026def exception_message(message):
27 return "storage exception " + message
28
tiernob20a9022018-05-22 12:07:05 +020029
Eduardo Sousa4d611d32018-05-09 19:20:37 +010030@pytest.fixture
31def fs_base():
32 return FsBase()
33
tiernob20a9022018-05-22 12:07:05 +020034
Eduardo Sousa4d611d32018-05-09 19:20:37 +010035def test_constructor():
36 fs_base = FsBase()
tiernob20a9022018-05-22 12:07:05 +020037 assert fs_base is not None
Eduardo Sousa4d611d32018-05-09 19:20:37 +010038 assert isinstance(fs_base, FsBase)
39
tiernob20a9022018-05-22 12:07:05 +020040
Eduardo Sousa4d611d32018-05-09 19:20:37 +010041def test_get_params(fs_base):
42 params = fs_base.get_params()
Eduardo Sousa4d611d32018-05-09 19:20:37 +010043 assert isinstance(params, dict)
44 assert len(params) == 0
45
tiernob20a9022018-05-22 12:07:05 +020046
Eduardo Sousa4d611d32018-05-09 19:20:37 +010047def test_fs_connect(fs_base):
48 fs_base.fs_connect(None)
49
tiernob20a9022018-05-22 12:07:05 +020050
Eduardo Sousa4d611d32018-05-09 19:20:37 +010051def test_fs_disconnect(fs_base):
52 fs_base.fs_disconnect()
53
tiernob20a9022018-05-22 12:07:05 +020054
Eduardo Sousa4d611d32018-05-09 19:20:37 +010055def test_mkdir(fs_base):
56 with pytest.raises(FsException) as excinfo:
57 fs_base.mkdir(None)
58 assert str(excinfo.value).startswith(exception_message("Method 'mkdir' not implemented"))
59 assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
60
tiernob20a9022018-05-22 12:07:05 +020061
Eduardo Sousa4d611d32018-05-09 19:20:37 +010062def test_file_exists(fs_base):
63 with pytest.raises(FsException) as excinfo:
64 fs_base.file_exists(None)
65 assert str(excinfo.value).startswith(exception_message("Method 'file_exists' not implemented"))
66 assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
67
tiernob20a9022018-05-22 12:07:05 +020068
Eduardo Sousa4d611d32018-05-09 19:20:37 +010069def test_file_size(fs_base):
70 with pytest.raises(FsException) as excinfo:
71 fs_base.file_size(None)
72 assert str(excinfo.value).startswith(exception_message("Method 'file_size' not implemented"))
73 assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
74
tiernob20a9022018-05-22 12:07:05 +020075
Eduardo Sousa4d611d32018-05-09 19:20:37 +010076def test_file_extract(fs_base):
77 with pytest.raises(FsException) as excinfo:
78 fs_base.file_extract(None, None)
79 assert str(excinfo.value).startswith(exception_message("Method 'file_extract' not implemented"))
80 assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
81
tiernob20a9022018-05-22 12:07:05 +020082
Eduardo Sousa4d611d32018-05-09 19:20:37 +010083def test_file_open(fs_base):
84 with pytest.raises(FsException) as excinfo:
85 fs_base.file_open(None, None)
86 assert str(excinfo.value).startswith(exception_message("Method 'file_open' not implemented"))
87 assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR
88
tiernob20a9022018-05-22 12:07:05 +020089
Eduardo Sousa4d611d32018-05-09 19:20:37 +010090def test_file_delete(fs_base):
91 with pytest.raises(FsException) as excinfo:
92 fs_base.file_delete(None, None)
93 assert str(excinfo.value).startswith(exception_message("Method 'file_delete' not implemented"))
94 assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR