Coverage for gws-app/gws/plugin/model_field/datetime/_test.py: 100%
32 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 23:09 +0200
« prev ^ index » next coverage.py v7.11.0, created at 2025-10-16 23:09 +0200
1import gws
2import gws.test.util as u
3import gws.lib.datetimex as dtx
6@u.fixture(scope='module')
7def model():
8 u.pg.create('t', {'id': 'int primary key', 'dat': 'timestamptz'})
10 cfg = """
11 models+ {
12 uid "TEST_MODEL" type "postgres" tableName "t"
13 fields+ { name "id" type "integer" }
14 fields+ { name "dat" type "date" }
15 }
16 """
18 root = u.gws_root(cfg)
19 yield u.cast(gws.Model, root.get('TEST_MODEL'))
22def test_create(model: gws.Model):
23 mc = u.model_context()
25 d = dtx.new(2000, 2, 3, 4, 5, 6)
27 f = u.feature(model, id=1, dat=d)
28 model.create_feature(f, mc)
30 fs = model.get_features([1], mc)
31 assert dtx.to_iso_string(fs[0].get('dat')) == dtx.to_iso_string(d)
34def test_read(model: gws.Model):
35 mc = u.model_context()
37 ds = [
38 dtx.new(2000, 2, 3, 4, 5, 6),
39 dtx.new(2001, 12, 13, 14, 15, 16),
40 ]
41 u.pg.insert('t', [{'id': 1, 'dat': ds[0]}, {'id': 2, 'dat': ds[1]}])
43 fs = model.get_features([1, 2], mc)
45 assert dtx.to_iso_string(fs[0].get('dat')) == dtx.to_iso_string(ds[0])
46 assert dtx.to_iso_string(fs[1].get('dat')) == dtx.to_iso_string(ds[1])
49def test_update(model: gws.Model):
50 mc = u.model_context()
52 ds = [
53 dtx.new(2000, 2, 3, 4, 5, 6),
54 dtx.new(2001, 12, 13, 14, 15, 16),
55 ]
56 u.pg.insert('t', [{'id': 1, 'dat': ds[0]}, {'id': 2, 'dat': ds[1]}])
58 new = dtx.new(2009, 9, 19, 11, 22, 33)
59 f = u.feature(model, id=1, dat=new)
60 model.update_feature(f, mc)
62 fs = model.get_features([1, 2], mc)
63 assert dtx.to_iso_string(fs[0].get('dat')) == dtx.to_iso_string(new)