Coverage for gws-app/gws/base/database/_test/provider_test.py: 100%

24 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-16 23:09 +0200

1import gws 

2import gws.lib.sa as sa 

3import gws.test.util as u 

4import gws.base.database.provider 

5 

6 

7@u.fixture(scope='module') 

8def db(): 

9 u.pg.create_schema('s1') 

10 u.pg.create_schema('s2') 

11 u.pg.create('s1.tab1', {'id': 'int primary key', 'a': 'text'}) 

12 u.pg.create('s2.tab2', {'id': 'int primary key', 'a': 'text'}) 

13 

14 root = u.gws_root() 

15 yield u.get_db(root) 

16 

17 

18## 

19 

20 

21def test_table(db): 

22 tab = db.table('s1.tab1') 

23 assert tab is not None 

24 with u.raises(sa.Error): 

25 tab = db.table('s1.ZZZ') 

26 

27 

28def test_count(db: gws.DatabaseProvider): 

29 tab = db.table('s1.tab1') 

30 

31 with db.connect() as conn: 

32 conn.exec_commit('truncate s1.tab1') 

33 conn.exec_commit( 

34 tab.insert().values( 

35 [ 

36 {'id': 1, 'a': 'X'}, 

37 {'id': 2, 'a': 'Y'}, 

38 {'id': 3, 'a': 'Z'}, 

39 ]), 

40 ) 

41 conn.commit() 

42 assert db.count(tab) == 3 

43 

44# @TODO other provider methods