Skip to content

Commit f5f3324

Browse files
committed
Fix tests
1 parent 7e13739 commit f5f3324

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

netbox_config_diff/migrations/0002_add_script.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1+
import logging
12
import os
23

34
from core.choices import ManagedFileRootPathChoices
45
from django.conf import settings
56
from django.db import migrations
67
from pathlib import Path
78

9+
logger = logging.getLogger(__name__)
810
SCRIPT_NAME = "config_diff.py"
911

1012

1113
def forward_func(apps, schema_editor):
1214
script_path = Path(__file__).parent.parent.joinpath("scripts", SCRIPT_NAME)
1315
new_path = os.path.join(settings.SCRIPTS_ROOT, SCRIPT_NAME)
14-
with open(script_path, "r") as script_file, open(new_path, "w") as new_file:
15-
new_file.write(script_file.read())
16+
try:
17+
with open(script_path, "r") as script_file, open(new_path, "w") as new_file:
18+
new_file.write(script_file.read())
19+
except FileNotFoundError:
20+
logger.warning(f"Failed to open: {script_path} or {new_path}")
1621

1722
ManagedFile = apps.get_model("core", "ManagedFile")
1823
db_alias = schema_editor.connection.alias

netbox_config_diff/migrations/0004_update_script.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1+
import logging
12
import os
23

34
from django.conf import settings
45
from django.db import migrations
56
from pathlib import Path
67

8+
logger = logging.getLogger(__name__)
9+
710
SCRIPT_NAME = "config_diff.py"
811

912

1013
def forward_func(apps, schema_editor):
1114
script_path = Path(__file__).parent.parent.joinpath("scripts", SCRIPT_NAME)
1215
new_path = os.path.join(settings.SCRIPTS_ROOT, SCRIPT_NAME)
13-
with open(script_path, "r") as script_file, open(new_path, "w") as new_file:
14-
new_file.write(script_file.read())
16+
try:
17+
with open(script_path, "r") as script_file, open(new_path, "w") as new_file:
18+
new_file.write(script_file.read())
19+
except FileNotFoundError:
20+
logger.warning(f"Failed to open: {script_path} or {new_path}")
1521

1622

1723
def reverse_func(apps, schema_editor):

tests/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from unittest.mock import Mock
33

44
import pytest
5+
from django.db import connection
6+
from django.test.utils import setup_databases
57
from faker import Faker
68
from typing_extensions import Unpack
79

@@ -10,6 +12,27 @@
1012
from tests.factories import DataSourceFactory
1113

1214

15+
@pytest.fixture(scope="session")
16+
def django_db_setup(request, django_test_environment, django_db_blocker):
17+
with django_db_blocker.unblock():
18+
with connection.cursor() as cursor:
19+
cursor.execute(
20+
"""
21+
DO $$
22+
BEGIN
23+
CREATE COLLATION IF NOT EXISTS natural_sort (
24+
provider = icu,
25+
locale = 'und-u-kn-true',
26+
deterministic = true
27+
);
28+
END $$;
29+
"""
30+
)
31+
setup_databases(verbosity=request.config.option.verbose, interactive=False, serialized_aliases=[])
32+
33+
yield
34+
35+
1336
class ScriptData(TypedDict, total=False):
1437
site: str | None
1538
devices: list[str] | None

0 commit comments

Comments
 (0)