def test_find(request, populate): conf = request.config conn = TessMongoConnection(conf.getoption('db_host'), conf.getoption('db_port'), conf.getoption('db_user'), password=conf.getoption('db_passwd', default=None), db=conf.getoption('db_name', default=None)) for key, val in populate.items(): # Test finding every entry in the database. result = conn.find(key) assert len(result) == len(val) for r in result: match = [ all([getattr(r, k) == val[i][k] for k in val[i].keys()]) for i in range(len(val)) ] assert sum([1 if m else 0 for m in match]) == 1 # Test finding individual entries for entry in val: result = conn.find(key, _id=entry['id']) assert len(result) == 1 assert all( [getattr(result[0], k) == entry[k] for k in entry.keys()]) # Test finding non-existent entries result = conn.find(key, foo='bar') assert result == []
def test_find(self, request, populate, entity_map): conf = request.config conn = TessMongoConnection(conf.getoption('db_host'), conf.getoption('db_port'), conf.getoption('db_user'), password=conf.getoption('db_passwd', default=None), db=conf.getoption('db_name', default=None)) for entity_type in populate: if len(populate[entity_type]) == 0: continue end = \ len(populate[entity_type]) if len(populate[entity_type]) < 100 \ else 100 for query_ent in populate[entity_type][:end]: entity = entity_map[entity_type].json_decode(query_ent) ents = conn.find( entity_type, **entity.json_encode( exclude=['_id', 'lemmata', 'semantic', 'sound'])) assert ents[0].json_encode( exclude=['_id']) == entity.json_encode(exclude=['_id']) for text in populate['texts']: text = Text.json_decode(text) ents = conn.find('tokens', text=text.path) correct_tokens = [ t for t in populate['tokens'] if t['text'] == text.path ] assert len(ents) == len(correct_tokens) ents = conn.find('frequencies', text=text.path) correct_tokens = [ t for t in populate['frequencies'] if t['text'] == text.path ] assert len(ents) == len(correct_tokens) ents = conn.find('units', text=text.path) correct_tokens = [ t for t in populate['units'] if t['text'] == text.path ] assert len(ents) == len(correct_tokens)
def test_delete(self, request, populate, entity_map): conf = request.config conn = TessMongoConnection(conf.getoption('db_host'), conf.getoption('db_port'), conf.getoption('db_user'), password=conf.getoption('db_passwd', default=None), db=conf.getoption('db_name', default=None)) for entity_type in populate: if len(populate[entity_type]) == 0: continue end = \ len(populate[entity_type]) if len(populate[entity_type]) < 100 \ else 100 for query_ent in populate[entity_type][:end]: entity = entity_map[entity_type].json_decode(query_ent) res = conn.delete(entity) found = conn.find(entity_type, **entity.json_encode(exclude=['_id'])) assert res.deleted_count == 1 assert len(found) == 0 conn.insert(entity)