Skip to content

Commit 9dbae9c

Browse files
authored
Merge pull request #99 from sphinx-contrib/renderer-declarative-tests
Add drop-in test infrastructure
2 parents a4036a1 + ed3ef9a commit 9dbae9c

21 files changed

+2407
-0
lines changed

tests/conftest.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
1+
import os
2+
import pathlib
13
import textwrap
4+
25
import pytest
6+
import yaml
37

48
from sphinx.application import Sphinx
9+
from sphinxcontrib.openapi import utils
10+
11+
12+
_testspecs_dir = pathlib.Path(os.path.dirname(__file__), "testspecs")
13+
_testspecs_v2_dir = _testspecs_dir.joinpath("v2.0")
14+
_testspecs_v3_dir = _testspecs_dir.joinpath("v3.0")
15+
16+
_testspecs = [str(path.relative_to(_testspecs_dir)) for path in _testspecs_dir.glob("*/*")]
17+
_testspecs_v2 = [str(path.relative_to(_testspecs_dir)) for path in _testspecs_v2_dir.glob("*/*")]
18+
_testspecs_v3 = [str(path.relative_to(_testspecs_dir)) for path in _testspecs_v3_dir.glob("*/*")]
19+
20+
21+
def pytest_addoption(parser):
22+
parser.addoption("--regenerate-rendered-specs", action="store_true")
23+
24+
25+
def pytest_collection_modifyitems(items):
26+
items_new = []
27+
28+
for item in items:
29+
has_mark = bool(list(item.iter_markers(name="regenerate_rendered_specs")))
30+
31+
if any(
32+
[
33+
item.config.getoption("--regenerate-rendered-specs") and has_mark,
34+
not item.config.getoption("--regenerate-rendered-specs") and not has_mark,
35+
]
36+
):
37+
items_new.append(item)
38+
39+
items[:] = items_new
540

641

742
def _format_option_raw(key, val):
@@ -46,3 +81,19 @@ def run(spec, options={}):
4681
).build()
4782

