Skip to content

Commit

Permalink
feat: include test app for django package (#760)
Browse files Browse the repository at this point in the history
* feat: include test app for django package

* feat: include test app for django package

* fix: add Sphinx autodoc
  • Loading branch information
browniebroke committed Jun 10, 2024
1 parent b0f9ab5 commit 8c1eafe
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion project/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: "CHANGELOG.md|.copier-answers.yml|.all-contributorsrc"
exclude: "CHANGELOG.md|.copier-answers.yml|.all-contributorsrc|project"
default_stages: [commit]

ci:
Expand Down
1 change: 1 addition & 0 deletions project/docs/conf.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ release = "0.0.0"
# General configuration
extensions = [
"myst_parser",
"sphinx.ext.autodoc",
]

# The suffix of source filenames.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ DATABASES = {

USE_TZ = True
TIME_ZONE = "UTC"
ROOT_URLCONF = "tests.urls"

INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.admin",
"django.contrib.contenttypes",
"{{ package_name }}",
"tests.testapp",
]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class TestAppConfig(AppConfig):
name = "tests.testapp"
verbose_name = "Test App"
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.db import models


class Blog(models.Model):
name = models.CharField(max_length=50)


class Author(models.Model):
full_name = models.CharField(max_length=50)


class Post(models.Model):
blog = models.ForeignKey(
Blog,
on_delete=models.CASCADE,
related_name="posts",
)
author = models.ForeignKey(
Author,
on_delete=models.CASCADE,
related_name="posts",
)
title = models.CharField(max_length=50)
content = models.TextField()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin
from django.urls import path

urlpatterns = [
path("admin/", admin.site.urls),
]
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ select = [
"D104",
"S101",
]
"project/tests/**/*" = [
"D100",
"D101",
"D102",
"D103",
"D104",
"S101",
]

[tool.pytest.ini_options]
addopts = "-v -Wdefault"
Expand Down
23 changes: 23 additions & 0 deletions tests/test_generate_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,27 @@ def test_django_package_yes(
' "django_snake_farm",',
],
)
_check_file_contents(
dst_path / "tests" / "urls.py",
expected_strs=[
"urlpatterns = [",
' path("admin/", admin.site.urls),',
],
)
_check_file_contents(
dst_path / "tests" / "testapp" / "apps.py",
expected_strs=[
"class TestAppConfig(AppConfig):",
' name = "tests.testapp"',
' verbose_name = "Test App"',
],
)
_check_file_contents(
dst_path / "tests" / "testapp" / "models.py",
expected_strs=[
"class Blog(models.Model):",
],
)
_check_file_contents(
dst_path / "docs" / "index.md",
expected_strs=["configuration"],
Expand Down Expand Up @@ -327,6 +348,8 @@ def test_django_package_no(
assert not (dst_path / "src" / "snake_farm" / "conf.py").exists()
assert not (dst_path / "src" / "snake_farm" / "apps.py").exists()
assert not (dst_path / "tests" / "settings.py").exists()
assert not (dst_path / "tests" / "urls.py").exists()
assert not (dst_path / "tests" / "testapp").exists()
assert not (dst_path / "docs" / "configuration.rst").exists()
_check_file_contents(
dst_path / "pyproject.toml",
Expand Down

0 comments on commit 8c1eafe

Please sign in to comment.