Skip to content

Commit

Permalink
ORM configuration Options is missing (postgreSQL) #98
Browse files Browse the repository at this point in the history
  • Loading branch information
20c-ed authored and vegu committed Aug 13, 2024
1 parent 5fbb8c6 commit 21cce69
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
## Unreleased
### Added
- help text for info_traffic
- ORM configuration options exposed
### Fixed
- missing migrations
### Changed
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased:
added:
- help text for info_traffic
- ORM configuration options exposed
fixed:
- missing migrations
changed:
Expand Down
6 changes: 6 additions & 0 deletions src/django_peeringdb/client_adaptor/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"PORT",
"USER",
"PASSWORD",
"OPTIONS",
)


Expand All @@ -16,6 +17,11 @@ def database_settings(db_config):
db[k] = v

db["ENGINE"] = "django.db.backends." + db["ENGINE"]

# Check if the ENGINE is not PostgreSQL, remove OPTIONS if it's present
if db["ENGINE"] != "django.db.backends.postgresql":
db.pop("OPTIONS", None)

return db


Expand Down
77 changes: 77 additions & 0 deletions tests/test_client_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,83 @@ def test_database_settings():
assert db_config == expected


def test_database_settings_postgresql():
db_config = database_settings(
{
"engine": "postgresql",
"name": "test_db",
"host": "localhost",
"port": 5432,
"user": "test_user",
"password": "test_password",
"options": {"options": "-c search_path=peeringdb_schema"},
}
)

expected = {
"ENGINE": "django.db.backends.postgresql",
"NAME": "test_db",
"HOST": "localhost",
"PORT": 5432,
"USER": "test_user",
"PASSWORD": "test_password",
"OPTIONS": {"options": "-c search_path=peeringdb_schema"},
}

assert db_config == expected
assert "OPTIONS" in db_config


def test_database_settings_mysql():
db_config = database_settings(
{
"engine": "mysql",
"name": "test_db",
"host": "localhost",
"port": 3306,
"user": "test_user",
"password": "test_password",
}
)

expected = {
"ENGINE": "django.db.backends.mysql",
"NAME": "test_db",
"HOST": "localhost",
"PORT": 3306,
"USER": "test_user",
"PASSWORD": "test_password",
}

assert db_config == expected


def test_database_settings_mysql_no_options():
db_config = database_settings(
{
"engine": "mysql",
"name": "test_db",
"host": "localhost",
"port": 3306,
"user": "test_user",
"password": "test_password",
"options": {"options": "-c some_option"},
}
)

expected = {
"ENGINE": "django.db.backends.mysql",
"NAME": "test_db",
"HOST": "localhost",
"PORT": 3306,
"USER": "test_user",
"PASSWORD": "test_password",
}

assert db_config == expected
assert "OPTIONS" not in db_config


def test_backend_setup():
Backend.setup()
for model in models.all_models:
Expand Down

0 comments on commit 21cce69

Please sign in to comment.