|
| 1 | +import pytest |
| 2 | + |
| 3 | +import bookstack |
| 4 | + |
| 5 | + |
| 6 | +# TODO |
| 7 | +# Tests will not work when you run them. This is why. |
| 8 | +# |
| 9 | +# Fixtures are defined in conftest.py; however, conftest.py is currently |
| 10 | +# listed in .gitignore. Therefore, it will be unavailable until |
| 11 | +# I redact sensitive information from the VCR.py casettes. |
| 12 | + |
| 13 | + |
| 14 | +class TestBookStack: |
| 15 | + @staticmethod |
| 16 | + def test_intiialize_empty(): |
| 17 | + with pytest.raises(TypeError): |
| 18 | + bookstack.BookStack() # pylint: disable=no-value-for-parameter |
| 19 | + |
| 20 | + @staticmethod |
| 21 | + @pytest.mark.parametrize( |
| 22 | + "base_url, token_id, token_secret", [ |
| 23 | + ( |
| 24 | + 'https://example.com', |
| 25 | + 'abc123', |
| 26 | + 'def456' |
| 27 | + ) |
| 28 | + ] |
| 29 | + ) |
| 30 | + def test_intiialize(base_url, token_id, token_secret): |
| 31 | + kwargs = { |
| 32 | + 'base_url': base_url, |
| 33 | + 'token_id': token_id, |
| 34 | + 'token_secret': token_secret |
| 35 | + } |
| 36 | + |
| 37 | + test_result = bookstack.BookStack(**kwargs) |
| 38 | + |
| 39 | + assert base_url in test_result.api_base_url |
| 40 | + assert token_id == token_id |
| 41 | + assert token_secret == token_secret |
| 42 | + |
| 43 | + # @staticmethod |
| 44 | + # @pytest.mark.vcr() |
| 45 | + # def test_get_docs(fixture_bookstack): |
| 46 | + # test_result = fixture_bookstack._get_docs() |
| 47 | + |
| 48 | + # assert test_result |
| 49 | + # assert isinstance(test_result, dict) |
| 50 | + # assert all(key in test_result.keys() for key in ['docs']) |
| 51 | + |
| 52 | + @staticmethod |
| 53 | + # @pytest.mark.vcr() |
| 54 | + def test_api(fixture_bookstack): |
| 55 | + test_result = fixture_bookstack._api |
| 56 | + |
| 57 | + assert isinstance(test_result, bookstack.models.API) |
| 58 | + |
| 59 | + @staticmethod |
| 60 | + def test_methods(fixture_bookstack): |
| 61 | + test_result = fixture_bookstack.methods() |
| 62 | + |
| 63 | + assert 'books_export_plain_text' in test_result |
| 64 | + assert '_create_methods' not in test_result |
| 65 | + |
| 66 | + @staticmethod |
| 67 | + def test_reset_api(fixture_bookstack): |
| 68 | + raise NotImplementedError |
| 69 | + |
| 70 | + @staticmethod |
| 71 | + @pytest.mark.vcr() |
| 72 | + def test_get_books(fixture_bookstack): |
| 73 | + test_result = fixture_bookstack.get_books() |
| 74 | + |
| 75 | + assert test_result |
| 76 | + assert isinstance(test_result, dict) |
| 77 | + assert all(key in test_result.keys() for key in ['data', 'total']) |
| 78 | + |
| 79 | + @staticmethod |
| 80 | + @pytest.mark.vcr() |
| 81 | + def test_read_book(fixture_bookstack): |
| 82 | + test_result = fixture_bookstack.read_book(1) |
| 83 | + |
| 84 | + assert test_result |
| 85 | + assert isinstance(test_result, dict) |
| 86 | + assert all(key in test_result.keys() |
| 87 | + for key in ['id', 'name','slug']) |
| 88 | + |
| 89 | + @staticmethod |
| 90 | + @pytest.mark.vcr() |
| 91 | + def test_export_text(fixture_bookstack): |
| 92 | + test_result = fixture_bookstack.export_text(1) |
| 93 | + |
| 94 | + assert test_result |
| 95 | + assert isinstance(test_result, str) |
| 96 | + |
| 97 | + @staticmethod |
| 98 | + @pytest.mark.vcr() |
| 99 | + def test_export_html(fixture_bookstack): |
| 100 | + test_result = fixture_bookstack.export_html(1) |
| 101 | + |
| 102 | + assert test_result |
| 103 | + assert isinstance(test_result, str) |
| 104 | + |
| 105 | + |
| 106 | +class TestAPI: |
| 107 | + @staticmethod |
| 108 | + def test_intiialize_empty(): |
| 109 | + with pytest.raises(TypeError): |
| 110 | + bookstack.models.API() # pylint: disable=no-value-for-parameter |
| 111 | + |
| 112 | + @staticmethod |
| 113 | + def test_initialize(api_info): |
| 114 | + test_result = bookstack.models.API(api_info) |
| 115 | + |
| 116 | + assert test_result |
| 117 | + |
0 commit comments