def local_user(db): return UserFactory()
def user(db): return UserFactory(id=-1, username='******')
def user(etools_user): return UserFactory(username=etools_user.username, email=etools_user.email)
def users(db): UserFactory(username="******") UserFactory(username="******", is_superuser=True, is_staff=True)
def client(self): user = UserFactory(is_superuser=True) client = APIClient() client.force_authenticate(user) return client
def django_db_setup(request, django_test_environment, django_db_blocker, django_db_use_migrations, django_db_keepdb, django_db_createdb, django_db_modify_db_settings, enable_migration_signals, pytestconfig): if django_db_createdb or enable_migration_signals: warnings.warn("Warning: pre/post migrate signals are enabled \n") else: warnings.warn("Warning: pre/post migrate signals have been disabled\n") import django.core.management.commands.migrate django.core.management.commands.migrate.emit_pre_migrate_signal = MagicMock( ) django.core.management.commands.migrate.emit_post_migrate_signal = MagicMock( ) # """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 setup_databases_args = {} if not django_db_use_migrations: _disable_native_migrations() if django_db_keepdb and not django_db_createdb: setup_databases_args["keepdb"] = True # this patch is logically wrong, but we do not use constance permissions # otherwise test fails with # # .venv/lib/python3.9/site-packages/django/db/backends/utils.py:84: in _execute # return self.cursor.execute(sql, params) # E django.db.utils.ProgrammingError: relation "django_content_type" does not exist # E LINE 1: ..."."app_label", "django_content_type"."model" FROM "django_co... # E ^ # signals.post_migrate.disconnect(dispatch_uid='constance.create_perm') with django_db_blocker.unblock(): db_cfg = setup_databases(verbosity=request.config.option.verbose, interactive=False, **setup_databases_args) def _teardown_database(): with django_db_blocker.unblock(): teardown_databases(db_cfg, verbosity=request.config.option.verbose) if not django_db_keepdb: request.addfinalizer(_teardown_database) from test_utilities.factories import UserFactory from unicef_rest_framework.models import Service, UserAccessControl from etools_datamart.apps.etl.models import EtlTask from etools_datamart.apps.tracking.models import APIRequestLog with django_db_blocker.unblock(): EtlTask.objects.inspect() Service.objects.load_services() UserAccessControl.objects.all().delete() APIRequestLog.objects.truncate() UserFactory(username='******', is_superuser=True) from django.contrib.sites.models import Site Site.objects.get_or_create(domain='example.com', name='example.com') assert Service.objects.exists() assert not APIRequestLog.objects.exists()
def local_user(db): from test_utilities.factories import UserFactory return UserFactory()
def user(etools_user): from test_utilities.factories import UserFactory return UserFactory(username=etools_user.username, azure_id=uuid.uuid4(), email=etools_user.email)
def staff_user(etools_user): from test_utilities.factories import UserFactory return UserFactory(username=etools_user.username, email=etools_user.email, is_staff=True)
def user2(db): from test_utilities.factories import UserFactory return UserFactory()