Skip to content

Commit e601a5e

Browse files
committed
add tests and docs
1 parent 9592f5c commit e601a5e

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

docs/docs/api/rpc.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ To use an RPC function:
6060
options:
6161
members:
6262
- list_
63+
- get_
6364
- delete
6465
- TableInfo
6566

mathesar/tests/rpc/test_endpoints.py

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
"tables.list",
4545
[user_is_authenticated]
4646
),
47+
(
48+
tables.get_,
49+
"tables.get",
50+
[user_is_authenticated]
51+
),
4752
(
4853
tables.delete,
4954
"tables.delete",

mathesar/tests/rpc/test_tables.py

+37
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,43 @@ def mock_table_info(_schema_oid, conn):
6464
assert actual_table_list == expect_table_list
6565

6666

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+
67104
def test_tables_delete(rf, monkeypatch):
68105
request = rf.post('/api/rpc/v0', data={})
69106
request.user = User(username='alice', password='pass1234')

0 commit comments

Comments
 (0)