Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move testapp out of tests/ and rename main module #189

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -205,119 +205,119 @@
"line_number": 19
}
],
"tests/conftest.py": [
"conftest.py": [
{
"type": "Secret Keyword",
"filename": "tests/conftest.py",
"filename": "conftest.py",
"hashed_secret": "e5e9fa1ba31ecd1ae84f75caaa474f3a663f05f4",
"is_verified": false,
"line_number": 120
"line_number": 123
}
],
"tests/mitol/common/utils/test_urls.py": [
"tests/common/utils/test_urls.py": [
{
"type": "Basic Auth Credentials",
"filename": "tests/mitol/common/utils/test_urls.py",
"filename": "tests/common/utils/test_urls.py",
"hashed_secret": "9d4e1e23bd5b727046a9e3b4b7db57bd8d6ee684",
"is_verified": false,
"line_number": 18
}
],
"tests/mitol/digitalcredentials/test_backend.py": [
"tests/digitalcredentials/test_backend.py": [
{
"type": "Secret Keyword",
"filename": "tests/mitol/digitalcredentials/test_backend.py",
"filename": "tests/digitalcredentials/test_backend.py",
"hashed_secret": "6367c48dd193d56ea7b0baad25b19455e529f5ee",
"is_verified": false,
"line_number": 150
}
],
"tests/mitol/digitalcredentials/test_requests_utils.py": [
"tests/digitalcredentials/test_requests_utils.py": [
{
"type": "Base64 High Entropy String",
"filename": "tests/mitol/digitalcredentials/test_requests_utils.py",
"filename": "tests/digitalcredentials/test_requests_utils.py",
"hashed_secret": "00df9aef8d11911143efbe3abdbd640d3d18cf06",
"is_verified": false,
"line_number": 60
}
],
"tests/mitol/google_sheets/test_api.py": [
"tests/google_sheets/test_api.py": [
{
"type": "Secret Keyword",
"filename": "tests/mitol/google_sheets/test_api.py",
"filename": "tests/google_sheets/test_api.py",
"hashed_secret": "a0281cd072cea8e80e7866b05dc124815760b6c9",
"is_verified": false,
"line_number": 46
}
],
"tests/mitol/google_sheets/test_utils.py": [
"tests/google_sheets/test_utils.py": [
{
"type": "Secret Keyword",
"filename": "tests/mitol/google_sheets/test_utils.py",
"filename": "tests/google_sheets/test_utils.py",
"hashed_secret": "43ed4c2d8375dfc89e3dc8c917f404b9481d355b",
"is_verified": false,
"line_number": 15
}
],
"tests/mitol/google_sheets/test_views.py": [
"tests/google_sheets/test_views.py": [
{
"type": "Secret Keyword",
"filename": "tests/mitol/google_sheets/test_views.py",
"filename": "tests/google_sheets/test_views.py",
"hashed_secret": "43ed4c2d8375dfc89e3dc8c917f404b9481d355b",
"is_verified": false,
"line_number": 29
}
],
"tests/testapp/settings/dev.py": [
"testapp/main/settings/dev.py": [
{
"type": "Secret Keyword",
"filename": "tests/testapp/settings/dev.py",
"filename": "testapp/main/settings/dev.py",
"hashed_secret": "6367c48dd193d56ea7b0baad25b19455e529f5ee",
"is_verified": false,
"line_number": 17
}
],
"tests/testapp/settings/example.dev.py": [
"testapp/main/settings/example.dev.py": [
{
"type": "Secret Keyword",
"filename": "tests/testapp/settings/example.dev.py",
"filename": "testapp/main/settings/example.dev.py",
"hashed_secret": "6367c48dd193d56ea7b0baad25b19455e529f5ee",
"is_verified": false,
"line_number": 14
}
],
"tests/testapp/settings/shared.py": [
"testapp/main/settings/shared.py": [
{
"type": "Secret Keyword",
"filename": "tests/testapp/settings/shared.py",
"filename": "testapp/main/settings/shared.py",
"hashed_secret": "8f2581750096043a1c68bedea8cfa6e13ad1a2e4",
"is_verified": false,
"line_number": 40
},
{
"type": "Basic Auth Credentials",
"filename": "tests/testapp/settings/shared.py",
"filename": "testapp/main/settings/shared.py",
"hashed_secret": "afc848c316af1a89d49826c5ae9d00ed769415f3",
"is_verified": false,
"line_number": 120
},
{
"type": "Secret Keyword",
"filename": "tests/testapp/settings/shared.py",
"filename": "testapp/main/settings/shared.py",
"hashed_secret": "9bc34549d565d9505b287de0cd20ac77be1d3f2c",
"is_verified": false,
"line_number": 200
}
],
"tests/testapp/settings/test.py": [
"testapp/main/settings/test.py": [
{
"type": "Secret Keyword",
"filename": "tests/testapp/settings/test.py",
"filename": "testapp/main/settings/test.py",
"hashed_secret": "6367c48dd193d56ea7b0baad25b19455e529f5ee",
"is_verified": false,
"line_number": 9
}
]
},
"generated_at": "2025-02-25T16:15:37Z"
"generated_at": "2025-02-26T21:06:50Z"
}
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ This repository is the home of MIT Open Learning's reusable django apps.

This set of libraries is managed using [uv](https://docs.astral.sh/uv/).

### Setup

To run this app in local development mode, copy `testapp/main/settings/example.dev.py` to `testapp/main/settings/dev.py`. This file has the same defaults as `testapp/main/settings/test.py`, but it is gitignored so you can safely add secrets to it. `manage.py` and `main/wsgi.py` both load `dev.py`.


#### Use on your host system

- Install `xmlsec` native libraries for your OS: https://xmlsec.readthedocs.io/en/stable/install.html
Expand Down Expand Up @@ -63,7 +68,7 @@ To add a new one, it's easiest to copy one of the existing apps. There's one cal
* Under `[tool.uv.sources]`, add a new entry for the new app, using (again) the same format as the other entries.
4. Test building: `uv build --package mitol-django-<appname>` . (This ensures that uv is OK with your changes.)
5. Add space for the app in the `tests` app: `mkdir tests/mitol/<appname>` and add a blank `__init__.py` to it.
6. Add the app to `testapp/settings/shared.py`
6. Add the app to `testapp/main/settings/shared.py`
* You must add it to `INSTALLED_APPS`.
* If your app has configuration settings, add to the `import_settings_module` call at the top too.

Expand Down
28 changes: 27 additions & 1 deletion tests/conftest.py → conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from datetime import timedelta # noqa: INP001
import json
from contextlib import contextmanager
from datetime import timedelta
from os import environ
from pathlib import Path
from types import SimpleNamespace

import pytest
Expand Down Expand Up @@ -119,3 +122,26 @@ def google_sheets_client_creds_settings(settings):
settings.MITOL_GOOGLE_SHEETS_DRIVE_CLIENT_ID = "nhijg1i.apps.googleusercontent.com"
settings.MITOL_GOOGLE_SHEETS_DRIVE_CLIENT_SECRET = "secret" # noqa: S105
return settings


@pytest.fixture(scope="session")
def open_data_fixture_file():
"""Create a fixture that provides a function to load data fixtures"""

@contextmanager
def _open_data_fixture_file(path):
with Path.open(Path(__file__).parent / "tests/data" / path, "r") as f:
yield f

return _open_data_fixture_file


@pytest.fixture(scope="session")
def load_data_fixture_json(open_data_fixture_file):
"""Return a function that will load fixture data as json"""

def _load_data_fixture_json(path):
with open_data_fixture_file(path) as f:
return json.load(f)

return _load_data_fixture_json
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ exclude = ["BUILD", "pyproject.toml"]
[tool.pytest.ini_options]
addopts = "--cov . --cov-report term --cov-report html --cov-report xml --reuse-db"
norecursedirs = ".git .tox .* CVS _darcs {arch} *.egg dist"
DJANGO_SETTINGS_MODULE = "testapp.settings.test"
DJANGO_SETTINGS_MODULE = "main.settings.test"
# -- recommended but optional:
python_files = ["tests/mitol/**/test_*.py"]
pythonpath = ["src", "tests"]
python_files = ["tests/**/test_*.py"]
pythonpath = ["testapp", "src", "tests"]

[tool.django-stubs]
django_settings_module = "testapp.settings.test"
django_settings_module = "main.settings.test"

[tool.mypy]
namespace_packages = true
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/testapp/admin.py → testapp/main/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.contrib import admin

from testapp.models import DemoCourseware
from main.models import DemoCourseware


@admin.register(DemoCourseware)
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/factories.py → testapp/main/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from mitol.payment_gateway.api import CartItem, Order, Refund

from testapp.models import DemoCourseware
from main.models import DemoCourseware

FAKE = faker.Factory.create()

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Migration(migrations.Migration):
verbose_name="ID",
),
),
("second_levels", models.ManyToManyField(to="testapp.SecondLevel2")),
("second_levels", models.ManyToManyField(to="main.SecondLevel2")),
],
),
migrations.CreateModel(
Expand All @@ -114,7 +114,7 @@ class Migration(migrations.Migration):
"second_level",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="testapp.SecondLevel1",
to="main.SecondLevel1",
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Migration(migrations.Migration):
dependencies = [
("testapp", "0001_initial"),
("main", "0001_initial"),
]

operations = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("testapp", "0002_auditabletestmodel"),
("main", "0002_auditabletestmodel"),
]

operations = [
Expand Down Expand Up @@ -41,7 +41,7 @@ class Migration(migrations.Migration):
models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="testapp.auditabletestmodel",
to="main.auditabletestmodel",
),
),
],
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""
Dev-only settings

Copy this file to testapp/settings/dev.py. DO NOT RENAME!
Copy this file to main/settings/dev.py. DO NOT RENAME!

You can then modify the copied file, testapp/settings/dev.py is gitignored.
You can then modify the copied file, main/settings/dev.py is gitignored.
"""

from mitol.common.envs import import_settings_modules

import_settings_modules("testapp.settings.shared")
import_settings_modules("main.settings.shared")

MITOL_DIGITAL_CREDENTIALS_VERIFY_SERVICE_BASE_URL = "http://localhost:5000/"
MITOL_DIGITAL_CREDENTIALS_BUILD_CREDENTIAL_FUNC = (
"mitol.digitalcredentials.testapp.integration.build_credential"
"mitol.digitalcredentials.main.integration.build_credential"
)
MITOL_DIGITAL_CREDENTIALS_HMAC_SECRET = "abc123" # noqa: S105
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"""
Dev-only settings

Copy this file to testapp/settings/dev.py. DO NOT RENAME!
Copy this file to main/settings/dev.py. DO NOT RENAME!

You can then modify the copied file, testapp/settings/dev.py is gitignored.
You can then modify the copied file, main/settings/dev.py is gitignored.
"""

from mitol.common.envs import import_settings_modules

import_settings_modules("testapp.settings.shared")
import_settings_modules("main.settings.shared")
MITOL_DIGITAL_CREDENTIALS_VERIFY_SERVICE_BASE_URL = "http://localhost:5000/"
MITOL_DIGITAL_CREDENTIALS_BUILD_CREDENTIAL_FUNC = "testapp.integration.build_credential"
MITOL_DIGITAL_CREDENTIALS_BUILD_CREDENTIAL_FUNC = "main.integration.build_credential"
MITOL_DIGITAL_CREDENTIALS_HMAC_SECRET = "abc123" # noqa: S105


# mail app settings, customize for local development
MITOL_MAIL_MESSAGE_CLASSES = ["testapp.messages.SampleMessage"]
MITOL_MAIL_MESSAGE_CLASSES = ["main.messages.SampleMessage"]

MITOL_MAIL_FROM_EMAIL = "invalid@localhost"
MITOL_MAIL_REPLY_TO_ADDRESS = "invalid@localhost"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Django settings for testapp project.
Django settings for main project.

Generated by 'django-admin startproject' using Django 2.2.15.

Expand Down Expand Up @@ -73,7 +73,7 @@
"mitol.olposthog.apps.OlPosthog",
"mitol.transcoding.apps.Transcoding",
# test app, integrates the reusable apps
"testapp",
"main",
]

MIDDLEWARE = [
Expand All @@ -86,12 +86,12 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "testapp.urls"
ROOT_URLCONF = "main.urls"

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [BASE_DIR + "/testapp/templates/"],
"DIRS": [BASE_DIR + "/main/templates/"],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
Expand All @@ -104,7 +104,7 @@
},
]

WSGI_APPLICATION = "testapp.wsgi.application"
WSGI_APPLICATION = "main.wsgi.application"

REST_FRAMEWORK = {"TEST_REQUEST_DEFAULT_FORMAT": "json"}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from mitol.common.envs import import_settings_modules

import_settings_modules("testapp.settings.shared")
import_settings_modules("main.settings.shared")

MITOL_DIGITAL_CREDENTIALS_VERIFY_SERVICE_BASE_URL = "http://localhost:5000/"
MITOL_DIGITAL_CREDENTIALS_BUILD_CREDENTIAL_FUNC = "testapp.integration.build_credential"
MITOL_DIGITAL_CREDENTIALS_BUILD_CREDENTIAL_FUNC = "main.integration.build_credential"
MITOL_DIGITAL_CREDENTIALS_HMAC_SECRET = "abc123" # noqa: S105

# mail app settings
MITOL_MAIL_MESSAGE_CLASSES = ["testapp.messages.SampleMessage"]
MITOL_MAIL_MESSAGE_CLASSES = ["main.messages.SampleMessage"]

MITOL_MAIL_FROM_EMAIL = "invalid@localhost"
MITOL_MAIL_REPLY_TO_ADDRESS = "invalid@localhost"
Expand Down
Loading