Example #1
0
def test_find_and_find_one_accept_a_callable_as_a_matching_value():
    """Tests that both find and find_one will accept a callable as a
    matching value, and if (when passed the current value for field
    will include the record if the callable returns True)"""
    store = _create_store()
    results = store.find({"this": lambda x: x.startswith("t")})
    assert len(results) == 3
    result = store.find({"this": lambda x: x.startswith("t")})
    assert len([result]) == 1
Example #2
0
def test_find_and_find_one_accept_a_callable_as_a_matching_value():
    """Tests that both find and find_one will accept a callable as a
    matching value, and if (when passed the current value for field
    will include the record if the callable returns True)"""
    store = _create_store()
    results = store.find({"this": lambda x: x.startswith("t")})
    assert len(results) == 3
    result = store.find({"this": lambda x: x.startswith("t")})
    assert len([result]) == 1
Example #3
0
def test_sort_works_based_on_key():
    """Tests that the Store's method find will accept an
    argument called order_by which will sort based on the key
    named in the order_by parameter."""
    store = _create_store()
    results = store.find({}, order_by="this")
    assert results[0]["this"] == "bar"
Example #4
0
def test_find_returns_Store_of_matching_records():
    """Tests that the Store's find method will return a new
    store consisting of any matching records."""
    store = _create_store()

    result = store.find({"this": "that"})
    assert len(result) == 3
Example #5
0
def test_find_and_find_one_can_encrypt_ints():
    store = _create_store()
    for index, record in enumerate(store):
        record["integer"] = index
    encrypted = store.find({}, encrypt_list=["integer"], password="******")
    for index, record in enumerate(encrypted):
        assert not isinstance(record["integer"], int)
Example #6
0
def test_sort_works_based_on_key():
    """Tests that the Store's method find will accept an
    argument called order_by which will sort based on the key
    named in the order_by parameter."""
    store = _create_store()
    results = store.find({}, order_by="this")
    assert results[0]["this"] == "bar"
Example #7
0
def test_find_returns_Store_of_matching_records():
    """Tests that the Store's find method will return a new
    store consisting of any matching records."""
    store = _create_store()

    result = store.find({"this": "that"})
    assert len(result) == 3
Example #8
0
def test_find_and_find_one_can_encrypt_ints():
    store = _create_store()
    for index, record in enumerate(store):
        record["integer"] = index
    encrypted = store.find({}, encrypt_list=["integer"], password="******")
    for index, record in enumerate(encrypted):
        assert not isinstance(record["integer"], int)
Example #9
0
def test_find_accepts_argument_to_encrypt_list():
    """Tests that the Store's find method will accept an encrypt_list
    parameter and that any field named in the list will be encrypted
    with password."""
    store = _create_store()
    results = store.find({}, encrypt_list=["this"], password="******")
    assert isinstance(results, Store)
    for index, record in enumerate(results):
        assert record["this"] != store[index]["this"]
        assert decrypt(record["this"], key="password") == store[index]["this"]
Example #10
0
def test_find_accepts_argument_to_encrypt_list():
    """Tests that the Store's find method will accept an encrypt_list
    parameter and that any field named in the list will be encrypted
    with password."""
    store = _create_store()
    results = store.find({}, encrypt_list=["this"], password="******")
    assert isinstance(results, Store)
    for index, record in enumerate(results):
        assert record["this"] != store[index]["this"]
        assert decrypt(record["this"], key="password") == store[index]["this"]
Example #11
0
def test_find_and_find_one_accept_compiled_regex():
    """Tests that the Store's methods find and find_one will
    accept a compiled regex and will then match records where
    the regex matches."""
    import re
    store = _create_store()
    regex = re.compile("t.*")
    results = store.find({"this": regex})
    result = [store.find_one({"this": regex})]
    assert len(results) == 3
    assert len(result) == 1
Example #12
0
def test_find_and_find_one_accept_compiled_regex():
    """Tests that the Store's methods find and find_one will
    accept a compiled regex and will then match records where
    the regex matches."""
    import re

    store = _create_store()
    regex = re.compile("t.*")
    results = store.find({"this": regex})
    result = [store.find_one({"this": regex})]
    assert len(results) == 3
    assert len(result) == 1
Example #13
0
def test_find_and_find_one_accept_sanitize_list_argument_and_sanitizes_those_fields():
    """Tests that the Store's methods find and find_one will accept a
    parameter called sanitize_list and that any field named in the list
    will be sanitized (ie the value of that field will be replaced with
    8 asterics [*])"""
    store = _create_store()
    results = store.find({"this": "that"}, sanitize_list=["this"])
    print "RESULTS: ", results
    print "STORE:", store
    for result in results:
        assert result["this"] == "*" * 8
    result = store.find_one({"this": "that"}, sanitize_list=["this"])
    print "RESULT:", result
    assert result["this"] == "*" * 8
Example #14
0
def test_find_and_find_one_accept_sanitize_list_argument_and_sanitizes_those_fields(
):
    """Tests that the Store's methods find and find_one will accept a
    parameter called sanitize_list and that any field named in the list
    will be sanitized (ie the value of that field will be replaced with
    8 asterics [*])"""
    store = _create_store()
    results = store.find({"this": "that"}, sanitize_list=["this"])
    print "RESULTS: ", results
    print "STORE:", store
    for result in results:
        assert result["this"] == "*" * 8
    result = store.find_one({"this": "that"}, sanitize_list=["this"])
    print "RESULT:", result
    assert result["this"] == "*" * 8