def test_unindexed_query(): """ Tests a query over a single type. Only non-indexed fields are tested. """ query = Query(Person).add(Person.name, 'Peter Pan') results = list(query.execute(DEFAULT_DB_ALIAS)) eq_(len(results), 1) eq_(results[0]['name'], 'Peter Pan')
def test_complex_query(): """ Tests a single-type query with both indexed and non-indexed fields. """ query = Query(Person).add(Person.name, 'Peter Pan', negate=True).add(Person.age, 15) results = list(query.execute(DEFAULT_DB_ALIAS)) eq_(len(results), 1) eq_(results[0]['name'], 'Tinker Bell')
def test_negated_query(): """ Tests a negated query over a single type. Only indexed fields are tested. """ query = Query(IndexedMouse).add(IndexedMouse.age, 2)\ .add(IndexedMouse.name, 'jerry', negate=True) results = list(query.execute(DEFAULT_DB_ALIAS)) eq_(len(results), 1) assert len([m for m in results if m['name'] == 'jerry']) == 0, "The query"\ " returned jerry, even though he was excluded."
def test_basic_indexed_query(): """ Tests a basic query over a single type. Only indexed fields are tested. """ age_query = Query(IndexedMouse).add(IndexedMouse.age, 2) results = list(age_query.execute(DEFAULT_DB_ALIAS)) eq_(len(results), 2) assert len([m for m in results if m['name'] == 'Brain']) == 0, "The query"\ " returned Brain - even though he's too old." results = list(age_query.add(IndexedMouse.name, 'jerry')\ .execute(DEFAULT_DB_ALIAS)) eq_(len(results), 1) assert len([m for m in results if m['name'] == 'jerry']) > 0, "The query"\ " didn't return jerry - wrong mouse."