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

[ch28811] update libraries: pytest-django==4.5.2 #240

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ flake8 = "*"
flake8-html = "*"
isort = "*"
pytest-cov = "*"
pytest-django = "<4.3"
pytest-django = "==4.5.2"
pytest-echo = "*"
vcrpy = "*"

Expand Down
65 changes: 57 additions & 8 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions tests/_test_lib/settings_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import random

from etools_datamart.config.settings import * # noqa
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/_test_lib/test_utilities/factories/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class InterventionFactory(DataMartModelFactory):

class Meta:
model = models.Intervention
django_get_or_create = ('intervention_id', 'schema_name')


class InterventionByLocationFactory(DataMartModelFactory):
Expand Down
44 changes: 41 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import pytest
from _pytest.fixtures import SubRequest
from pytest_django.django_compat import is_django_unittest


def pytest_configure(config):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -274,4 +312,4 @@ def local_user(db):
def schema_access_control(db):
from test_utilities.factories import SchemaAccessControlFactory

return SchemaAccessControlFactory()
return SchemaAccessControlFactory()