Skip to content

Commit

Permalink
Merge pull request #19 from MatBarba/mbarba/no_username
Browse files Browse the repository at this point in the history
Mbarba/no username
  • Loading branch information
JAlvarezJarreta authored Jul 16, 2024
2 parents bef0981 + dbb2b4a commit 56fe24d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/ensembl/utils/database/unittestdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
from ensembl.utils import StrPath
from ensembl.utils.database.dbconnection import DBConnection, StrURL

TEST_USERNAME = os.environ.get("USER", "pytestuser")


class UnitTestDB:
"""Creates and connects to a new test database, applying the schema and importing the data.
Expand Down Expand Up @@ -84,7 +86,7 @@ def __init__(
db_url = make_url(server_url)
if not name:
name = Path(dump_dir).name if dump_dir else "testdb"
db_name = os.environ["USER"] + "_" + name
db_name = f"{TEST_USERNAME}_{name}"

# Add the database name to the URL
if db_url.get_dialect().name == "sqlite":
Expand Down
8 changes: 4 additions & 4 deletions tests/database/test_dbconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.
"""Unit testing of `ensembl.utils.database.dbconnection` module."""

import os
from pathlib import Path

import pytest
Expand All @@ -27,6 +26,7 @@
from sqlalchemy_utils import create_database, database_exists, drop_database

from ensembl.utils.database import DBConnection, UnitTestDB
from ensembl.utils.database.unittestdb import TEST_USERNAME


class MockBase(DeclarativeBase):
Expand Down Expand Up @@ -84,7 +84,7 @@ def test_dialect(self) -> None:
@pytest.mark.dependency(name="test_db_name", depends=["test_init", "test_dialect"], scope="class")
def test_db_name(self) -> None:
"""Tests `DBConnection.db_name` property."""
expected_db_name = f"{os.environ['USER']}_mock_db"
expected_db_name = f"{TEST_USERNAME}_mock_db"
if self.dbc.dialect == "sqlite":
expected_db_name += ".db"
assert self.dbc.db_name == expected_db_name
Expand Down Expand Up @@ -260,7 +260,7 @@ def test_create_all_tables(request: FixtureRequest) -> None:

# Create a test db
db_url = make_url(request.config.getoption("server"))
db_name = f"{os.environ['USER']}_test_create_all_tables"
db_name = f"{TEST_USERNAME}_test_create_all_tables"
db_url = db_url.set(database=db_name)
if database_exists(db_url):
drop_database(db_url)
Expand All @@ -279,7 +279,7 @@ def test_create_table(request: FixtureRequest) -> None:

# Create a test db
db_url = make_url(request.config.getoption("server"))
db_name = f"{os.environ['USER']}_test_create_table"
db_name = f"{TEST_USERNAME}_test_create_table"
db_url = db_url.set(database=db_name)
if database_exists(db_url):
drop_database(db_url)
Expand Down

0 comments on commit 56fe24d

Please sign in to comment.