| 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 | ## |
| Gulsum Atici | a06b854 | 2023-05-09 13:42:13 +0300 | [diff] [blame^] | 19 | import asyncio |
| 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.msgbase import MsgBase, MsgException |
| 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 | |
| 25 | |
| 26 | def exception_message(message): |
| 27 | return "messaging 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 msg_base(): |
| 32 | return MsgBase() |
| 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 | msgbase = MsgBase() |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 37 | assert msgbase is not None |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 38 | assert isinstance(msgbase, MsgBase) |
| 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_connect(msg_base): |
| Eduardo Sousa | 5ffda64 | 2018-05-09 19:42:00 +0100 | [diff] [blame] | 42 | msg_base.connect(None) |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 43 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 44 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 45 | def test_disconnect(msg_base): |
| 46 | msg_base.disconnect() |
| 47 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 48 | |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 49 | def test_write(msg_base): |
| 50 | with pytest.raises(MsgException) as excinfo: |
| 51 | msg_base.write("test", "test", "test") |
| garciadeblas | 2644b76 | 2021-03-24 09:21:01 +0100 | [diff] [blame] | 52 | assert str(excinfo.value).startswith( |
| 53 | exception_message("Method 'write' not implemented") |
| 54 | ) |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 55 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |
| 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_read(msg_base): |
| 59 | with pytest.raises(MsgException) as excinfo: |
| 60 | msg_base.read("test") |
| garciadeblas | 2644b76 | 2021-03-24 09:21:01 +0100 | [diff] [blame] | 61 | assert str(excinfo.value).startswith( |
| 62 | exception_message("Method 'read' not implemented") |
| 63 | ) |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 64 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |
| 65 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 66 | |
| Gulsum Atici | a06b854 | 2023-05-09 13:42:13 +0300 | [diff] [blame^] | 67 | def test_aiowrite(msg_base): |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 68 | with pytest.raises(MsgException) as excinfo: |
| Gulsum Atici | a06b854 | 2023-05-09 13:42:13 +0300 | [diff] [blame^] | 69 | asyncio.run(msg_base.aiowrite("test", "test", "test")) |
| garciadeblas | 2644b76 | 2021-03-24 09:21:01 +0100 | [diff] [blame] | 70 | assert str(excinfo.value).startswith( |
| 71 | exception_message("Method 'aiowrite' not implemented") |
| 72 | ) |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 73 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |
| 74 | |
| tierno | b20a902 | 2018-05-22 12:07:05 +0200 | [diff] [blame] | 75 | |
| Gulsum Atici | a06b854 | 2023-05-09 13:42:13 +0300 | [diff] [blame^] | 76 | def test_aioread(msg_base): |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 77 | with pytest.raises(MsgException) as excinfo: |
| Gulsum Atici | a06b854 | 2023-05-09 13:42:13 +0300 | [diff] [blame^] | 78 | asyncio.run(msg_base.aioread("test")) |
| garciadeblas | 2644b76 | 2021-03-24 09:21:01 +0100 | [diff] [blame] | 79 | assert str(excinfo.value).startswith( |
| 80 | exception_message("Method 'aioread' not implemented") |
| 81 | ) |
| Eduardo Sousa | 4d611d3 | 2018-05-09 19:20:37 +0100 | [diff] [blame] | 82 | assert excinfo.value.http_code == http.HTTPStatus.INTERNAL_SERVER_ERROR |