@@ -64,6 +64,43 @@ def mock_table_info(_schema_oid, conn):
64
64
assert actual_table_list == expect_table_list
65
65
66
66
67
+ def test_tables_get (rf , monkeypatch ):
68
+ request = rf .post ('/api/rpc/v0' , data = {})
69
+ request .user = User (username = 'alice' , password = 'pass1234' )
70
+ schema_oid = 2200
71
+ database_id = 11
72
+
73
+ @contextmanager
74
+ def mock_connect (_database_id , user ):
75
+ if _database_id == database_id and user .username == 'alice' :
76
+ try :
77
+ yield True
78
+ finally :
79
+ pass
80
+ else :
81
+ raise AssertionError ('incorrect parameters passed' )
82
+
83
+ def mock_table_get (_schema_oid , conn ):
84
+ if _schema_oid != schema_oid :
85
+ raise AssertionError ('incorrect parameters passed' )
86
+ return {
87
+ 'oid' : 17408 ,
88
+ 'name' : 'Authors' ,
89
+ 'schema' : schema_oid ,
90
+ 'description' : 'a description on the authors table.'
91
+ }
92
+ monkeypatch .setattr (tables , 'connect' , mock_connect )
93
+ monkeypatch .setattr (tables , 'get_table' , mock_table_get )
94
+ expect_table_list = {
95
+ 'oid' : 17408 ,
96
+ 'name' : 'Authors' ,
97
+ 'schema' : schema_oid ,
98
+ 'description' : 'a description on the authors table.'
99
+ }
100
+ actual_table_list = tables .list_ (schema_oid = 2200 , database_id = 11 , request = request )
101
+ assert actual_table_list == expect_table_list
102
+
103
+
67
104
def test_tables_delete (rf , monkeypatch ):
68
105
request = rf .post ('/api/rpc/v0' , data = {})
69
106
request .user = User (username = 'alice' , password = 'pass1234' )
0 commit comments