1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-11-23 16:42:29 +00:00
senpy/tests/test_test.py

50 lines
1.5 KiB
Python
Raw Normal View History

2019-07-17 14:29:30 +00:00
#
# Copyright 2014 Grupo de Sistemas Inteligentes (GSI) DIT, UPM
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
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
ENDPOINT = 'http://invalid.com'
2018-07-23 17:07:04 +00:00
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'