From a03f3b44eb4c7f40e0f4348806d4ca28257fb3f1 Mon Sep 17 00:00:00 2001 From: Arkadiusz Adamski Date: Fri, 4 Oct 2024 20:55:05 +0200 Subject: [PATCH] feat: custom path to Django admin --- .github/workflows/main.yml | 13 +++++++++++++ cardie/cardie/settings.py | 5 +++++ cardie/cardie/tests.py | 21 +++++++++++++++++++++ cardie/cardie/urls.py | 8 ++++++-- cardie/fixtures/server.json | 12 ++++++++++++ cardie/main/tests.py | 2 -- cardie/main/views.py | 2 +- 7 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 cardie/cardie/tests.py create mode 100644 cardie/fixtures/server.json delete mode 100644 cardie/main/tests.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..886649d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,13 @@ +name: tests +on: [pull_request, push] +env: + DATABASE_URL: sqlite:///cardie/db.sqlite3 +jobs: + test_project: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - run: pip install -r requirements.txt + - run: pip install -r requirements-dev.txt + - run: python cardie/manage.py test cardie diff --git a/cardie/cardie/settings.py b/cardie/cardie/settings.py index 63deb14..9d2944a 100644 --- a/cardie/cardie/settings.py +++ b/cardie/cardie/settings.py @@ -22,6 +22,7 @@ "django-insecure-a_r$cp+uufzh*bdagc!fra@7n10c*ciuleve_4+-cs_bftbb9", ), DJANGO_ALLOWED_HOSTS=(list, ["localhost", "127.0.0.1"]), + ADMIN_PATH=(str, "admin/"), ) # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -39,7 +40,11 @@ ALLOWED_HOSTS = env("DJANGO_ALLOWED_HOSTS") +ADMIN_PATH = env("ADMIN_PATH") +FIXTURE_DIRS = [ + os.path.join(BASE_DIR, "fixtures"), +] # Application definition INSTALLED_APPS = [ diff --git a/cardie/cardie/tests.py b/cardie/cardie/tests.py new file mode 100644 index 0000000..c201fc5 --- /dev/null +++ b/cardie/cardie/tests.py @@ -0,0 +1,21 @@ +from unittest import skip + +from django.test import Client, TestCase, override_settings + + +@override_settings(ADMIN_PATH="foo/") +class AdminTestCase(TestCase): + fixtures = ["server"] + + def setUp(self): + self.client = Client() + + def test_default_path_should_be_admin(self): + response = self.client.get("/admin/", follow=True) + self.assertEqual(response.status_code, 200) + + @skip("This test is failing. Is hard to test this because urls are populated.") + @override_settings(ADMIN_PATH="foo/") + def test_custom_path_should_be_foo(self): + response = self.client.get("/foo/", follow=True) + self.assertEqual(response.status_code, 200) diff --git a/cardie/cardie/urls.py b/cardie/cardie/urls.py index 07d8099..1b3e64e 100644 --- a/cardie/cardie/urls.py +++ b/cardie/cardie/urls.py @@ -14,11 +14,15 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + +from django.conf import settings from django.contrib import admin -from django.urls import path, include +from django.urls import include, path + +ADMIN_PATH = settings.ADMIN_PATH urlpatterns = [ path("", include("main.urls")), path("auth/", include("authentication.urls")), - path('admin/', admin.site.urls), + path(ADMIN_PATH, admin.site.urls), ] diff --git a/cardie/fixtures/server.json b/cardie/fixtures/server.json new file mode 100644 index 0000000..4e3e1d6 --- /dev/null +++ b/cardie/fixtures/server.json @@ -0,0 +1,12 @@ +[ + { + "model": "main.server", + "pk": 1, + "fields": { + "ip": "127.0.0.1", + "production": true, + "allow_create_accounts": true, + "allow_sign_in": true + } + } +] diff --git a/cardie/main/tests.py b/cardie/main/tests.py deleted file mode 100644 index 4929020..0000000 --- a/cardie/main/tests.py +++ /dev/null @@ -1,2 +0,0 @@ - -# Create your tests here. diff --git a/cardie/main/views.py b/cardie/main/views.py index 8b4100a..df1e010 100644 --- a/cardie/main/views.py +++ b/cardie/main/views.py @@ -7,7 +7,7 @@ from django.utils import timezone from django.views.decorators.csrf import csrf_exempt from main.icons import icons -from main.models import Card, Server, TempCard +from main.models import Card, TempCard def index(request):