Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homepage changes - Modify Connections to Databases #3710

Merged
merged 14 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions mathesar/rpc/database_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

from mathesar.utils import permissions
from mathesar.rpc.exceptions.handlers import handle_rpc_exceptions
from mathesar.rpc.servers import ServerInfo
from mathesar.rpc.databases import DatabaseInfo
from mathesar.rpc.configured_roles import ConfiguredRoleInfo


class DatabaseConnectionResult(TypedDict):
Expand All @@ -18,20 +21,20 @@ class DatabaseConnectionResult(TypedDict):
Database, and ConfiguredRole models, as well as a UserDatabaseRoleMap entry.

Attributes:
server_id: The Django ID of the Server model instance.
database_id: The Django ID of the Database model instance.
configured_role_id: The Django ID of the ConfiguredRole model instance.
server: Information on the Server model instance.
database: Information on the Database model instance.
configured_role: Information on the ConfiguredRole model instance.
"""
server_id: int
database_id: int
configured_role_id: int
server: ServerInfo
database: DatabaseInfo
configured_role: ConfiguredRoleInfo

@classmethod
def from_model(cls, model):
return cls(
server_id=model.server.id,
database_id=model.database.id,
configured_role_id=model.configured_role.id,
server=ServerInfo.from_model(model.server),
database=DatabaseInfo.from_model(model.database),
configured_role=ConfiguredRoleInfo.from_model(model.configured_role),
)


Expand Down
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
8 changes: 4 additions & 4 deletions mathesar/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
path('administration/update/', views.admin_home, name='admin_update'),
path('shares/tables/<slug>/', views.shared_table, name='shared_table'),
path('shares/explorations/<slug>/', views.shared_query, name='shared_query'),
path('connections/', views.connections, name='connections'),
path('db/<connection_id>/', views.schemas, name='schemas'),
path('databases/', views.databases, name='databases'),
path('db/<database_id>/', views.schemas, name='schemas'),
path('i18n/', include('django.conf.urls.i18n')),
re_path(
r'^db/(?P<connection_id>\w+)/(?P<schema_id>\w+)/',
views.schemas,
r'^db/(?P<database_id>\w+)/(?P<schema_id>\w+)/',
views.schemas_home,
name='schema_home'
),
]
Loading
Loading