def test_jsonrpcrequest_send_request_invalid_json_response(self): self.request_patcher.stop() url = 'http://example.com' headers = {'User-agent': 'Netscape'} with mock_urlopen(b'LOL DUDE', expected_url=url, expected_data=b'{"la": "LU"}', expected_headers=headers): self.assertRaises( webuntis.errors.RemoteError, webuntis.utils.remote._send_request, url, {'la': 'LU'}, headers )
def test_jsonrpcrequest_send_request_invalid_json_input(self): self.request_patcher.stop() url = 'http://example.com' headers = {'User-agent': 'Netscape'} with mock_urlopen(Exception('No.'), expected_url=url, expected_data='Does not matter', expected_headers=headers): self.assertRaises( TypeError, webuntis.utils.remote._send_request, url, object(), headers )
def test_jsonrpcrequest_send_request_valid_request(self): self.request_patcher.stop() url = 'http://example.com' headers = {'User-agent': 'Netscape'} with mock_urlopen(b'{"ret": "VAL"}', expected_url=url, expected_data=b'{"la": "LU"}', expected_headers=headers): self.assertEqual( webuntis.utils.remote._send_request( url, {'la': 'LU'}, headers ), {'ret': 'VAL'} )