def test_error_code_response(self): w = Wallhaven() responses.add(responses.GET, 'https://wallhaven.cc/api/v1/search', status=429) with self.assertRaises(RateLimitError): w.search()
def test_connection_error(self): w = Wallhaven() responses.add(responses.GET, 'https://wallhaven.cc/api/v1/search', body=requests.exceptions.ConnectionError()) with self.assertRaises(requests.exceptions.ConnectionError): w.search()
def test_invalid_json(self): responses.add(responses.GET, 'https://wallhaven.cc/api/v1/search', status=200, body='{}}') w = Wallhaven() with self.assertRaises(json.JSONDecodeError): w.search()
def test_error_code_response(self): w = Wallhaven() for e in [201, 400, 404, 422, 500, 502, 503]: responses.add(responses.GET, 'https://wallhaven.cc/api/v1/search', status=e) with self.assertRaises(requests.exceptions.RequestException): w.search()
def test_invalid_parameters(self): w = Wallhaven() with self.assertRaises(ValueError): w.search(purity='1111') with self.assertRaises(KeyError): w.search(test_parameter='1111') with self.assertRaises(ValueError): w.search(q='id:r4e5tg')
def test_valid_search_json_with_page_in_kwargs(self): with open(get_resource_file("test_search.json"), 'r') as fp: mock_json = json.load(fp) responses.add(responses.GET, 'https://wallhaven.cc/api/v1/search', status=200, json=mock_json) w = Wallhaven() result_wallpapers, result_meta = w.search(**{'page': 1}) self.assertEqual(dataclasses.asdict(result_meta), mock_json['meta']) self.assertIsInstance(result_wallpapers, list) for w in result_wallpapers: self.assertIsInstance(w, Wallpaper) self.assertIsInstance(result_meta, Meta)