Coverage for gws-app/gws/plugin/model_field/text/_test.py: 0%
25 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 01:37 +0200
1import gws.config
2import gws.base.feature
3import gws.test.util as u
6@u.fixture(scope='module')
7def root():
8 u.pg.create('plain', {'id': 'int primary key', 'a': 'text', 'b': 'text'})
9 u.pg.insert('plain', [
10 {'id': 1, 'a': 'abc 1', 'b': 'uvw 1'},
11 {'id': 2, 'a': 'def 2', 'b': 'xyz 2'},
12 {'id': 3, 'a': 'abc 3', 'b': 'uvw 3'},
13 {'id': 4, 'a': 'def 4', 'b': 'xyz 4'},
14 ])
15 cfg = '''
16 models+ {
17 uid "NO_SEARCH" type "postgres" tableName "plain"
18 fields+ { name "a" type text }
19 }
20 models+ {
21 uid "EXACT_1" type "postgres" tableName "plain"
22 fields+ { name "a" type text textSearch.type exact }
23 }
24 models+ {
25 uid "ANY_1" type "postgres" tableName "plain"
26 fields+ { name "a" type text textSearch.type any }
27 }
28 models+ {
29 uid "ANY_1_OR_2" type "postgres" tableName "plain"
30 fields+ { name "a" type text textSearch.type any }
31 fields+ { name "b" type text textSearch.type any }
32 }
33 models+ {
34 uid "BEGIN_1" type "postgres" tableName "plain"
35 fields+ { name "a" type text textSearch.type begin }
36 }
37 models+ {
38 uid "END_1" type "postgres" tableName "plain"
39 fields+ { name "a" type text textSearch.type begin }
40 }
41 '''
43 yield u.gws_root(cfg)
46##
48def test_no_search_no_results(root: gws.Root):
49 mm = u.cast(gws.Model, root.get('NO_SEARCH'))
51 fs = mm.find_features(gws.SearchQuery(keyword='abc'), u.model_context())
52 assert [f.get('a') for f in fs] == []
55def test_exact_search(root: gws.Root):
56 mm = u.cast(gws.Model, root.get('EXACT_1'))
58 fs = mm.find_features(gws.SearchQuery(keyword='abc'), u.model_context())
59 assert [f.get('a') for f in fs] == []
61 fs = mm.find_features(gws.SearchQuery(keyword='abc 1'), u.model_context())
62 assert [f.get('a') for f in fs] == ['abc 1']
65def test_any_search(root: gws.Root):
66 mm = u.cast(gws.Model, root.get('ANY_1'))
68 fs = mm.find_features(gws.SearchQuery(keyword='boo'), u.model_context())
69 assert [f.get('a') for f in fs] == []
71 fs = mm.find_features(gws.SearchQuery(keyword='abc'), u.model_context())
72 assert [f.get('a') for f in fs] == ['abc 1', 'abc 3']