Skip to content

Commit

Permalink
Move sample project to tests
Browse files Browse the repository at this point in the history
also cleanup tests
  • Loading branch information
danialkeimasi committed Aug 12, 2023
1 parent f0f66cf commit 5617091
Show file tree
Hide file tree
Showing 26 changed files with 79 additions and 175 deletions.
1 change: 1 addition & 0 deletions django_nextjs/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.middleware.csrf import get_token as get_csrf_token
from django.template.loader import render_to_string
from multidict import MultiMapping

from .app_settings import NEXTJS_SERVER_URL
from .utils import filter_mapping_obj

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "tests.settings"
DJANGO_SETTINGS_MODULE = "tests.sample.djproject.settings"
norecursedirs = ".git"
django_find_project = false
pythonpath = ["."]
Expand Down
Empty file removed sample/project/__init__.py
Empty file.
126 changes: 0 additions & 126 deletions sample/project/settings.py

This file was deleted.

17 changes: 0 additions & 17 deletions sample/project/templates/index.html

This file was deleted.

1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"pytest-cov",
"pytest-django",
"pytest-asyncio",
"daphne", # used in tests
"black",
"isort",
]
Expand Down
8 changes: 4 additions & 4 deletions sample/project/asgi.py → tests/sample/djproject/asgi.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import os

from django.core.asgi import get_asgi_application
from django.urls import re_path, path
from django.urls import path, re_path

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djproject.settings")
django_asgi_app = get_asgi_application()

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django_nextjs.proxy import NextJSProxyHttpConsumer, NextJSProxyWebsocketConsumer

from django.conf import settings

from django_nextjs.proxy import NextJSProxyHttpConsumer, NextJSProxyWebsocketConsumer

# put your custom routes here if you need
http_routes = [re_path(r"", django_asgi_app)]
websocket_routers = []
Expand Down
19 changes: 9 additions & 10 deletions tests/settings.py → tests/sample/djproject/settings.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import os
from pathlib import Path

BASE_DIR = Path(__file__).resolve().parent.parent

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
SECRET_KEY = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

DEBUG = True
USE_TZ = False

INSTALLED_APPS = [
"daphne",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django_nextjs.apps.DjangoNextJSConfig",
]

MIDDLEWARE = [
Expand All @@ -22,12 +25,12 @@
"django.contrib.messages.middleware.MessageMiddleware",
]

# ROOT_URLCONF = "tests.urls"
ROOT_URLCONF = "djproject.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": [BASE_DIR / "djproject" / "templates"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand All @@ -40,12 +43,8 @@
},
]

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
WSGI_APPLICATION = "djproject.wsgi.application"
ASGI_APPLICATION = "djproject.asgi.application"

STATIC_URL = "/static/"

Expand Down
15 changes: 15 additions & 0 deletions tests/sample/djproject/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "django_nextjs/document_base.html" %}


{% block head %}
<title>head</title>
{{ block.super }}
<meta name="description" content="head">
{% endblock %}


{% block body %}
<span>pre_body_{{ request.path_info }}</span>
{{ block.super }}
<span>post_body_{{ request.path_info }}</span>
{% endblock %}
2 changes: 1 addition & 1 deletion sample/project/urls.py → tests/sample/djproject/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from django.urls import path, include
from django.urls import include, path

from django_nextjs.render import render_nextjs_page

Expand Down
2 changes: 1 addition & 1 deletion sample/project/wsgi.py → tests/sample/djproject/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djproject.settings")

application = get_wsgi_application()
2 changes: 1 addition & 1 deletion sample/manage.py → tests/sample/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djproject.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export default function Home() {
return (
<div>
<div>/app</div>
<Link href="/app/second">Go To /app/second</Link>
<Link href="/app/second" id="2">
/app/second
</Link>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export default function Home() {
return (
<div>
<div>/app/second</div>
<Link href="/app">Go To /app</Link>
<Link href="/app" id="1">
/app
</Link>
</div>
);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions tests/test_live.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# import pytest
# from playwright.async_api import Page, expect
# from pytest_django.live_server_helper import LiveServer

# def test_homepage_has_Playwright_in_title_and_get_started_link_linking_to_the_intro_page(page: Page):
# page.goto("https://playwright.dev/")

# # Expect a title "to contain" a substring.
# expect(page).to_have_title(re.compile("Playwright"))

# # create a locator
# get_started = page.get_by_role("link", name="Get started")

# # Expect an attribute "to be strictly equal" to the value.
# expect(get_started).to_have_attribute("href", "/docs/intro")

# # Click the get started link.
# get_started.click()

# # Expects the URL to contain intro.
# expect(page).to_have_url(re.compile(".*intro"))


# @pytest.mark.asyncio
# async def test_dispatch_raises_exception_when_not_in_debug_mode(page: Page, live_server: LiveServer):
# await page.goto(live_server.url + "/app")

# expect(page).to_have_title("pre_body_/app")
# expect(page).to_have_title("post_body_/app")

# btn_goto_2 = page.get_by_role("link", name="/app/second")
# expect(btn_goto_2).to_have_attribute("href", "/app/second")

# btn_goto_2.click()

# expect()
15 changes: 3 additions & 12 deletions tests/test_proxy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
from django.conf import settings
from django.test import RequestFactory
from django_nextjs.proxy import NextJSProxyView

from django_nextjs.exceptions import NextJSImproperlyConfigured
from django.test import RequestFactory
from django.conf import settings
from django_nextjs.proxy import NextJSProxyView


def test_dispatch_raises_exception_when_not_in_debug_mode(rf: RequestFactory):
Expand All @@ -13,12 +13,3 @@ def test_dispatch_raises_exception_when_not_in_debug_mode(rf: RequestFactory):
view = NextJSProxyView.as_view()
with pytest.raises(NextJSImproperlyConfigured):
view(request)


def test_(rf: RequestFactory):
settings.DEBUG = True

request = rf.get("/test")
view = NextJSProxyView.as_view()

# TODO:

0 comments on commit 5617091

Please sign in to comment.