1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-09-20 22:01:41 +00:00
senpy/tests/test_test.py

34 lines
918 B
Python
Raw Normal View History

2018-01-18 11:23:06 +00:00
from unittest import TestCase
import requests
import json
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'