diff --git a/Pipfile b/Pipfile index 1434aac54..a808e1b5e 100644 --- a/Pipfile +++ b/Pipfile @@ -71,7 +71,7 @@ flake8 = "*" flake8-html = "*" isort = "*" pytest-cov = "*" -pytest-django = "<4.3" +pytest-django = "==4.5.2" pytest-echo = "*" vcrpy = "*" diff --git a/Pipfile.lock b/Pipfile.lock index c5c7d3d65..4931bdd4d 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b5f7d7d03c5200879bd725c184d7777a47a04893742e049a086d2d206825fce4" + "sha256": "8bc6d16349e4d58fcb5b4cca579dc0c582dc82c46070f51240cc984be8f569c9" }, "pipfile-spec": 6, "requires": { @@ -673,6 +673,13 @@ ], "version": "==0.5.1" }, + "iniconfig": { + "hashes": [ + "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3", + "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32" + ], + "version": "==1.1.1" + }, "iso8601": { "hashes": [ "sha256:36532f77cc800594e8f16641edae7f1baf7932f05d8e508545b95fc53c6dc85b", @@ -919,6 +926,14 @@ ], "version": "==9.1.1" }, + "pluggy": { + "hashes": [ + "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159", + "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3" + ], + "markers": "python_version >= '3.6'", + "version": "==1.0.0" + }, "prompt-toolkit": { "hashes": [ "sha256:859b283c50bde45f5f97829f77a4674d1c1fcd88539364f1b28a37805cfd89c0", @@ -988,6 +1003,14 @@ "index": "pypi", "version": "==2.9.3" }, + "py": { + "hashes": [ + "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719", + "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", + "version": "==1.11.0" + }, "pycparser": { "hashes": [ "sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9", @@ -1018,9 +1041,7 @@ "version": "==0.19.5" }, "pyjwt": { - "extras": [ - "crypto" - ], + "extras": [], "hashes": [ "sha256:72d1d253f32dbd4f5c88eaf1fdc62f3a19f676ccbadb9dbc5d07e951b2b26daf", "sha256:d42908208c699b3b973cbeb01a969ba6a96c821eefb1c5bfe4c390c01d67abba" @@ -1066,6 +1087,14 @@ ], "version": "==0.18.1" }, + "pytest": { + "hashes": [ + "sha256:13d0e3ccfc2b6e26be000cb6568c832ba67ba32e719443bfe725814d3c42433c", + "sha256:a06a0425453864a270bc45e71f783330a7428defb4230fb5e6a731fde06ecd45" + ], + "markers": "python_version >= '3.7'", + "version": "==7.1.2" + }, "python-bidi": { "hashes": [ "sha256:50eef6f6a0bbdd685f9e8c207f3c9050f5b578d0a46e37c76a9c4baea2cc2e13", @@ -1266,7 +1295,7 @@ "sha256:dc6a613d6c74eef5a14a214d433d06291526145431c3b964f5e16529b1842bed", "sha256:de9c6b8a1ba52919ae919f3ae96abb72b994dd0350226e28f3686cb4f142165c" ], - "markers": "platform_python_implementation == 'CPython' and python_version < '3.11'", + "markers": "python_version < '3.11' and platform_python_implementation == 'CPython'", "version": "==0.2.6" }, "sentry-sdk": { @@ -1277,6 +1306,14 @@ "index": "pypi", "version": "==1.6.0" }, + "setuptools": { + "hashes": [ + "sha256:990a4f7861b31532871ab72331e755b5f14efbe52d336ea7f6118144dd478741", + "sha256:c1848f654aea2e3526d17fc3ce6aeaa5e7e24e66e645b5be2171f3f6b4e5a178" + ], + "markers": "python_version >= '3.7'", + "version": "==62.6.0" + }, "six": { "hashes": [ "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926", @@ -1340,6 +1377,14 @@ ], "version": "==0.10.2" }, + "tomli": { + "hashes": [ + "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc", + "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f" + ], + "markers": "python_version >= '3.7'", + "version": "==2.0.1" + }, "tqdm": { "hashes": [ "sha256:40be55d30e200777a307a7585aee69e4eabb46b4ec6a4b4a5f2d9f11e7d5408d", @@ -1822,6 +1867,7 @@ "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159", "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3" ], + "markers": "python_version >= '3.6'", "version": "==1.0.0" }, "py": { @@ -1829,6 +1875,7 @@ "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719", "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378" ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'", "version": "==1.11.0" }, "pycodestyle": { @@ -1865,6 +1912,7 @@ "sha256:13d0e3ccfc2b6e26be000cb6568c832ba67ba32e719443bfe725814d3c42433c", "sha256:a06a0425453864a270bc45e71f783330a7428defb4230fb5e6a731fde06ecd45" ], + "markers": "python_version >= '3.7'", "version": "==7.1.2" }, "pytest-cov": { @@ -1877,11 +1925,11 @@ }, "pytest-django": { "hashes": [ - "sha256:80f8875226ec4dc0b205f0578072034563879d98d9b1bec143a80b9045716cb0", - "sha256:a51150d8962200250e850c6adcab670779b9c2aa07271471059d1fb92a843fa9" + "sha256:c60834861933773109334fe5a53e83d1ef4828f2203a1d6a0fa9972f4f75ab3e", + "sha256:d9076f759bb7c36939dbdd5ae6633c18edfc2902d1a69fdbefd2426b970ce6c2" ], "index": "pypi", - "version": "==4.2.0" + "version": "==4.5.2" }, "pytest-echo": { "hashes": [ @@ -1968,6 +2016,7 @@ "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc", "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f" ], + "markers": "python_version >= '3.7'", "version": "==2.0.1" }, "vcrpy": { diff --git a/tests/_test_lib/settings_test.py b/tests/_test_lib/settings_test.py index b2033e00e..43441222d 100644 --- a/tests/_test_lib/settings_test.py +++ b/tests/_test_lib/settings_test.py @@ -1,4 +1,3 @@ -import os import random from etools_datamart.config.settings import * # noqa @@ -28,15 +27,17 @@ def cache_random_prefix(*args, **kwargs): CACHES['default']['KEY_FUNCTION'] = cache_random_prefix # noqa # Use only one db during tests -DATABASES['etools']['PORT'] = DATABASES['default']['PORT'] # noqa -DATABASES['etools']['HOST'] = DATABASES['default']['HOST'] # noqa -DATABASES['etools']['USERNAME'] = DATABASES['default'].get('USERNAME', "") # noqa -DATABASES['etools']['PASSWORD'] = DATABASES['default'].get('PASSWORD', "") # noqa +# DATABASES['etools']['PORT'] = DATABASES['default']['PORT'] # noqa +# DATABASES['etools']['HOST'] = DATABASES['default']['HOST'] # noqa +# DATABASES['etools']['USERNAME'] = DATABASES['default'].get('USERNAME', "") # noqa +# DATABASES['etools']['PASSWORD'] = DATABASES['default'].get('PASSWORD', "") # noqa TEST_SCHEMAS = ['bolivia', 'chad', 'lebanon'] SCHEMA_FILTER = {'schema_name__in': TEST_SCHEMAS} SCHEMA_EXCLUDE = {} +USE_TZ = True + CSRF_COOKIE_SECURE = False SECURE_BROWSER_XSS_FILTER = False SECURE_CONTENT_TYPE_NOSNIFF = False diff --git a/tests/_test_lib/test_utilities/factories/data.py b/tests/_test_lib/test_utilities/factories/data.py index 847e87b30..c6e5d06b6 100644 --- a/tests/_test_lib/test_utilities/factories/data.py +++ b/tests/_test_lib/test_utilities/factories/data.py @@ -71,6 +71,7 @@ class InterventionFactory(DataMartModelFactory): class Meta: model = models.Intervention + django_get_or_create = ('intervention_id', 'schema_name') class InterventionByLocationFactory(DataMartModelFactory): diff --git a/tests/conftest.py b/tests/conftest.py index 15e20b3ff..3fe29b5ba 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -36,6 +36,7 @@ import pytest from _pytest.fixtures import SubRequest +from pytest_django.django_compat import is_django_unittest def pytest_configure(config): @@ -109,11 +110,11 @@ def django_db_setup(request, # """Top level fixture to ensure test databases are available""" from django.test.utils import setup_databases, teardown_databases - from pytest_django.fixtures import _disable_native_migrations + from pytest_django.fixtures import _disable_migrations setup_databases_args = {} if not django_db_use_migrations: - _disable_native_migrations() + _disable_migrations() if django_db_keepdb and not django_db_createdb: setup_databases_args["keepdb"] = True @@ -160,6 +161,43 @@ def _teardown_database(): assert not APIRequestLog.objects.exists() +@pytest.fixture() +def _django_db_helper( + request, django_db_blocker, transactional=False, reset_sequences=False +): + if is_django_unittest(request): + return + + if not transactional and "live_server" in request.fixturenames: + # Do nothing, we get called with transactional=True, too. + return + + django_db_blocker.unblock() + request.addfinalizer(django_db_blocker.restore) + + if transactional: + from django.test import TransactionTestCase as django_case + + if reset_sequences: + + class ResetSequenceTestCase(django_case): + reset_sequences = True + + django_case = ResetSequenceTestCase + else: + from django.db import transaction + from django.test import TestCase as django_case + transaction.Atomic._ensure_durability = False + + def reset_durability(): + transaction.Atomic._ensure_durability = True + request.addfinalizer(reset_durability) + + test_case = django_case(methodName="__init__") + test_case._pre_setup() + request.addfinalizer(test_case._post_teardown) + + @pytest.fixture def user1(db): from test_utilities.factories import UserFactory @@ -274,4 +312,4 @@ def local_user(db): def schema_access_control(db): from test_utilities.factories import SchemaAccessControlFactory - return SchemaAccessControlFactory() + return SchemaAccessControlFactory() \ No newline at end of file