def test_get_first_search_result_invalid(self): fake_json = json.dumps({'items': []}) url = "https://api.github.com/search/repositories?q=aksejake" with requests_mock.mock() as mocker: mocker.get(url, json=fake_json) response = json.loads(requests.get(url).json()) with pytest.raises(Exception) as exc_info: gitdl.get_first_search_result(response) assert str(exc_info.value) == "Repository Not Found."
def test_get_first_search_result_valid(self): fake_json = json.dumps({'items': [{"id": 1, "name": "gitdl"}]}) url = "https://api.github.com/search/repositories?q=aksejake" with requests_mock.mock() as mocker: mocker.get(url, json=fake_json) response = json.loads(requests.get(url).json()) res = gitdl.get_first_search_result(response) self.assertEqual(res, {'id': 1, 'name': 'gitdl'})
def test_get_first_search_result_invalid(self): url = "https://api.github.com/search/repositories?q=aksejake" response = requests.get(url).json() with pytest.raises(Exception) as exc_info: gitdl.get_first_search_result(response) assert str(exc_info.value) == "Repository Not Found."