4883
yield run
84+
85+
86+
@pytest.fixture(scope="function")
87+
def get_testspec():
88+
def get_testspec(*args, encoding="utf-8", resolve_refs=True):
89+
with _testspecs_dir.joinpath(*args).open(encoding=encoding) as f:
90+
spec = yaml.safe_load(f)
91+
if resolve_refs:
92+
spec = utils._resolve_refs("", spec)
93+
return spec
94+
return get_testspec
95+
96+
97+
@pytest.fixture(scope="function", params=_testspecs)
98+
def testspec(request, get_testspec):
99+
return request.param, get_testspec(request.param)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
.. http:get:: /
2+
3+
**List API versions**
4+
5+
:statuscode 200:
6+
200 300 response
7+
8+
.. sourcecode:: http
9+
10+
HTTP/1.1 200 OK
11+
Content-Type: application/json
12+
13+
{
14+
"versions": [
15+
{
16+
"status": "CURRENT",
17+
"updated": "2011-01-21T11:33:21Z",
18+
"id": "v2.0",
19+
"links": [
20+
{
21+
"href": "http://127.0.0.1:8774/v2/",
22+
"rel": "self"
23+
}
24+
]
25+
},
26+
{
27+
"status": "EXPERIMENTAL",
28+
"updated": "2013-07-23T11:33:21Z",
29+
"id": "v3.0",
30+
"links": [
31+
{
32+
"href": "http://127.0.0.1:8774/v3/",
33+
"rel": "self"
34+
}
35+
]
36+
}
37+
]
38+
}
39+
:statuscode 300:
40+
200 300 response
41+
42+
.. http:get:: /v2
43+
44+
**Show API version details**
45+
46+
:statuscode 200:
47+
200 203 response
48+
49+
.. sourcecode:: http
50+
51+
HTTP/1.1 200 OK
52+
Content-Type: application/json
53+
54+
{
55+
"version": {
56+
"status": "CURRENT",
57+
"updated": "2011-01-21T11:33:21Z",
58+
"media-types": [
59+
{
60+
"base": "application/xml",
61+
"type": "application/vnd.openstack.compute+xml;version=2"
62+
},
63+
{
64+
"base": "application/json",
65+
"type": "application/vnd.openstack.compute+json;version=2"
66+
}
67+
],
68+
"id": "v2.0",
69+
"links": [
70+
{
71+
"href": "http://127.0.0.1:8774/v2/",
72+
"rel": "self"
73+
},
74+
{
75+
"href": "http://docs.openstack.org/api/openstack-compute/2/os-compute-devguide-2.pdf",
76+
"type": "application/pdf",
77+
"rel": "describedby"
78+
},
79+
{
80+
"href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
81+
"type": "application/vnd.sun.wadl+xml",
82+
"rel": "describedby"
83+
},
84+
{
85+
"href": "http://docs.openstack.org/api/openstack-compute/2/wadl/os-compute-2.wadl",
86+
"type": "application/vnd.sun.wadl+xml",
87+
"rel": "describedby"
88+
}
89+
]
90+
}
91+
}
92+
:statuscode 203:
93+
200 203 response
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
.. http:get:: /pets
2+
3+
Returns all pets from the system that the user has access to
4+
5+
:queryparam tags:
6+
tags to filter by
7+
:queryparamtype tags: array
8+
:queryparam limit:
9+
maximum number of results to return
10+
:queryparamtype limit: integer:int32
11+
:statuscode 200:
12+
pet response
13+
14+
:statuscode default:
15+
unexpected error
16+
17+
.. http:post:: /pets
18+
19+
Creates a new pet in the store. Duplicates are allowed
20+
21+
22+
:statuscode 200:
23+
pet response
24+
25+
:statuscode default:
26+
unexpected error
27+
28+
.. http:get:: /pets/{id}
29+
30+
Returns a user based on a single ID, if the user does not have access to the pet
31+
32+
:param id:
33+
ID of pet to fetch
34+
:paramtype id: integer:int64, required
35+
:statuscode 200:
36+
pet response
37+
38+
:statuscode default:
39+
unexpected error
40+
41+
.. http:delete:: /pets/{id}
42+
43+
deletes a single pet based on the ID supplied
44+
45+
:param id:
46+
ID of pet to delete
47+
:paramtype id: integer:int64, required
48+
:statuscode 204:
49+
pet deleted
50+
:statuscode default:
51+
unexpected error
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.. http:get:: /pets
2+
3+
**List all pets**
4+
5+
:queryparam limit:
6+
How many items to return at one time (max 100)
7+
:queryparamtype limit: integer:int32
8+
:statuscode 200:
9+
A paged array of pets
10+
11+
12+
:resheader x-next:
13+
A link to the next page of responses
14+
:resheadertype x-next: string
15+
:statuscode default:
16+
unexpected error
17+
18+
.. http:post:: /pets
19+
20+
**Create a pet**
21+
22+
:statuscode 201:
23+
Null response
24+
:statuscode default:
25+
unexpected error
26+
27+
.. http:get:: /pets/{petId}
28+
29+
**Info for a specific pet**
30+
31+
:param petId:
32+
The id of the pet to retrieve
33+
:paramtype petId: string, required
34+
:statuscode 200:
35+
Expected response to a valid request
36+
37+
:statuscode default:
38+
unexpected error
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
.. http:get:: /products
2+
3+
**Product Types**
4+
5+
The Products endpoint returns information about the Uber products offered at a given location. The response includes the display name and other details about each product, and lists the products in the proper display order.
6+
7+
:queryparam latitude:
8+
Latitude component of location.
9+
:queryparamtype latitude: number:double, required
10+
:queryparam longitude:
11+
Longitude component of location.
12+
:queryparamtype longitude: number:double, required
13+
:statuscode 200:
14+
An array of products
15+
16+
:statuscode default:
17+
Unexpected error
18+
19+
.. http:get:: /estimates/price
20+
21+
**Price Estimates**
22+
23+
.. role:: raw-html-m2r(raw)
24+
:format: html
25+
26+
27+
The Price Estimates endpoint returns an estimated price range for each product offered at a given location. The price estimate is provided as a formatted string with the full price range and the localized currency symbol.\ :raw-html-m2r:`<br>`\ :raw-html-m2r:`<br>`\ The response also includes low and high estimates, and the `ISO 4217 <http://en.wikipedia.org/wiki/ISO_4217>`_ currency code for situations requiring currency conversion. When surge is active for a particular product, its surge_multiplier will be greater than 1, but the price estimate already factors in this multiplier.
28+
29+
:queryparam start_latitude:
30+
Latitude component of start location.
31+
:queryparamtype start_latitude: number:double, required
32+
:queryparam start_longitude:
33+
Longitude component of start location.
34+
:queryparamtype start_longitude: number:double, required
35+
:queryparam end_latitude:
36+
Latitude component of end location.
37+
:queryparamtype end_latitude: number:double, required
38+
:queryparam end_longitude:
39+
Longitude component of end location.
40+
:queryparamtype end_longitude: number:double, required
41+
:statuscode 200:
42+
An array of price estimates by product
43+
44+
:statuscode default:
45+
Unexpected error
46+
47+
.. http:get:: /estimates/time
48+
49+
**Time Estimates**
50+
51+
The Time Estimates endpoint returns ETAs for all products offered at a given location, with the responses expressed as integers in seconds. We recommend that this endpoint be called every minute to provide the most accurate, up-to-date ETAs.
52+
53+
:queryparam start_latitude:
54+
Latitude component of start location.
55+
:queryparamtype start_latitude: number:double, required
56+
:queryparam start_longitude:
57+
Longitude component of start location.
58+
:queryparamtype start_longitude: number:double, required
59+
:queryparam customer_uuid:
60+
Unique customer identifier to be used for experience customization.
61+
:queryparamtype customer_uuid: string:uuid
62+
:queryparam product_id:
63+
Unique identifier representing a specific product for a given latitude & longitude.
64+
:queryparamtype product_id: string
65+
:statuscode 200:
66+
An array of products
67+
68+
:statuscode default:
69+
Unexpected error
70+
71+
.. http:get:: /me
72+
73+
**User Profile**
74+
75+
The User Profile endpoint returns information about the Uber user that has authorized with the application.
76+
77+
:statuscode 200:
78+
Profile information for a user
79+
80+
:statuscode default:
81+
Unexpected error
82+
83+
.. http:get:: /history
84+
85+
**User Activity**
86+
87+
.. role:: raw-html-m2r(raw)
88+
:format: html
89+
90+
91+
The User Activity endpoint returns data about a user's lifetime activity with Uber. The response will include pickup locations and times, dropoff locations and times, the distance of past requests, and information about which products were requested.\ :raw-html-m2r:`<br>`\ :raw-html-m2r:`<br>`\ The history array in the response will have a maximum length based on the limit parameter. The response value count may exceed limit, therefore subsequent API requests may be necessary.
92+
93+
:queryparam offset:
94+
Offset the list of returned results by this amount. Default is zero.
95+
:queryparamtype offset: integer:int32
96+
:queryparam limit:
97+
Number of items to retrieve. Default is 5, maximum is 100.
98+
:queryparamtype limit: integer:int32
99+
:statuscode 200:
100+
History information for the given user
101+
102+
:statuscode default:
103+
Unexpected error

0 commit comments

Comments
 (0)