test_test.py 937 Bytes
Newer Older
1
2
3
4
from unittest import TestCase

import requests
import json
5
from senpy.testing import patch_requests
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from senpy.models import Results


class TestTest(TestCase):
    def test_patch_text(self):
        with patch_requests('hello'):
            r = requests.get('http://example.com')
            assert r.text == 'hello'
            assert r.content == 'hello'

    def test_patch_json(self):
        r = Results()
        with patch_requests(r):
            res = requests.get('http://example.com')
            assert res.content == json.dumps(r.jsonld())
            js = res.json()
            assert js
            assert js['@type'] == r['@type']

    def test_patch_dict(self):
        r = {'nothing': 'new'}
        with patch_requests(r):
            res = requests.get('http://example.com')
            assert res.content == json.dumps(r)
            js = res.json()
            assert js
            assert js['nothing'] == 'new'