-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_make_requests.py
More file actions
46 lines (33 loc) · 1.35 KB
/
test_make_requests.py
File metadata and controls
46 lines (33 loc) · 1.35 KB
1
2
3
4
5
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
33
34
35
36
37
38
39
40
41
42
import unittest
import make_requests
from unittest.mock import patch, mock_open
import json
from io import StringIO
# sample_json = StringIO( ' your_existing_dict ')
class TestRequest(unittest.TestCase):
#
# def test_url(self):
# result = make_requests.test_url()
# self.assertRaisesRegex(ValueError, r'[a-zA-Z0-9.-]+\.(com|edu|net|gov)')
def test_load_json(self):
sample_json = StringIO ('{"name": "John", "shares": "100", "price": 1230.23}')
with patch('urllib.request.urlopen') as url_patch:
with patch('json.load') as j_patch:
url_patch.return_value.__enter__.return_value = sample_json
res = make_requests.load_json('test', file_counter=0)
j_patch.assert_called_with({})
# print(res)
# self.assertDictEqual(res, {'name': 'John', 'shares': '100', 'price': 1230.23})
# def test_read_file_data(self):
# import json
# sample_json = {
# 'name': 'John',
# 'shares': 100,
# 'price': 1230.23
# }
# sample_json = json.dump(sample_json)
# path = / path / to / file
# filename = testcase.json
# self.assertEqual(read_file_data(filename, path), sample_json)
if __name__ == '__main__':
unittest.main()