8000 Merge branch 'dynamic_requests' into develop · coffeepenbit/bookstack@2443d00 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 2443d00

Browse files
committed
Merge branch 'dynamic_requests' into develop
2 parents 88016f9 + 044dba0 commit 2443d00

File tree

3 files changed

+129
-10
lines changed

3 files changed

+129
-10
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Project specific
2-
tests/
2+
tests/*
3+
!tests/test_models.py
34

45
# Byte-compiled / optimized / DLL files
56
__pycache__/

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# bookstack
2-
version: 0.1.0-alpha.2
2+
*version: 0.1.0-alpha.2*
3+
4+
**Please note that this project is currently in an unstable state. Please be patient.**
35

46
A Python wrapper for [BookStack's](https://www.bookstackapp.com) API
57

@@ -8,22 +10,21 @@ To install `bookstack`, run:
810

911
`pip install bookstack`
1012

11-
# Usage
13+
# Setup
1214
To use BookStack's API, you'll need to get a token ID and secret.
1315

1416
You can find how to get these values from your BookStack instance's doc page at `http[s]://<example.com>/api/docs`
1517

18+
# Usage
19+
Once you've acquired your token ID and secret, you're ready to rock.
20+
1621
```python
1722
import bookstack
1823

1924
# Input the appropriate values for these three variables
2025
base_url = 'http[s]://<example.com>'
2126
token_id = '<token_id>'
22-
token_secret = '<token_secret'>
23-
24-
api = bookstack.BookStack(base_url, token_id=<token_id>, token_secret=<token_secret>)
25-
```
27+
token_secret = '<token_secret>'
2628

27-
## TODO
28-
- Documentation
29-
- Remove `tests` directory from `.gitignore`
29+
api = bookstack.BookStack(base_url, token_id=token_id, token_secret=token_secret)
30+
```

tests/test_models.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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

Comments
 (0)
0