From 87300885dcfdf5ec8fb90a0aa7a6db60ae6c8fc7 Mon Sep 17 00:00:00 2001 From: Nathan Levesque Date: Wed, 26 Feb 2025 16:09:21 -0500 Subject: [PATCH] Move testapp out of tests/ and rename main module --- .secrets.baseline | 52 ++++----- README.md | 7 +- tests/conftest.py => conftest.py | 28 ++++- pyproject.toml | 8 +- .../main}/__init__.py | 0 {tests/testapp => testapp/main}/admin.py | 2 +- {tests/testapp => testapp/main}/factories.py | 2 +- .../testapp => testapp/main}/integration.py | 0 {tests/testapp => testapp/main}/messages.py | 0 .../main}/migrations/0001_initial.py | 4 +- .../migrations/0002_auditabletestmodel.py | 2 +- .../0003_auditabletestmodelaudit.py | 4 +- .../main/migrations}/__init__.py | 0 {tests/testapp => testapp/main}/models.py | 0 .../main/settings}/__init__.py | 0 .../testapp => testapp/main}/settings/dev.py | 8 +- .../main}/settings/example.dev.py | 10 +- .../main}/settings/shared.py | 10 +- .../testapp => testapp/main}/settings/test.py | 6 +- .../main}/templates/mail/partials/_logo.html | 0 .../main}/templates/mail/sample/body.html | 0 .../main}/templates/mail/sample/subject.txt | 0 {tests/testapp => testapp/main}/urls.py | 2 +- {tests/testapp => testapp/main}/utils.py | 0 {tests/testapp => testapp/main}/views.py | 2 +- {tests/testapp => testapp/main}/wsgi.py | 2 +- {tests => testapp}/manage.py | 2 +- .../{mitol/common/templates => }/__init__.py | 0 .../utils => authentication}/__init__.py | 0 .../authentication/test_serializers.py | 0 .../views}/__init__.py | 0 .../authentication/views/test_djoser.py | 0 .../authentication/views/test_saml.py | 0 tests/{mitol/geoip => common}/__init__.py | 0 .../templates}/__init__.py | 0 .../common/templates/test_render_bundle.py | 0 tests/{mitol => }/common/test_apps.py | 8 +- tests/{mitol => }/common/test_decorators.py | 0 tests/{mitol => }/common/test_envs.py | 2 +- tests/{mitol => }/common/test_models.py | 6 +- tests/{mitol => }/common/test_pytest_utils.py | 0 .../utils}/__init__.py | 0 .../common/utils/test_collections.py | 0 .../{mitol => }/common/utils/test_currency.py | 0 .../{mitol => }/common/utils/test_datetime.py | 0 .../common/utils/test_http_requests.py | 0 tests/{mitol => }/common/utils/test_urls.py | 0 .../{mitol => }/common/utils/test_webpack.py | 0 .../__init__.py | 0 .../digitalcredentials/test_backend.py | 2 +- .../digitalcredentials/test_models.py | 6 +- .../digitalcredentials/test_requests_utils.py | 0 .../digitalcredentials/test_serializers.py | 8 +- .../digitalcredentials/test_views.py | 8 +- .../{mitol/hubspot_api => geoip}/__init__.py | 0 tests/{mitol => }/geoip/test_api.py | 0 .../{mitol/mail => google_sheets}/__init__.py | 0 tests/{mitol => }/google_sheets/test_api.py | 0 .../google_sheets/test_sheet_handler_api.py | 0 tests/{mitol => }/google_sheets/test_utils.py | 0 tests/{mitol => }/google_sheets/test_views.py | 2 +- .../__init__.py | 0 .../google_sheets_deferrals/test_api.py | 8 +- .../__init__.py | 0 .../google_sheets_refunds/test_api.py | 8 +- .../olposthog => hubspot_api}/__init__.py | 0 tests/{mitol => }/hubspot_api/test_api.py | 0 .../hubspot_api/test_decorators.py | 0 .../{mitol/openedx/utils => mail}/__init__.py | 0 tests/{mitol => }/mail/test_api.py | 0 tests/{mitol => }/mail/test_defaults.py | 0 tests/{mitol => }/mail/test_messages.py | 0 .../transcoding => mail/testapp}/__init__.py | 0 .../{mitol => }/mail/testapp/test_messages.py | 2 +- tests/{mitol => }/mail/testapp/test_urls.py | 0 .../__init__.py | 0 .../oauth_toolkit_extensions/test_backends.py | 0 .../oauth_toolkit_extensions/test_models.py | 0 tests/{testapp => olposthog}/__init__.py | 0 tests/{mitol => }/olposthog/test_features.py | 0 .../migrations => openedx/utils}/__init__.py | 0 .../{mitol => }/openedx/utils/test_courses.py | 0 .../payment_gateway/api/test_cybersource.py | 17 +-- .../utils/test_payment_utils.py | 0 tests/testapp/README.md | 104 ------------------ .../settings => transcoding}/__init__.py | 0 tests/{mitol => }/transcoding/test_utils.py | 0 tests/uvtestapp/__init__.py | 0 tests/{mitol => }/uvtestapp/test_api.py | 0 uv.lock | 2 +- 90 files changed, 120 insertions(+), 214 deletions(-) rename tests/conftest.py => conftest.py (83%) rename {tests/mitol/authentication => testapp/main}/__init__.py (100%) rename {tests/testapp => testapp/main}/admin.py (80%) rename {tests/testapp => testapp/main}/factories.py (97%) rename {tests/testapp => testapp/main}/integration.py (100%) rename {tests/testapp => testapp/main}/messages.py (100%) rename {tests/testapp => testapp/main}/migrations/0001_initial.py (96%) rename {tests/testapp => testapp/main}/migrations/0002_auditabletestmodel.py (94%) rename {tests/testapp => testapp/main}/migrations/0003_auditabletestmodelaudit.py (93%) rename {tests/mitol/authentication/views => testapp/main/migrations}/__init__.py (100%) rename {tests/testapp => testapp/main}/models.py (100%) rename {tests/mitol/common => testapp/main/settings}/__init__.py (100%) rename {tests/testapp => testapp/main}/settings/dev.py (52%) rename {tests/testapp => testapp/main}/settings/example.dev.py (69%) rename {tests/testapp => testapp/main}/settings/shared.py (97%) rename {tests/testapp => testapp/main}/settings/test.py (78%) rename {tests/testapp => testapp/main}/templates/mail/partials/_logo.html (100%) rename {tests/testapp => testapp/main}/templates/mail/sample/body.html (100%) rename {tests/testapp => testapp/main}/templates/mail/sample/subject.txt (100%) rename {tests/testapp => testapp/main}/urls.py (94%) rename {tests/testapp => testapp/main}/utils.py (100%) rename {tests/testapp => testapp/main}/views.py (91%) rename {tests/testapp => testapp/main}/wsgi.py (81%) rename {tests => testapp}/manage.py (88%) rename tests/{mitol/common/templates => }/__init__.py (100%) rename tests/{mitol/common/utils => authentication}/__init__.py (100%) rename tests/{mitol => }/authentication/test_serializers.py (100%) rename tests/{mitol/digitalcredentials => authentication/views}/__init__.py (100%) rename tests/{mitol => }/authentication/views/test_djoser.py (100%) rename tests/{mitol => }/authentication/views/test_saml.py (100%) rename tests/{mitol/geoip => common}/__init__.py (100%) rename tests/{mitol/google_sheets => common/templates}/__init__.py (100%) rename tests/{mitol => }/common/templates/test_render_bundle.py (100%) rename tests/{mitol => }/common/test_apps.py (87%) rename tests/{mitol => }/common/test_decorators.py (100%) rename tests/{mitol => }/common/test_envs.py (99%) rename tests/{mitol => }/common/test_models.py (99%) rename tests/{mitol => }/common/test_pytest_utils.py (100%) rename tests/{mitol/google_sheets_deferrals => common/utils}/__init__.py (100%) rename tests/{mitol => }/common/utils/test_collections.py (100%) rename tests/{mitol => }/common/utils/test_currency.py (100%) rename tests/{mitol => }/common/utils/test_datetime.py (100%) rename tests/{mitol => }/common/utils/test_http_requests.py (100%) rename tests/{mitol => }/common/utils/test_urls.py (100%) rename tests/{mitol => }/common/utils/test_webpack.py (100%) rename tests/{mitol/google_sheets_refunds => digitalcredentials}/__init__.py (100%) rename tests/{mitol => }/digitalcredentials/test_backend.py (98%) rename tests/{mitol => }/digitalcredentials/test_models.py (83%) rename tests/{mitol => }/digitalcredentials/test_requests_utils.py (100%) rename tests/{mitol => }/digitalcredentials/test_serializers.py (99%) rename tests/{mitol => }/digitalcredentials/test_views.py (99%) rename tests/{mitol/hubspot_api => geoip}/__init__.py (100%) rename tests/{mitol => }/geoip/test_api.py (100%) rename tests/{mitol/mail => google_sheets}/__init__.py (100%) rename tests/{mitol => }/google_sheets/test_api.py (100%) rename tests/{mitol => }/google_sheets/test_sheet_handler_api.py (100%) rename tests/{mitol => }/google_sheets/test_utils.py (100%) rename tests/{mitol => }/google_sheets/test_views.py (98%) rename tests/{mitol/mail/testapp => google_sheets_deferrals}/__init__.py (100%) rename tests/{mitol => }/google_sheets_deferrals/test_api.py (95%) rename tests/{mitol/oauth_toolkit_extensions => google_sheets_refunds}/__init__.py (100%) rename tests/{mitol => }/google_sheets_refunds/test_api.py (95%) rename tests/{mitol/olposthog => hubspot_api}/__init__.py (100%) rename tests/{mitol => }/hubspot_api/test_api.py (100%) rename tests/{mitol => }/hubspot_api/test_decorators.py (100%) rename tests/{mitol/openedx/utils => mail}/__init__.py (100%) rename tests/{mitol => }/mail/test_api.py (100%) rename tests/{mitol => }/mail/test_defaults.py (100%) rename tests/{mitol => }/mail/test_messages.py (100%) rename tests/{mitol/transcoding => mail/testapp}/__init__.py (100%) rename tests/{mitol => }/mail/testapp/test_messages.py (96%) rename tests/{mitol => }/mail/testapp/test_urls.py (100%) rename tests/{mitol/uvtestapp => oauth_toolkit_extensions}/__init__.py (100%) rename tests/{mitol => }/oauth_toolkit_extensions/test_backends.py (100%) rename tests/{mitol => }/oauth_toolkit_extensions/test_models.py (100%) rename tests/{testapp => olposthog}/__init__.py (100%) rename tests/{mitol => }/olposthog/test_features.py (100%) rename tests/{testapp/migrations => openedx/utils}/__init__.py (100%) rename tests/{mitol => }/openedx/utils/test_courses.py (100%) rename tests/{mitol => }/payment_gateway/api/test_cybersource.py (98%) rename tests/{mitol => }/payment_gateway/utils/test_payment_utils.py (100%) delete mode 100644 tests/testapp/README.md rename tests/{testapp/settings => transcoding}/__init__.py (100%) rename tests/{mitol => }/transcoding/test_utils.py (100%) create mode 100644 tests/uvtestapp/__init__.py rename tests/{mitol => }/uvtestapp/test_api.py (100%) diff --git a/.secrets.baseline b/.secrets.baseline index 4dc9c0ef..c863757e 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -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" } diff --git a/README.md b/README.md index 53b026b2..66c8caff 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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-` . (This ensures that uv is OK with your changes.) 5. Add space for the app in the `tests` app: `mkdir tests/mitol/` 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. diff --git a/tests/conftest.py b/conftest.py similarity index 83% rename from tests/conftest.py rename to conftest.py index 75951738..62ef0f4a 100644 --- a/tests/conftest.py +++ b/conftest.py @@ -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 @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 1ed38d63..20b58bf1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/tests/mitol/authentication/__init__.py b/testapp/main/__init__.py similarity index 100% rename from tests/mitol/authentication/__init__.py rename to testapp/main/__init__.py diff --git a/tests/testapp/admin.py b/testapp/main/admin.py similarity index 80% rename from tests/testapp/admin.py rename to testapp/main/admin.py index 965fb3ac..085ba626 100644 --- a/tests/testapp/admin.py +++ b/testapp/main/admin.py @@ -2,7 +2,7 @@ from django.contrib import admin -from testapp.models import DemoCourseware +from main.models import DemoCourseware @admin.register(DemoCourseware) diff --git a/tests/testapp/factories.py b/testapp/main/factories.py similarity index 97% rename from tests/testapp/factories.py rename to testapp/main/factories.py index eaadcf0d..5d1bad5c 100644 --- a/tests/testapp/factories.py +++ b/testapp/main/factories.py @@ -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() diff --git a/tests/testapp/integration.py b/testapp/main/integration.py similarity index 100% rename from tests/testapp/integration.py rename to testapp/main/integration.py diff --git a/tests/testapp/messages.py b/testapp/main/messages.py similarity index 100% rename from tests/testapp/messages.py rename to testapp/main/messages.py diff --git a/tests/testapp/migrations/0001_initial.py b/testapp/main/migrations/0001_initial.py similarity index 96% rename from tests/testapp/migrations/0001_initial.py rename to testapp/main/migrations/0001_initial.py index 56ddfa8b..bbc8c6c4 100644 --- a/tests/testapp/migrations/0001_initial.py +++ b/testapp/main/migrations/0001_initial.py @@ -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( @@ -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", ), ), ], diff --git a/tests/testapp/migrations/0002_auditabletestmodel.py b/testapp/main/migrations/0002_auditabletestmodel.py similarity index 94% rename from tests/testapp/migrations/0002_auditabletestmodel.py rename to testapp/main/migrations/0002_auditabletestmodel.py index 43e7842c..e3b3c32d 100644 --- a/tests/testapp/migrations/0002_auditabletestmodel.py +++ b/testapp/main/migrations/0002_auditabletestmodel.py @@ -5,7 +5,7 @@ class Migration(migrations.Migration): dependencies = [ - ("testapp", "0001_initial"), + ("main", "0001_initial"), ] operations = [ diff --git a/tests/testapp/migrations/0003_auditabletestmodelaudit.py b/testapp/main/migrations/0003_auditabletestmodelaudit.py similarity index 93% rename from tests/testapp/migrations/0003_auditabletestmodelaudit.py rename to testapp/main/migrations/0003_auditabletestmodelaudit.py index 7ceb40c1..aff20d74 100644 --- a/tests/testapp/migrations/0003_auditabletestmodelaudit.py +++ b/testapp/main/migrations/0003_auditabletestmodelaudit.py @@ -8,7 +8,7 @@ class Migration(migrations.Migration): dependencies = [ migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ("testapp", "0002_auditabletestmodel"), + ("main", "0002_auditabletestmodel"), ] operations = [ @@ -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", ), ), ], diff --git a/tests/mitol/authentication/views/__init__.py b/testapp/main/migrations/__init__.py similarity index 100% rename from tests/mitol/authentication/views/__init__.py rename to testapp/main/migrations/__init__.py diff --git a/tests/testapp/models.py b/testapp/main/models.py similarity index 100% rename from tests/testapp/models.py rename to testapp/main/models.py diff --git a/tests/mitol/common/__init__.py b/testapp/main/settings/__init__.py similarity index 100% rename from tests/mitol/common/__init__.py rename to testapp/main/settings/__init__.py diff --git a/tests/testapp/settings/dev.py b/testapp/main/settings/dev.py similarity index 52% rename from tests/testapp/settings/dev.py rename to testapp/main/settings/dev.py index 75db7741..c1813e5f 100644 --- a/tests/testapp/settings/dev.py +++ b/testapp/main/settings/dev.py @@ -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 diff --git a/tests/testapp/settings/example.dev.py b/testapp/main/settings/example.dev.py similarity index 69% rename from tests/testapp/settings/example.dev.py rename to testapp/main/settings/example.dev.py index 6749d60f..898a9eb1 100644 --- a/tests/testapp/settings/example.dev.py +++ b/testapp/main/settings/example.dev.py @@ -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" diff --git a/tests/testapp/settings/shared.py b/testapp/main/settings/shared.py similarity index 97% rename from tests/testapp/settings/shared.py rename to testapp/main/settings/shared.py index ed774d44..e9d9e34a 100644 --- a/tests/testapp/settings/shared.py +++ b/testapp/main/settings/shared.py @@ -1,5 +1,5 @@ """ -Django settings for testapp project. +Django settings for main project. Generated by 'django-admin startproject' using Django 2.2.15. @@ -73,7 +73,7 @@ "mitol.olposthog.apps.OlPosthog", "mitol.transcoding.apps.Transcoding", # test app, integrates the reusable apps - "testapp", + "main", ] MIDDLEWARE = [ @@ -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": [ @@ -104,7 +104,7 @@ }, ] -WSGI_APPLICATION = "testapp.wsgi.application" +WSGI_APPLICATION = "main.wsgi.application" REST_FRAMEWORK = {"TEST_REQUEST_DEFAULT_FORMAT": "json"} diff --git a/tests/testapp/settings/test.py b/testapp/main/settings/test.py similarity index 78% rename from tests/testapp/settings/test.py rename to testapp/main/settings/test.py index c6f9a4ba..eda86173 100644 --- a/tests/testapp/settings/test.py +++ b/testapp/main/settings/test.py @@ -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" diff --git a/tests/testapp/templates/mail/partials/_logo.html b/testapp/main/templates/mail/partials/_logo.html similarity index 100% rename from tests/testapp/templates/mail/partials/_logo.html rename to testapp/main/templates/mail/partials/_logo.html diff --git a/tests/testapp/templates/mail/sample/body.html b/testapp/main/templates/mail/sample/body.html similarity index 100% rename from tests/testapp/templates/mail/sample/body.html rename to testapp/main/templates/mail/sample/body.html diff --git a/tests/testapp/templates/mail/sample/subject.txt b/testapp/main/templates/mail/sample/subject.txt similarity index 100% rename from tests/testapp/templates/mail/sample/subject.txt rename to testapp/main/templates/mail/sample/subject.txt diff --git a/tests/testapp/urls.py b/testapp/main/urls.py similarity index 94% rename from tests/testapp/urls.py rename to testapp/main/urls.py index e064a564..f25b48fc 100644 --- a/tests/testapp/urls.py +++ b/testapp/main/urls.py @@ -5,7 +5,7 @@ from oauth2_provider.urls import base_urlpatterns from rest_framework import routers -from testapp.views import DemoCoursewareViewSet +from main.views import DemoCoursewareViewSet router = routers.SimpleRouter() router.register(r"democourseware", DemoCoursewareViewSet) diff --git a/tests/testapp/utils.py b/testapp/main/utils.py similarity index 100% rename from tests/testapp/utils.py rename to testapp/main/utils.py diff --git a/tests/testapp/views.py b/testapp/main/views.py similarity index 91% rename from tests/testapp/views.py rename to testapp/main/views.py index 83b7c16f..3f830e08 100644 --- a/tests/testapp/views.py +++ b/testapp/main/views.py @@ -3,7 +3,7 @@ from mitol.digitalcredentials.mixins import DigitalCredentialsRequestViewSetMixin from rest_framework.viewsets import ModelViewSet -from testapp.models import DemoCourseware +from main.models import DemoCourseware class DemoCoursewareViewSet(ModelViewSet, DigitalCredentialsRequestViewSetMixin): diff --git a/tests/testapp/wsgi.py b/testapp/main/wsgi.py similarity index 81% rename from tests/testapp/wsgi.py rename to testapp/main/wsgi.py index 4c7beec6..ac839e70 100644 --- a/tests/testapp/wsgi.py +++ b/testapp/main/wsgi.py @@ -11,6 +11,6 @@ from django.core.wsgi import get_wsgi_application -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testapp.settings.dev") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings.dev") application = get_wsgi_application() diff --git a/tests/manage.py b/testapp/manage.py similarity index 88% rename from tests/manage.py rename to testapp/manage.py index 02c55a65..c98ee921 100755 --- a/tests/manage.py +++ b/testapp/manage.py @@ -6,7 +6,7 @@ def main() -> None: - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testapp.settings.dev") + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings.dev") try: from django.core.management import execute_from_command_line except ImportError as exc: diff --git a/tests/mitol/common/templates/__init__.py b/tests/__init__.py similarity index 100% rename from tests/mitol/common/templates/__init__.py rename to tests/__init__.py diff --git a/tests/mitol/common/utils/__init__.py b/tests/authentication/__init__.py similarity index 100% rename from tests/mitol/common/utils/__init__.py rename to tests/authentication/__init__.py diff --git a/tests/mitol/authentication/test_serializers.py b/tests/authentication/test_serializers.py similarity index 100% rename from tests/mitol/authentication/test_serializers.py rename to tests/authentication/test_serializers.py diff --git a/tests/mitol/digitalcredentials/__init__.py b/tests/authentication/views/__init__.py similarity index 100% rename from tests/mitol/digitalcredentials/__init__.py rename to tests/authentication/views/__init__.py diff --git a/tests/mitol/authentication/views/test_djoser.py b/tests/authentication/views/test_djoser.py similarity index 100% rename from tests/mitol/authentication/views/test_djoser.py rename to tests/authentication/views/test_djoser.py diff --git a/tests/mitol/authentication/views/test_saml.py b/tests/authentication/views/test_saml.py similarity index 100% rename from tests/mitol/authentication/views/test_saml.py rename to tests/authentication/views/test_saml.py diff --git a/tests/mitol/geoip/__init__.py b/tests/common/__init__.py similarity index 100% rename from tests/mitol/geoip/__init__.py rename to tests/common/__init__.py diff --git a/tests/mitol/google_sheets/__init__.py b/tests/common/templates/__init__.py similarity index 100% rename from tests/mitol/google_sheets/__init__.py rename to tests/common/templates/__init__.py diff --git a/tests/mitol/common/templates/test_render_bundle.py b/tests/common/templates/test_render_bundle.py similarity index 100% rename from tests/mitol/common/templates/test_render_bundle.py rename to tests/common/templates/test_render_bundle.py diff --git a/tests/mitol/common/test_apps.py b/tests/common/test_apps.py similarity index 87% rename from tests/mitol/common/test_apps.py rename to tests/common/test_apps.py index ff6a6357..7caa6124 100644 --- a/tests/mitol/common/test_apps.py +++ b/tests/common/test_apps.py @@ -1,7 +1,7 @@ """Tests for apps""" +import main import pytest -import testapp from django.core.exceptions import ImproperlyConfigured from mitol.common.apps import BaseApp @@ -13,7 +13,7 @@ class NoRequiredSettingsApp(BaseApp): """Test app that requires no settings""" # no error is raised - app = NoRequiredSettingsApp("test", testapp) + app = NoRequiredSettingsApp("test", main) app.ready() @@ -28,7 +28,7 @@ class RequiredSettingsApp(BaseApp): settings.TEST_SETTING = True # no error is raised - app = RequiredSettingsApp("test", testapp) + app = RequiredSettingsApp("test", main) app.ready() @@ -42,6 +42,6 @@ class RequiredSettingsApp(BaseApp): settings.TEST_SETTING = True - app = RequiredSettingsApp("test", testapp) + app = RequiredSettingsApp("test", main) with pytest.raises(ImproperlyConfigured): app.ready() diff --git a/tests/mitol/common/test_decorators.py b/tests/common/test_decorators.py similarity index 100% rename from tests/mitol/common/test_decorators.py rename to tests/common/test_decorators.py diff --git a/tests/mitol/common/test_envs.py b/tests/common/test_envs.py similarity index 99% rename from tests/mitol/common/test_envs.py rename to tests/common/test_envs.py index e0fc2d8c..a616a233 100644 --- a/tests/mitol/common/test_envs.py +++ b/tests/common/test_envs.py @@ -23,7 +23,7 @@ "FEATURE_DEF": "False", "FLAG_GHI": "False", # this here to ensure the envs.reload() works - "DJANGO_SETTINGS_MODULE": "testapp.settings.test", + "DJANGO_SETTINGS_MODULE": "main.settings.test", "CRONTAB_BLANK": " ", "CRONTAB_EMPTY": "", "CRONTAB_VALID": "* * * * *", diff --git a/tests/mitol/common/test_models.py b/tests/common/test_models.py similarity index 99% rename from tests/mitol/common/test_models.py rename to tests/common/test_models.py index 9aeb724b..1b7abd4f 100644 --- a/tests/mitol/common/test_models.py +++ b/tests/common/test_models.py @@ -6,9 +6,7 @@ import pytest import pytz from freezegun import freeze_time -from mitol.common.factories import UserFactory -from mitol.common.utils.serializers import serialize_model_object -from testapp.models import ( +from main.models import ( AuditableTestModel, AuditableTestModelAudit, FirstLevel1, @@ -18,6 +16,8 @@ SecondLevel2, Updateable, ) +from mitol.common.factories import UserFactory +from mitol.common.utils.serializers import serialize_model_object pytestmark = pytest.mark.django_db diff --git a/tests/mitol/common/test_pytest_utils.py b/tests/common/test_pytest_utils.py similarity index 100% rename from tests/mitol/common/test_pytest_utils.py rename to tests/common/test_pytest_utils.py diff --git a/tests/mitol/google_sheets_deferrals/__init__.py b/tests/common/utils/__init__.py similarity index 100% rename from tests/mitol/google_sheets_deferrals/__init__.py rename to tests/common/utils/__init__.py diff --git a/tests/mitol/common/utils/test_collections.py b/tests/common/utils/test_collections.py similarity index 100% rename from tests/mitol/common/utils/test_collections.py rename to tests/common/utils/test_collections.py diff --git a/tests/mitol/common/utils/test_currency.py b/tests/common/utils/test_currency.py similarity index 100% rename from tests/mitol/common/utils/test_currency.py rename to tests/common/utils/test_currency.py diff --git a/tests/mitol/common/utils/test_datetime.py b/tests/common/utils/test_datetime.py similarity index 100% rename from tests/mitol/common/utils/test_datetime.py rename to tests/common/utils/test_datetime.py diff --git a/tests/mitol/common/utils/test_http_requests.py b/tests/common/utils/test_http_requests.py similarity index 100% rename from tests/mitol/common/utils/test_http_requests.py rename to tests/common/utils/test_http_requests.py diff --git a/tests/mitol/common/utils/test_urls.py b/tests/common/utils/test_urls.py similarity index 100% rename from tests/mitol/common/utils/test_urls.py rename to tests/common/utils/test_urls.py diff --git a/tests/mitol/common/utils/test_webpack.py b/tests/common/utils/test_webpack.py similarity index 100% rename from tests/mitol/common/utils/test_webpack.py rename to tests/common/utils/test_webpack.py diff --git a/tests/mitol/google_sheets_refunds/__init__.py b/tests/digitalcredentials/__init__.py similarity index 100% rename from tests/mitol/google_sheets_refunds/__init__.py rename to tests/digitalcredentials/__init__.py diff --git a/tests/mitol/digitalcredentials/test_backend.py b/tests/digitalcredentials/test_backend.py similarity index 98% rename from tests/mitol/digitalcredentials/test_backend.py rename to tests/digitalcredentials/test_backend.py index 42121eec..534a7a92 100644 --- a/tests/mitol/digitalcredentials/test_backend.py +++ b/tests/digitalcredentials/test_backend.py @@ -7,6 +7,7 @@ import responses from django.core.exceptions import ImproperlyConfigured from django.urls import reverse +from main.factories import DemoCoursewareDigitalCredentialRequestFactory from mitol.digitalcredentials.backend import ( build_api_url, build_credential, @@ -14,7 +15,6 @@ issue_credential, verify_presentations, ) -from testapp.factories import DemoCoursewareDigitalCredentialRequestFactory def test_build_api_url(): diff --git a/tests/mitol/digitalcredentials/test_models.py b/tests/digitalcredentials/test_models.py similarity index 83% rename from tests/mitol/digitalcredentials/test_models.py rename to tests/digitalcredentials/test_models.py index 48e07d89..913eaf89 100644 --- a/tests/mitol/digitalcredentials/test_models.py +++ b/tests/digitalcredentials/test_models.py @@ -1,15 +1,13 @@ """Models tests""" -# Models require an installed app, so most of the tests are instead in: -# mitol-django-digitalcredentials/testapp/models_test.py from hashlib import sha256 import pytest -from mitol.digitalcredentials.factories import LearnerDIDFactory -from testapp.factories import ( +from main.factories import ( DemoCoursewareDigitalCredentialFactory, DemoCoursewareDigitalCredentialRequestFactory, ) +from mitol.digitalcredentials.factories import LearnerDIDFactory pytestmark = pytest.mark.django_db diff --git a/tests/mitol/digitalcredentials/test_requests_utils.py b/tests/digitalcredentials/test_requests_utils.py similarity index 100% rename from tests/mitol/digitalcredentials/test_requests_utils.py rename to tests/digitalcredentials/test_requests_utils.py diff --git a/tests/mitol/digitalcredentials/test_serializers.py b/tests/digitalcredentials/test_serializers.py similarity index 99% rename from tests/mitol/digitalcredentials/test_serializers.py rename to tests/digitalcredentials/test_serializers.py index f9e6fffa..ef52677e 100644 --- a/tests/mitol/digitalcredentials/test_serializers.py +++ b/tests/digitalcredentials/test_serializers.py @@ -5,6 +5,10 @@ import pytest import responses from django.contrib.contenttypes.models import ContentType +from main.factories import ( + DemoCoursewareDigitalCredentialFactory, + DemoCoursewareDigitalCredentialRequestFactory, +) from mitol.digitalcredentials.factories import LearnerDIDFactory from mitol.digitalcredentials.models import ( DigitalCredential, @@ -15,10 +19,6 @@ DigitalCredentialIssueSerializer, DigitalCredentialRequestSerializer, ) -from testapp.factories import ( - DemoCoursewareDigitalCredentialFactory, - DemoCoursewareDigitalCredentialRequestFactory, -) pytestmark = pytest.mark.django_db diff --git a/tests/mitol/digitalcredentials/test_views.py b/tests/digitalcredentials/test_views.py similarity index 99% rename from tests/mitol/digitalcredentials/test_views.py rename to tests/digitalcredentials/test_views.py index 673a5264..0ae9c3c3 100644 --- a/tests/mitol/digitalcredentials/test_views.py +++ b/tests/digitalcredentials/test_views.py @@ -5,13 +5,13 @@ import pytest import responses from django.urls import reverse -from mitol.digitalcredentials.backend import create_deep_link_url -from mitol.digitalcredentials.models import DigitalCredentialRequest -from rest_framework.test import APIClient -from testapp.factories import ( +from main.factories import ( DemoCoursewareDigitalCredentialRequestFactory, DemoCoursewareFactory, ) +from mitol.digitalcredentials.backend import create_deep_link_url +from mitol.digitalcredentials.models import DigitalCredentialRequest +from rest_framework.test import APIClient pytestmark = pytest.mark.django_db diff --git a/tests/mitol/hubspot_api/__init__.py b/tests/geoip/__init__.py similarity index 100% rename from tests/mitol/hubspot_api/__init__.py rename to tests/geoip/__init__.py diff --git a/tests/mitol/geoip/test_api.py b/tests/geoip/test_api.py similarity index 100% rename from tests/mitol/geoip/test_api.py rename to tests/geoip/test_api.py diff --git a/tests/mitol/mail/__init__.py b/tests/google_sheets/__init__.py similarity index 100% rename from tests/mitol/mail/__init__.py rename to tests/google_sheets/__init__.py diff --git a/tests/mitol/google_sheets/test_api.py b/tests/google_sheets/test_api.py similarity index 100% rename from tests/mitol/google_sheets/test_api.py rename to tests/google_sheets/test_api.py diff --git a/tests/mitol/google_sheets/test_sheet_handler_api.py b/tests/google_sheets/test_sheet_handler_api.py similarity index 100% rename from tests/mitol/google_sheets/test_sheet_handler_api.py rename to tests/google_sheets/test_sheet_handler_api.py diff --git a/tests/mitol/google_sheets/test_utils.py b/tests/google_sheets/test_utils.py similarity index 100% rename from tests/mitol/google_sheets/test_utils.py rename to tests/google_sheets/test_utils.py diff --git a/tests/mitol/google_sheets/test_views.py b/tests/google_sheets/test_views.py similarity index 98% rename from tests/mitol/google_sheets/test_views.py rename to tests/google_sheets/test_views.py index 792cc73d..11137e5b 100644 --- a/tests/mitol/google_sheets/test_views.py +++ b/tests/google_sheets/test_views.py @@ -3,12 +3,12 @@ import pytest from django.test.client import RequestFactory from django.urls import reverse +from main.utils import set_request_session from mitol.google_sheets.factories import GoogleApiAuthFactory from mitol.google_sheets.models import GoogleApiAuth from mitol.google_sheets.views import complete_google_auth from pytest_lazy_fixtures import lf as lazy_fixture from rest_framework import status -from testapp.utils import set_request_session lazy = lazy_fixture diff --git a/tests/mitol/mail/testapp/__init__.py b/tests/google_sheets_deferrals/__init__.py similarity index 100% rename from tests/mitol/mail/testapp/__init__.py rename to tests/google_sheets_deferrals/__init__.py diff --git a/tests/mitol/google_sheets_deferrals/test_api.py b/tests/google_sheets_deferrals/test_api.py similarity index 95% rename from tests/mitol/google_sheets_deferrals/test_api.py rename to tests/google_sheets_deferrals/test_api.py index 7cfb5abe..f519fa11 100644 --- a/tests/mitol/google_sheets_deferrals/test_api.py +++ b/tests/google_sheets_deferrals/test_api.py @@ -1,6 +1,5 @@ """Deferral request API tests""" -import os from types import SimpleNamespace import pytest @@ -15,12 +14,9 @@ @pytest.fixture() -def request_csv_rows(settings): +def request_csv_rows(open_data_fixture_file): """Fake deferral request spreadsheet data rows (loaded from CSV)""" - fake_request_csv_filepath = os.path.join( # noqa: PTH118 - settings.BASE_DIR, "data/google_sheets_deferrals/deferral_requests.csv" - ) - with open(fake_request_csv_filepath) as f: # noqa: PTH123 + with open_data_fixture_file("google_sheets_deferrals/deferral_requests.csv") as f: # Return all rows except for the header return [line.split(",") for i, line in enumerate(f.readlines()) if i > 0] diff --git a/tests/mitol/oauth_toolkit_extensions/__init__.py b/tests/google_sheets_refunds/__init__.py similarity index 100% rename from tests/mitol/oauth_toolkit_extensions/__init__.py rename to tests/google_sheets_refunds/__init__.py diff --git a/tests/mitol/google_sheets_refunds/test_api.py b/tests/google_sheets_refunds/test_api.py similarity index 95% rename from tests/mitol/google_sheets_refunds/test_api.py rename to tests/google_sheets_refunds/test_api.py index 798beb1e..fce51080 100644 --- a/tests/mitol/google_sheets_refunds/test_api.py +++ b/tests/google_sheets_refunds/test_api.py @@ -1,6 +1,5 @@ """Refund request API tests""" -import os from types import SimpleNamespace import pytest @@ -15,12 +14,9 @@ @pytest.fixture() -def request_csv_rows(settings): +def request_csv_rows(open_data_fixture_file): """Fake refund request spreadsheet data rows (loaded from CSV)""" - fake_request_csv_filepath = os.path.join( # noqa: PTH118 - settings.BASE_DIR, "data/google_sheets_refunds/refund_requests.csv" - ) - with open(fake_request_csv_filepath) as f: # noqa: PTH123 + with open_data_fixture_file("google_sheets_refunds/refund_requests.csv") as f: # Return all rows except for the header return [line.split(",") for i, line in enumerate(f.readlines()) if i > 0] diff --git a/tests/mitol/olposthog/__init__.py b/tests/hubspot_api/__init__.py similarity index 100% rename from tests/mitol/olposthog/__init__.py rename to tests/hubspot_api/__init__.py diff --git a/tests/mitol/hubspot_api/test_api.py b/tests/hubspot_api/test_api.py similarity index 100% rename from tests/mitol/hubspot_api/test_api.py rename to tests/hubspot_api/test_api.py diff --git a/tests/mitol/hubspot_api/test_decorators.py b/tests/hubspot_api/test_decorators.py similarity index 100% rename from tests/mitol/hubspot_api/test_decorators.py rename to tests/hubspot_api/test_decorators.py diff --git a/tests/mitol/openedx/utils/__init__.py b/tests/mail/__init__.py similarity index 100% rename from tests/mitol/openedx/utils/__init__.py rename to tests/mail/__init__.py diff --git a/tests/mitol/mail/test_api.py b/tests/mail/test_api.py similarity index 100% rename from tests/mitol/mail/test_api.py rename to tests/mail/test_api.py diff --git a/tests/mitol/mail/test_defaults.py b/tests/mail/test_defaults.py similarity index 100% rename from tests/mitol/mail/test_defaults.py rename to tests/mail/test_defaults.py diff --git a/tests/mitol/mail/test_messages.py b/tests/mail/test_messages.py similarity index 100% rename from tests/mitol/mail/test_messages.py rename to tests/mail/test_messages.py diff --git a/tests/mitol/transcoding/__init__.py b/tests/mail/testapp/__init__.py similarity index 100% rename from tests/mitol/transcoding/__init__.py rename to tests/mail/testapp/__init__.py diff --git a/tests/mitol/mail/testapp/test_messages.py b/tests/mail/testapp/test_messages.py similarity index 96% rename from tests/mitol/mail/testapp/test_messages.py rename to tests/mail/testapp/test_messages.py index 008002e3..14d2d25a 100644 --- a/tests/mitol/mail/testapp/test_messages.py +++ b/tests/mail/testapp/test_messages.py @@ -1,6 +1,6 @@ """Messages tests""" -from testapp.messages import SampleMessage +from main.messages import SampleMessage def test_create_message_subclass(mocker): diff --git a/tests/mitol/mail/testapp/test_urls.py b/tests/mail/testapp/test_urls.py similarity index 100% rename from tests/mitol/mail/testapp/test_urls.py rename to tests/mail/testapp/test_urls.py diff --git a/tests/mitol/uvtestapp/__init__.py b/tests/oauth_toolkit_extensions/__init__.py similarity index 100% rename from tests/mitol/uvtestapp/__init__.py rename to tests/oauth_toolkit_extensions/__init__.py diff --git a/tests/mitol/oauth_toolkit_extensions/test_backends.py b/tests/oauth_toolkit_extensions/test_backends.py similarity index 100% rename from tests/mitol/oauth_toolkit_extensions/test_backends.py rename to tests/oauth_toolkit_extensions/test_backends.py diff --git a/tests/mitol/oauth_toolkit_extensions/test_models.py b/tests/oauth_toolkit_extensions/test_models.py similarity index 100% rename from tests/mitol/oauth_toolkit_extensions/test_models.py rename to tests/oauth_toolkit_extensions/test_models.py diff --git a/tests/testapp/__init__.py b/tests/olposthog/__init__.py similarity index 100% rename from tests/testapp/__init__.py rename to tests/olposthog/__init__.py diff --git a/tests/mitol/olposthog/test_features.py b/tests/olposthog/test_features.py similarity index 100% rename from tests/mitol/olposthog/test_features.py rename to tests/olposthog/test_features.py diff --git a/tests/testapp/migrations/__init__.py b/tests/openedx/utils/__init__.py similarity index 100% rename from tests/testapp/migrations/__init__.py rename to tests/openedx/utils/__init__.py diff --git a/tests/mitol/openedx/utils/test_courses.py b/tests/openedx/utils/test_courses.py similarity index 100% rename from tests/mitol/openedx/utils/test_courses.py rename to tests/openedx/utils/test_courses.py diff --git a/tests/mitol/payment_gateway/api/test_cybersource.py b/tests/payment_gateway/api/test_cybersource.py similarity index 98% rename from tests/mitol/payment_gateway/api/test_cybersource.py rename to tests/payment_gateway/api/test_cybersource.py index 0c014437..d96867ce 100644 --- a/tests/mitol/payment_gateway/api/test_cybersource.py +++ b/tests/payment_gateway/api/test_cybersource.py @@ -1,6 +1,5 @@ import hashlib # noqa: INP001 import json -import os import random from collections import namedtuple from dataclasses import dataclass @@ -12,6 +11,7 @@ from CyberSource.rest import ApiException from django.conf import settings from factory import fuzzy +from main.factories import CartItemFactory, OrderFactory, RefundFactory from mitol.common.utils.datetime import now_in_utc from mitol.payment_gateway.api import ( CyberSourcePaymentGateway, @@ -23,7 +23,6 @@ InvalidTransactionException, RefundDuplicateException, ) -from testapp.factories import CartItemFactory, OrderFactory, RefundFactory from urllib3.response import HTTPResponse ISO_8601_FORMAT = "%Y-%m-%dT%H:%M:%SZ" @@ -45,19 +44,9 @@ def cartitems(): @pytest.fixture() -def response_payload(request): +def response_payload(request, load_data_fixture_json): """Fixture to return dictionary of a specific JSON file with provided name in request param""" # noqa: E501 - - with open( # noqa: PTH123 - os.path.join( # noqa: PTH118 - os.getcwd(), # noqa: PTH109 - "tests/data/payment_gateway/api", - f"{request.param}.json", - ), - ) as f: - response_txt = f.read() - response_json = json.loads(response_txt) - yield response_json + return load_data_fixture_json(f"payment_gateway/api/{request.param}.json") @dataclass diff --git a/tests/mitol/payment_gateway/utils/test_payment_utils.py b/tests/payment_gateway/utils/test_payment_utils.py similarity index 100% rename from tests/mitol/payment_gateway/utils/test_payment_utils.py rename to tests/payment_gateway/utils/test_payment_utils.py diff --git a/tests/testapp/README.md b/tests/testapp/README.md deleted file mode 100644 index 594e4fe9..00000000 --- a/tests/testapp/README.md +++ /dev/null @@ -1,104 +0,0 @@ -`mitol-django-digital-credentials` test app ---- - -### Setup - -To run this app in local development mode, copy `testapp/settings/example.dev.py` to `testapp/settings/dev.py`. This file has the same defaults as `testapp/settings/test.py`, but it is gitignored so you can safely add secrets to it. `manage.py` and `testapp/wsgi.py` both load `dev.py`. - -### Usage - -#### Digital Credentials - -Ensure the [`sign-and-verify`](https://github.com/digitalcredentials/sign-and-verify) service is running locally. - -You can test this app out by running: - -- `./pants django-run tests:manage -- migrate` - migrates sqlite db (gitignored) -- `/pants django-run tests:manage -- runserver` -- `/pants django-run testsmanage -- shell`: - -```python -import json -import requests -from datetime import timedelta -from oauth2_provider.models import AccessToken, get_application_model -from django.contrib.auth.models import User -from mitol.common.utils import now_in_utc -from testapp.factories import DemoCoursewareDigitalCredentialRequestFactory - -Application = get_application_model() - -### Create a user -learner, _ = User.objects.get_or_create( - username="myuser", - defaults=dict(email="myuser@example.com") -) - -# create oauth2 app and access token -application, _ = Application.objects.get_or_create( - name="Test Application", - defaults=dict( - redirect_uris="http://localhost", - user=learner, - client_type=Application.CLIENT_CONFIDENTIAL, - authorization_grant_type=Application.GRANT_AUTHORIZATION_CODE, - ) -) -access_token, _ = AccessToken.objects.update_or_create( - user=learner, - token="1234567890", - application=application, - defaults=dict( - expires=now_in_utc() + timedelta(days=1), - scope="read write digitalcredentials", - ) -) - -request = DemoCoursewareDigitalCredentialRequestFactory.create(learner=learner) - -did = "did:example:456" -response = requests.post( - "http://localhost:5000/generate/controlproof", - json={ - "presentationId": did, - "holder": "did:web:digitalcredentials.github.io", - "verificationMethod": "did:web:digitalcredentials.github.io#96K4BSIWAkhcclKssb8yTWMQSz4QzPWBy-JsAFlwoIs", - "challenge": str(request.uuid) - } -) -data = json.dumps(response.json()) -print(f"""curl \ - -H 'Authorization: Bearer {access_token.token}' \ - -H 'Accept: application/json' \ - -H 'Content-Type: application/json' \ - --data '{data}' \ - http://localhost:8000/api/credentials/request/{request.uuid}/""") -``` - -- Copy/paste and run curl command printed above - - -#### Mail - -You can test this app out by running: - -- `./pants django-run manage -- migrate` - migrates sqlite db (gitignored) -- `./pants django-run manage -- shell`: - -```python -### Create a user -from django.contrib.auth import get_user_model -User = get_user_model() -user = User.objects.create(username="", email="") -``` -```python -### Send an email -from mitol.mail.api import get_message_sender -from mitol.mail.messages import TemplatedMessage -from testapp.messages import SampleMessage -from django.contrib.auth import get_user_model -User = get_user_model() -user = User.objects.get(username="") -with get_message_sender(SampleMessage, shared_context={}) as sender: - sender.build_and_send_message(user, {}) -``` diff --git a/tests/testapp/settings/__init__.py b/tests/transcoding/__init__.py similarity index 100% rename from tests/testapp/settings/__init__.py rename to tests/transcoding/__init__.py diff --git a/tests/mitol/transcoding/test_utils.py b/tests/transcoding/test_utils.py similarity index 100% rename from tests/mitol/transcoding/test_utils.py rename to tests/transcoding/test_utils.py diff --git a/tests/uvtestapp/__init__.py b/tests/uvtestapp/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/mitol/uvtestapp/test_api.py b/tests/uvtestapp/test_api.py similarity index 100% rename from tests/mitol/uvtestapp/test_api.py rename to tests/uvtestapp/test_api.py diff --git a/uv.lock b/uv.lock index d702b774..9887b33f 100644 --- a/uv.lock +++ b/uv.lock @@ -1473,7 +1473,7 @@ requires-dist = [ [[package]] name = "mitol-django-transcoding" -version = "2025.2.22" +version = "2025.2.25" source = { editable = "src/transcoding" } dependencies = [ { name = "boto3" },