i have a question. I am doing rtsp client tests. This Client is our, works preety nice. Question is, is exist a way to check status of response if it return in json?
client.py
def get_paths(self):
return requests.get(f"{self.API_URL}/v1/paths/list").json()
tests.py
def test_get_path(self):
response = self.rtsp_client.get_paths()
self.assertEqual(response, 200)
In this example, i got:
Traceback (most recent call last):
File "/home/oliwer/Documents/repozytoriumGit/device-channels/project/backend/rtsp_simple_server_api/tests.py", line 99, in test_get_path
self.assertEqual(response, 200)
AssertionError: {'items': {'none': {'confName': 'none', '[3105 chars][]}}} != 200
I understand why i got this output. I am just interested is exist a way to test status code of this response.
Ps. The point is that, i can't change request functionality, it has to return json, i wanted to get something like that:
tests.py
def test_get_path(self):
response = self.rtsp_client.get_path().command_that_can_reverse_json()_command
self.assertEqual(response, 200)
I thought, that it is possible, when i have.json() method. In my opinion response is an object with this first response, but encoded to json file. So my thoughts were that i can reverse this operation, but i did not know how. In your opinion, i can't do that.
I would suggest, that you change your code like this
def get_paths():
return requests.get('https://jsonplaceholder.typicode.com/todos/1')
than you can access the status_code of the response with:
r = get_paths()
print(r.status_code)
>>> 200
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.