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

Support 202407 #104

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading