Skip to content

Commit

Permalink
feat: custom path to Django admin
Browse files Browse the repository at this point in the history
  • Loading branch information
ar4s committed Oct 5, 2024
1 parent 31c4c31 commit 491e458
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: tests
on: [pull_request, push]
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
5 changes: 5 additions & 0 deletions cardie/cardie/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [
Expand Down
21 changes: 21 additions & 0 deletions cardie/cardie/tests.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 6 additions & 2 deletions cardie/cardie/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]
12 changes: 12 additions & 0 deletions cardie/fixtures/server.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
2 changes: 0 additions & 2 deletions cardie/main/tests.py

This file was deleted.

0 comments on commit 491e458

Please sign in to comment.