Skip to content

Commit 0336ca4

Browse files
committed
doc: minor documentation tweaks
Also, index.rst is a bit more user friendy.
1 parent 374a8e3 commit 0336ca4

5 files changed

Lines changed: 107 additions & 21 deletions

File tree

doc/api.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
API documentation
2+
=================
3+
4+
.. automodule:: pytest_httpserver
5+
6+
.. autoclass:: HTTPServer
7+
:members:
8+
9+
.. automodule:: pytest_httpserver.httpserver
10+
11+
.. autoclass:: RequestMatcher
12+
:members:
13+
14+
.. autoclass:: pytest_httpserver.httpserver.Error
15+
:members:
16+
17+
.. autoclass:: pytest_httpserver.httpserver.NoHandlerError
18+
:members:
19+
20+
.. autoclass:: pytest_httpserver.httpserver.HTTPServerError
21+
:members:
22+
23+
.. autoclass:: pytest_httpserver.httpserver.RequestMatcher
24+
:members:
25+
26+
.. autoclass:: pytest_httpserver.httpserver.RequestHandler
27+
:members:
28+
29+
.. autoclass:: pytest_httpserver.httpserver.RequestHandlerList
30+
:members:
31+

doc/conf.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,29 @@
8383
# The theme to use for HTML and HTML Help pages. See the documentation for
8484
# a list of builtin themes.
8585
#
86-
html_theme = 'alabaster'
86+
html_theme = 'sphinx_rtd_theme'
8787

8888
# Theme options are theme-specific and customize the look and feel of a theme
8989
# further. For a list of options available for each theme, see the
9090
# documentation.
9191
#
9292
# html_theme_options = {}
9393

94+
html_theme_options = {
95+
'canonical_url': '',
96+
'analytics_id': '',
97+
'logo_only': False,
98+
'display_version': True,
99+
'prev_next_buttons_location': 'bottom',
100+
'style_external_links': False,
101+
# Toc options
102+
'collapse_navigation': True,
103+
'sticky_navigation': True,
104+
'navigation_depth': 4,
105+
'includehidden': True,
106+
'titles_only': False
107+
}
108+
94109
# Add any paths that contain custom static files (such as style sheets) here,
95110
# relative to this directory. They are copied after the builtin static files,
96111
# so a file named "default.css" will overwrite the builtin "default.css".
@@ -164,6 +179,3 @@
164179
author, 'pytest_httpserver', 'One line description of project.',
165180
'Miscellaneous'),
166181
]
167-
168-
169-

doc/index.rst

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,69 @@
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
6-
Welcome to pytest_httpserver's documentation!
7-
=============================================
6+
7+
User's Guide
8+
------------
9+
pytest-httpserver is a python package which allows you to start a real HTTP server
10+
for your tests. The server can be configured programmatically to how to respond to
11+
requests.
12+
13+
The aim of this project is to provide an easy to use API to start the server, configure
14+
the request handlers and then shut it down gracefully. All of these without touching
15+
a configuration file or dealing with daemons.
16+
17+
As the HTTP server is spawned in a different thread and listening on a TCP port, you
18+
can use any HTTP client. This library also helps you migrating to a different HTTP
19+
client library without the need to re-write any test for your client application.
20+
21+
This library can be used with pytest in the most convenient way but if you prefer to use
22+
other test frameworks, you can still use it with the context API or by writing a wrapper
23+
for it.
24+
25+
Example with pytest
26+
-------------------
27+
28+
.. code:: python
29+
30+
import requests
31+
32+
def test_json_client(httpserver: HTTPServer):
33+
httpserver.expect_request("/foobar").respond_with_json({"foo": "bar"})
34+
assert requests.get(httpserver.url_for("/foobar")).json() == {'foo': 'bar'}
35+
36+
37+
Example without pytest
38+
----------------------
39+
40+
.. code:: python
41+
42+
import requests
43+
import unittest
44+
from pytest_httpserver import HTTPServer
45+
46+
class TestJSONClient(unittest.TestCase):
47+
def setUp(self):
48+
self.httpserver = HTTPServer()
49+
self.httpserver.start()
50+
51+
def test_json_client(self):
52+
self.httpserver.expect_request("/foobar").respond_with_json({"foo": "bar"})
53+
self.assertEqual(requests.get(self.httpserver.url_for("/foobar")).json(), {'foo': 'bar'})
54+
55+
def tearDown(self):
56+
self.httpserver.stop()
57+
58+
59+
API Reference
60+
-------------
61+
62+
If you are looking for information on a specific function, class or
63+
method, this part of the documentation is for you.
864

965
.. toctree::
1066
:maxdepth: 2
11-
:caption: Contents:
67+
68+
api
1269

1370

1471

doc/modules.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

doc/pytest_httpserver.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)