-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from gulducat/base_url
base_url instead of proto + host
- Loading branch information
Showing
7 changed files
with
90 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
flake8 | ||
mock | ||
pytest-cov | ||
requests-mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from setuptools import setup | ||
|
||
VERSION = '0.1.3' | ||
VERSION = '0.2.0' | ||
|
||
|
||
def load_long_description(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env python | ||
|
||
""" | ||
probably shouldn't be doing this, but rolling my own | ||
super basic doctest helps keep docstrings and readme clean. | ||
it's quite fragile, but i'm ok with that. | ||
""" | ||
|
||
import re | ||
|
||
import requests # noqa | ||
import requests_mock | ||
|
||
|
||
def test_docs(requests_mock): | ||
# requests_mock makes sure only this url gets hit. | ||
url = 'https://api.example.com/cool/path' | ||
requests_mock.get(url, text='ok') | ||
requests_mock.post(url, text='ok') | ||
|
||
with open('README.md') as f: | ||
lines = f.readlines() | ||
|
||
for line in lines: | ||
line = line.strip() | ||
if ' = ' in line or line.startswith('from '): | ||
print('>>> ' + line) | ||
exec(line) | ||
continue | ||
|
||
if not line.startswith('api'): | ||
continue | ||
|
||
if not line.endswith(')'): | ||
print('>>> ' + line) | ||
exec(line) | ||
continue | ||
|
||
print('>>> resp = ' + line) | ||
resp = eval(line) | ||
assert resp.text == 'ok' | ||
|
||
# the below is kinda complicated, and not strictly necessary | ||
# since the logic is tested elsewhere, but eh, i wrote it | ||
# so here it remains. | ||
|
||
request_kw = re.search(r'(\w+)=(\{.*\})', line) | ||
if not request_kw: | ||
continue | ||
|
||
kw, val = request_kw.groups() | ||
print("#", kw, val) | ||
val = eval(val) | ||
|
||
if kw == 'json': | ||
json = eval('resp.request.json()') | ||
assert json == val | ||
|
||
elif kw == 'headers': | ||
headers = eval('resp.request.headers') | ||
intersection = {} | ||
for k, v in val.items(): | ||
if headers[k] == v: | ||
intersection[k] = v | ||
assert intersection == val | ||
|
||
|
||
if __name__ == '__main__': | ||
with requests_mock.Mocker() as m: | ||
test_docs(m) |