def test_get_postal_code(api_client): with requests_mock.mock() as m: m.get( get_api_url("postcodes/7315AD"), text=read_file("single_postal_code.json"), ) data = api_client.get_postal_code(postal_code="7315AD") assert data["postcode"] == "7315AD"
def test_get_address(api_client): with requests_mock.mock() as m: m.get( get_api_url("addresses/0855200000046355"), text=read_file("single_address.json"), ) data = api_client.get_address(address_id="0855200000046355") assert data["postcode"] == "5038EA"
def test_get_all_postal_codes_area(api_client): with requests_mock.mock() as m: m.get( get_api_url("postcodes?postcodeArea=7313"), text=read_file("postal_code_list_area.json"), ) data = api_client.get_all_postal_codes(area="7313")["results"] assert data[0]["postcode"] == "7513AA"
def test_get_all_addresses_from_id(api_client): with requests_mock.mock() as m: m.get( get_api_url("addresses?from[id]=0503200000060096"), text=read_file("address_list_from_id.json"), ) data = api_client.get_all_addresses( from_id="0503200000060096")["results"] assert data[0]["id"] == "0553200000001332"
def test_get_all_addresses_with_postal_code_and_number(api_client): with requests_mock.mock() as m: m.get( get_api_url("addresses?postcode=6545CA&number=5"), text=read_file("address_list_postal_code_and_number.json"), ) data = api_client.get_all_addresses(postal_code="6545CA", number=5)["results"] assert data[0]["postcode"] == "6545CA" assert data[0]["number"] == 5
def test_get_all_postal_codes_from_postal_code(api_client): with requests_mock.mock() as m: m.get( get_api_url( "postcodes?from[postcode]=7315AA&from[postcodeArea]=7315"), text=read_file("postal_code_list_from_postal_code.json"), ) data = api_client.get_all_postal_codes( from_postal_code="7315AA")["results"] assert data[0]["postcode"] == "7315BB"
def test_update_bitbucket_repo_info_mocked_check_for_next(developer): # Not needed check: but let's make sure for the demo: assert not developer.bitbucket_repo_info bitbucket_repo_info_str = read_file("bitbucket_repo_info.json") bitbucket_repo_info = json.loads(bitbucket_repo_info_str) bitbucket_repo_info["next"] = "this_triggers_a_not_implemented_error" with requests_mock.mock() as m2, pytest.raises(NotImplementedError): m2.get("https://bitbucket.org/api/2.0/repositories/acidjunk", text=json.dumps(bitbucket_repo_info)) developer.update_bitbucket_repo_info()
def test_update_bitbucket_repo_info_mocked(developer): # Not needed check: but let's make sure for the demo: assert not developer.bitbucket_repo_info bitbucket_repo_info_str = read_file("bitbucket_repo_info.json") with requests_mock.mock() as m: m.get("https://bitbucket.org/api/2.0/repositories/acidjunk", text=bitbucket_repo_info_str) developer.update_bitbucket_repo_info() assert "acidjunk" in str(developer.bitbucket_repo_info) assert len(developer.bitbucket_repo_info) == 2
def test_update_github_repo_info_mocked(developer): # Not needed check: but let's make sure for the demo: assert not developer.github_repo_info with requests_mock.mock() as m: m.get("https://api.github.com/users/acidjunk/repos", text=read_file("github_repo_info.json")) developer.update_github_repo_info() # Check if content arrived in model: assert "acidjunk" in str(developer.github_repo_info) assert "acidjunk_mocked" in str(developer.github_repo_info) assert len(developer.github_repo_info) == 2
def test_get_all_addresses(api_client): with requests_mock.mock() as m: m.get(get_api_url("addresses"), text=read_file("address_list.json")) data = api_client.get_all_addresses(postal_code="5038EA")["results"] assert data[0]["postcode"] == "5038EA"
def test_get_all_postal_codes(api_client): with requests_mock.mock() as m: m.get(get_api_url("postcodes"), text=read_file("postal_code_list.json")) data = api_client.get_all_postal_codes()["results"] assert data[0]["postcode"] == "7315AA"