2018-01-18 11:23:06 +00:00
|
|
|
from unittest import TestCase
|
|
|
|
|
|
|
|
import requests
|
|
|
|
import json
|
2018-06-15 14:47:48 +00:00
|
|
|
from senpy.testing import patch_requests
|
2018-01-18 11:23:06 +00:00
|
|
|
from senpy.models import Results
|
|
|
|
|
2018-07-23 17:07:04 +00:00
|
|
|
ENDPOINT = 'http://example.com'
|
|
|
|
|
2018-01-18 11:23:06 +00:00
|
|
|
|
|
|
|
class TestTest(TestCase):
|
|
|
|
def test_patch_text(self):
|
2018-07-23 17:07:04 +00:00
|
|
|
with patch_requests(ENDPOINT, 'hello'):
|
|
|
|
r = requests.get(ENDPOINT)
|
2018-01-18 11:23:06 +00:00
|
|
|
assert r.text == 'hello'
|
|
|
|
|
|
|
|
def test_patch_json(self):
|
|
|
|
r = Results()
|
2018-07-23 17:07:04 +00:00
|
|
|
with patch_requests(ENDPOINT, r):
|
|
|
|
res = requests.get(ENDPOINT)
|
|
|
|
assert res.text == json.dumps(r.jsonld())
|
2018-01-18 11:23:06 +00:00
|
|
|
js = res.json()
|
|
|
|
assert js
|
|
|
|
assert js['@type'] == r['@type']
|
|
|
|
|
|
|
|
def test_patch_dict(self):
|
|
|
|
r = {'nothing': 'new'}
|
2018-07-23 17:07:04 +00:00
|
|
|
with patch_requests(ENDPOINT, r):
|
|
|
|
res = requests.get(ENDPOINT)
|
|
|
|
assert res.text == json.dumps(r)
|
2018-01-18 11:23:06 +00:00
|
|
|
js = res.json()
|
|
|
|
assert js
|
|
|
|
assert js['nothing'] == 'new'
|