Skip to content

Commit

Permalink
Drop codenames (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
soininen authored Nov 1, 2024
2 parents 4677999 + ea83c92 commit 001b05e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 222 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

- The ``codename`` field and related stuff has been removed from ``DatabaseMapping``.

### Fixed

### Security
Expand Down
16 changes: 0 additions & 16 deletions spinedb_api/db_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@

from datetime import datetime, timezone
from functools import partialmethod
import hashlib
import logging
import os
import time
from types import MethodType
from alembic.config import Config
from alembic.environment import EnvironmentContext
Expand Down Expand Up @@ -129,7 +127,6 @@ def __init__(
username=None,
upgrade=False,
backup_url="",
codename=None,
create=False,
apply_filters=True,
memory=False,
Expand All @@ -143,7 +140,6 @@ def __init__(
upgrade (bool, optional): Whether the DB at the given `url` should be upgraded to the most recent
version.
backup_url (str, optional): A URL to backup the DB before upgrading.
codename (str, optional): A name to identify this object in your application.
create (bool, optional): Whether to create a new Spine DB at the given `url` if it's not already one.
apply_filters (bool, optional): Whether to apply filters in the `url`'s query segment.
memory (bool, optional): Whether to use a SQLite memory DB as replacement for the original one.
Expand All @@ -165,7 +161,6 @@ def __init__(
except ArgumentError as error:
raise SpineDBAPIError("Could not parse the given URL. Please check that it is valid.") from error
self.username = username if username else "anon"
self.codename = self._make_codename(codename)
self._memory = memory
self._memory_dirty = False
self._original_engine = self.create_engine(
Expand Down Expand Up @@ -211,17 +206,6 @@ def _make_sq(self, item_type):
sq_name = self._sq_name_by_item_type[item_type]
return getattr(self, sq_name)

def _make_codename(self, codename):
if codename:
return str(codename)
if not self.sa_url.drivername.startswith("sqlite"):
return self.sa_url.database
if self.sa_url.database is not None:
return os.path.splitext(os.path.basename(self.sa_url.database))[0]
hashing = hashlib.sha1()
hashing.update(bytes(str(time.time()), "utf-8"))
return hashing.hexdigest()

@staticmethod
def get_upgrade_db_prompt_data(url, create=False):
"""Returns data to prompt the user what to do if the DB at the given url is not the latest version.
Expand Down
179 changes: 0 additions & 179 deletions spinedb_api/perfect_split.py

This file was deleted.

53 changes: 26 additions & 27 deletions tests/test_DatabaseMapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -2717,11 +2717,11 @@ def test_add_relationship_classes_with_same_name(self):
def test_add_relationship_class_with_same_name_as_existing_one(self):
"""Test that adding a relationship class with an already taken name raises an integrity error."""
query_wrapper = create_query_wrapper(self._db_map)
with mock.patch.object(CustomDatabaseMapping, "query") as mock_query, mock.patch.object(
CustomDatabaseMapping, "object_class_sq"
) as mock_object_class_sq, mock.patch.object(
CustomDatabaseMapping, "wide_relationship_class_sq"
) as mock_wide_rel_cls_sq:
with (
mock.patch.object(CustomDatabaseMapping, "query") as mock_query,
mock.patch.object(CustomDatabaseMapping, "object_class_sq") as mock_object_class_sq,
mock.patch.object(CustomDatabaseMapping, "wide_relationship_class_sq") as mock_wide_rel_cls_sq,
):
mock_query.side_effect = query_wrapper
mock_object_class_sq.return_value = [
KeyedTuple([1, "fish"], labels=["id", "name"]),
Expand All @@ -2738,9 +2738,11 @@ def test_add_relationship_class_with_same_name_as_existing_one(self):
def test_add_relationship_class_with_invalid_object_class(self):
"""Test that adding a relationship class with a non existing object class raises an integrity error."""
query_wrapper = create_query_wrapper(self._db_map)
with mock.patch.object(CustomDatabaseMapping, "query") as mock_query, mock.patch.object(
CustomDatabaseMapping, "object_class_sq"
) as mock_object_class_sq, mock.patch.object(CustomDatabaseMapping, "wide_relationship_class_sq"):
with (
mock.patch.object(CustomDatabaseMapping, "query") as mock_query,
mock.patch.object(CustomDatabaseMapping, "object_class_sq") as mock_object_class_sq,
mock.patch.object(CustomDatabaseMapping, "wide_relationship_class_sq"),
):
mock_query.side_effect = query_wrapper
mock_object_class_sq.return_value = [KeyedTuple([1, "fish"], labels=["id", "name"])]
with self.assertRaises(SpineIntegrityError):
Expand Down Expand Up @@ -2791,13 +2793,12 @@ def test_add_relationship_identical_to_existing_one(self):
raises an integrity error.
"""
query_wrapper = create_query_wrapper(self._db_map)
with mock.patch.object(CustomDatabaseMapping, "query") as mock_query, mock.patch.object(
CustomDatabaseMapping, "object_sq"
) as mock_object_sq, mock.patch.object(
CustomDatabaseMapping, "wide_relationship_class_sq"
) as mock_wide_rel_cls_sq, mock.patch.object(
CustomDatabaseMapping, "wide_relationship_sq"
) as mock_wide_rel_sq:
with (
mock.patch.object(CustomDatabaseMapping, "query") as mock_query,
mock.patch.object(CustomDatabaseMapping, "object_sq") as mock_object_sq,
mock.patch.object(CustomDatabaseMapping, "wide_relationship_class_sq") as mock_wide_rel_cls_sq,
mock.patch.object(CustomDatabaseMapping, "wide_relationship_sq") as mock_wide_rel_sq,
):
mock_query.side_effect = query_wrapper
mock_object_sq.return_value = [
KeyedTuple([1, 10, "nemo"], labels=["id", "class_id", "name"]),
Expand All @@ -2817,12 +2818,11 @@ def test_add_relationship_identical_to_existing_one(self):
def test_add_relationship_with_invalid_class(self):
"""Test that adding a relationship with an invalid class raises an integrity error."""
query_wrapper = create_query_wrapper(self._db_map)
with mock.patch.object(CustomDatabaseMapping, "query") as mock_query, mock.patch.object(
CustomDatabaseMapping, "object_sq"
) as mock_object_sq, mock.patch.object(
CustomDatabaseMapping, "wide_relationship_class_sq"
) as mock_wide_rel_cls_sq, mock.patch.object(
CustomDatabaseMapping, "wide_relationship_sq"
with (
mock.patch.object(CustomDatabaseMapping, "query") as mock_query,
mock.patch.object(CustomDatabaseMapping, "object_sq") as mock_object_sq,
mock.patch.object(CustomDatabaseMapping, "wide_relationship_class_sq") as mock_wide_rel_cls_sq,
mock.patch.object(CustomDatabaseMapping, "wide_relationship_sq"),
):
mock_query.side_effect = query_wrapper
mock_object_sq.return_value = [
Expand All @@ -2840,12 +2840,11 @@ def test_add_relationship_with_invalid_class(self):
def test_add_relationship_with_invalid_object(self):
"""Test that adding a relationship with an invalid object raises an integrity error."""
query_wrapper = create_query_wrapper(self._db_map)
with mock.patch.object(CustomDatabaseMapping, "query") as mock_query, mock.patch.object(
CustomDatabaseMapping, "object_sq"
) as mock_object_sq, mock.patch.object(
CustomDatabaseMapping, "wide_relationship_class_sq"
) as mock_wide_rel_cls_sq, mock.patch.object(
CustomDatabaseMapping, "wide_relationship_sq"
with (
mock.patch.object(CustomDatabaseMapping, "query") as mock_query,
mock.patch.object(CustomDatabaseMapping, "object_sq") as mock_object_sq,
mock.patch.object(CustomDatabaseMapping, "wide_relationship_class_sq") as mock_wide_rel_cls_sq,
mock.patch.object(CustomDatabaseMapping, "wide_relationship_sq"),
):
mock_query.side_effect = query_wrapper
mock_object_sq.return_value = [
Expand Down

0 comments on commit 001b05e

Please sign in to comment.