Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pavish committed Jul 25, 2024
1 parent b328700 commit 5c2e9c8
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions mathesar/tests/rpc/test_database_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
"""
from mathesar.models.users import User
from mathesar.models.base import Database, ConfiguredRole, Server, UserDatabaseRoleMap
from mathesar.rpc import database_setup
from mathesar.rpc import database_setup, servers, configured_roles, databases


def test_create_new(monkeypatch, rf):
test_sample_data = ["movie_collection"]
test_database = "mathesar42"
request = rf.post("/api/rpc/v0/", data={})
request.user = User(username="alice", password="pass1234")
server_model = Server(id=2, host="example.com", port=5432)
db_model = Database(id=3, name=test_database, server=server_model)
role_model = ConfiguredRole(id=4, name="matheuser", server=server_model)

def mock_set_up_new_for_user(database, user, sample_data=[]):
if not (
Expand All @@ -23,9 +26,6 @@ def mock_set_up_new_for_user(database, user, sample_data=[]):
and sample_data == test_sample_data
):
raise AssertionError("incorrect parameters passed")
server_model = Server(id=2, host="example.com", port=5432)
db_model = Database(id=3, name=test_database, server=server_model)
role_model = ConfiguredRole(id=4, name="matheuser", server=server_model)
return UserDatabaseRoleMap(
user=user, database=db_model, configured_role=role_model, server=server_model
)
Expand All @@ -36,7 +36,9 @@ def mock_set_up_new_for_user(database, user, sample_data=[]):
mock_set_up_new_for_user,
)
expect_response = database_setup.DatabaseConnectionResult(
server_id=2, database_id=3, configured_role_id=4
server=servers.ServerInfo.from_model(server_model),
database=databases.DatabaseInfo.from_model(db_model),
configured_role=configured_roles.ConfiguredRoleInfo.from_model(role_model)
)

actual_response = database_setup.create_new(
Expand All @@ -54,6 +56,9 @@ def test_connect_existing(monkeypatch, rf):
test_password = "ernie1234"
request = rf.post("/api/rpc/v0/", data={})
request.user = User(username="alice", password="pass1234")
server_model = Server(id=2, host="example.com", port=5432)
db_model = Database(id=3, name=test_database, server=server_model)
role_model = ConfiguredRole(id=4, name="matheuser", server=server_model)

def mock_set_up_preexisting_database_for_user(
host, port, database_name, role_name, password, user, sample_data=[]
Expand All @@ -68,9 +73,6 @@ def mock_set_up_preexisting_database_for_user(
and sample_data == test_sample_data
):
raise AssertionError("incorrect parameters passed")
server_model = Server(id=2, host="example.com", port=5432)
db_model = Database(id=3, name=test_database, server=server_model)
role_model = ConfiguredRole(id=4, name="matheuser", server=server_model)
return UserDatabaseRoleMap(
user=user, database=db_model, configured_role=role_model, server=server_model
)
Expand All @@ -81,7 +83,9 @@ def mock_set_up_preexisting_database_for_user(
mock_set_up_preexisting_database_for_user,
)
expect_response = database_setup.DatabaseConnectionResult(
server_id=2, database_id=3, configured_role_id=4
server=servers.ServerInfo.from_model(server_model),
database=databases.DatabaseInfo.from_model(db_model),
configured_role=configured_roles.ConfiguredRoleInfo.from_model(role_model)
)

actual_response = database_setup.connect_existing(
Expand Down

0 comments on commit 5c2e9c8

Please sign in to comment.