Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
A legacy Django version (1.18, which is EOL) is now tested,
as well as ensuring that env vars are passed to manage.py.
  • Loading branch information
edmorley committed Sep 12, 2023
1 parent 3ed0739 commit 42b8298
Show file tree
Hide file tree
Showing 18 changed files with 65 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/django.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ mod tests {

#[test]
fn has_management_script_django_project() {
assert!(has_management_script(Path::new("tests/fixtures/django_collectstatic")).unwrap());
assert!(has_management_script(Path::new(
"tests/fixtures/django_staticfiles_latest_django"
))
.unwrap());
}

#[test]
Expand Down
31 changes: 29 additions & 2 deletions tests/django_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use libcnb_test::{assert_contains, assert_empty, BuildConfig, PackResult, TestRu
// them when the Django app is nested inside a subdirectory (such as in backend+frontend monorepos).
#[test]
#[ignore = "integration test"]
fn django_collectstatic() {
fn django_staticfiles_latest_django() {
TestRunner::default().build(
BuildConfig::new(builder(), "tests/fixtures/django_collectstatic"),
BuildConfig::new(builder(), "tests/fixtures/django_staticfiles_latest_django")
// Tests that env vars are passed to the 'manage.py' script invocations.
.env("EXPECTED_ENV_VAR", "1"),
|context| {
assert_empty!(context.pack_stderr);
assert_contains!(
Expand All @@ -24,6 +26,31 @@ fn django_collectstatic() {
);
}

// This tests the oldest Django version that works on Python 3.9 (which is the
// oldest Python that is available on all of our supported builders).
#[test]
#[ignore = "integration test"]
fn django_staticfiles_legacy_django() {
TestRunner::default().build(
BuildConfig::new(builder(), "tests/fixtures/django_staticfiles_legacy_django"),
|context| {
assert_empty!(context.pack_stderr);
assert_contains!(
context.pack_stdout,
indoc! {"
Successfully installed Django-1.8.19
[Generating Django static files]
Running 'manage.py collectstatic'
Linking '/workspace/testapp/static/robots.txt'
1 static file symlinked to '/workspace/staticfiles'.
"}
);
},
);
}

#[test]
#[ignore = "integration test"]
fn django_no_manage_py() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
from pathlib import Path

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

INSTALLED_APPS = [
"django.contrib.staticfiles",
"testapp",
]

STATIC_ROOT = BASE_DIR / "staticfiles"
STATIC_URL = "static/"

# Tests that app env vars are passed to the 'manage.py' script invocations.
assert "EXPECTED_ENV_VAR" in os.environ
10 changes: 10 additions & 0 deletions tests/fixtures/django_staticfiles_legacy_django/manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is the oldest Django version that works on Python 3.9 (which is the
# oldest Python that is available on all of our supported builders).
Django==1.8.19
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.9.18
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@

STATIC_ROOT = BASE_DIR / "staticfiles"
STATIC_URL = "static/"

SECRET_KEY = "example"
2 changes: 1 addition & 1 deletion tests/fixtures/pip_basic/manage.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Tests that manage.py alone doesn't trigger Django collectstatic.
raise Exception("This is not a Django app")
raise RuntimeError("This is not a Django app, so manage.py should not be run!")

0 comments on commit 42b8298

Please sign in to comment.