Exemplo n.º 1
0
def test_dots_get_succeeds__default(query, default, expected):
    """Test that the default is returned if no value found."""
    data = {
        'hello': {
            'salute': 1
        },
        'doints': {
            1: True,
        }
    }
    assert DictDots.get(data, query, default) == expected
Exemplo n.º 2
0
def test_dots_get_succeeds__no_default(query, result):
    """Tests that get retrieves the correct value."""
    data = {
        'hello': {
            'salute': 1
        },
        'doints': {
            1: True,
        },
        "list": [
            1,
            2,
        ],
        1: "numeric key"
    }
    assert DictDots.get(data, query) == result
def test_dots_get_succeeds(query, result, default):
    data = {'hello': {'salute': 1}, 'doints': {1: True}}
    assert DictDots.get(data, query) == result or Hash.get(
        data, query, default) == default
def test_hash_get_throws_invalid_query_exception(query):
    with pytest.raises(InvalidQueryString):
        DictDots.get([], query)
def test_is_valid_query(query, result):
    assert DictDots.is_valid_query(query) == result
Exemplo n.º 6
0
def test_dots_get_succeeds__list_data(query, result):
    data = [1, 2, "three", {"four": {"success": True}}]
    assert DictDots.get(data, query) == result
Exemplo n.º 7
0
def test_hash_get_throws_invalid_query_exception(query):
    """Tests that an error is raised for invalid queries."""
    with pytest.raises(InvalidQueryString):
        DictDots.get({}, query)
Exemplo n.º 8
0
def test_is_searchable_type(data, expected):
    """Test that is_searchable_type only allows supported types.

    Supported types are in :data:`constants.SEARCHABLE_TYPES`
    """
    assert DictDots.is_searchable_type(data) == expected
Exemplo n.º 9
0
def test_is_valid_query(query, result):
    """Test that queries can be validated."""
    assert DictDots.is_valid_query(query) == result
Exemplo n.º 10
0
def test_get__raises_does_not_exist(query):
    """Test that an error is raised if no data is found and no default is provided."""
    data = {"hello": "world"}
    with pytest.raises(DoesNotExist):
        DictDots.get(data, query)