def test_get_lookup_fields_fetches_json_from_url(fake_requests_get):
    #arrange
    input = "https://fake-url.com/data.txt"

    #act
    result = utils.get_lookup_fields(input)

    #assert
    fake_requests_get.assert_called_once_with(url=input)
def test_get_lookup_fields_loads_file_when_input_not_url(
        fake_get_lookup_fields_from_url):
    #arrange
    input = "https://fake-url.com/data.txt"

    #act
    result = utils.get_lookup_fields(input)

    #assert
    assert fake_get_lookup_fields_from_url.called
def test_get_lookup_fields_fetches_json_from_url():
    #arrange
    input = "data.txt"
    data = {"foo": "bar"}
    json_text = json.dumps(data)
    #act
    with patch('builtins.open', mock_open(read_data=json_text), create=True):
        result = utils.get_lookup_fields(input)

        #assert
        assert result["foo"] == data["foo"]
def test_get_lookup_fields_raises_exception_when_empty_string_passed_in():
    #arrange
    input = ""

    #act
    # with pytest.raises(ValueError) as excinfo:
    #     utils.get_lookup_fields(input)

    # #assert
    # assert "is_url input is empty string!" in str(excinfo.value)
    result = utils.get_lookup_fields(input)
    assert result == None
def test_get_lookup_fields_raises_exception_when_number_passed_in():
    #arrange
    input = 124

    # #act
    # with pytest.raises(ValueError) as excinfo:
    #     utils.get_lookup_fields(input)

    # #assert
    # assert "is_url input is numeric! Must be string" in str(excinfo.value)
    result = utils.get_lookup_fields(input)
    assert result == None
def test_get_lookup_fields_should_only_accept_strings():
    #arrange
    def input():
        print("a fake method")

    # #act
    # with pytest.raises(ValueError) as excinfo:
    #     utils.get_lookup_fields(input)

    # #assert
    # assert "is_url input must be string" in str(excinfo.value)
    result = utils.get_lookup_fields(input)
    assert result == None