Skip to content

Commit

Permalink
add tests and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anish9901 committed Jun 4, 2024
1 parent 9592f5c commit e601a5e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/docs/api/rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ To use an RPC function:
options:
members:
- list_
- get_
- delete
- TableInfo

Expand Down
5 changes: 5 additions & 0 deletions mathesar/tests/rpc/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
"tables.list",
[user_is_authenticated]
),
(
tables.get_,
"tables.get",
[user_is_authenticated]
),
(
tables.delete,
"tables.delete",
Expand Down
37 changes: 37 additions & 0 deletions mathesar/tests/rpc/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,43 @@ def mock_table_info(_schema_oid, conn):
assert actual_table_list == expect_table_list


def test_tables_get(rf, monkeypatch):
request = rf.post('/api/rpc/v0', data={})
request.user = User(username='alice', password='pass1234')
schema_oid = 2200
database_id = 11

@contextmanager
def mock_connect(_database_id, user):
if _database_id == database_id and user.username == 'alice':
try:
yield True
finally:
pass
else:
raise AssertionError('incorrect parameters passed')

def mock_table_get(_schema_oid, conn):
if _schema_oid != schema_oid:
raise AssertionError('incorrect parameters passed')
return {
'oid': 17408,
'name': 'Authors',
'schema': schema_oid,
'description': 'a description on the authors table.'
}
monkeypatch.setattr(tables, 'connect', mock_connect)
monkeypatch.setattr(tables, 'get_table', mock_table_get)
expect_table_list = {
'oid': 17408,
'name': 'Authors',
'schema': schema_oid,
'description': 'a description on the authors table.'
}
actual_table_list = tables.list_(schema_oid=2200, database_id=11, request=request)
assert actual_table_list == expect_table_list


def test_tables_delete(rf, monkeypatch):
request = rf.post('/api/rpc/v0', data={})
request.user = User(username='alice', password='pass1234')
Expand Down

0 comments on commit e601a5e

Please sign in to comment.