diff --git a/backend/src/zango/apps/shared/tenancy/management/commands/ws_makemigration.py b/backend/src/zango/apps/shared/tenancy/management/commands/ws_makemigration.py index 0e1259c2e..50f872ff4 100644 --- a/backend/src/zango/apps/shared/tenancy/management/commands/ws_makemigration.py +++ b/backend/src/zango/apps/shared/tenancy/management/commands/ws_makemigration.py @@ -33,9 +33,6 @@ def add_arguments(self, parser): "workspace", help="The workspace name to be used.", ) - parser.add_argument( - "--test", action="store_true", help="Run the migration for test database" - ) parser.add_argument( "--is_package_migration", action="store_true", @@ -43,10 +40,7 @@ def add_arguments(self, parser): ) def handle(self, *args, **options): - is_test_mode = options["test"] tenant = options["workspace"] - if is_test_mode: - connection.settings_dict["NAME"] = connection.settings_dict["NAME"] while True: try: tenant_obj = TenantModel.objects.get(name=tenant) diff --git a/backend/src/zango/apps/shared/tenancy/management/commands/ws_migrate.py b/backend/src/zango/apps/shared/tenancy/management/commands/ws_migrate.py index fecd45b12..65479f895 100644 --- a/backend/src/zango/apps/shared/tenancy/management/commands/ws_migrate.py +++ b/backend/src/zango/apps/shared/tenancy/management/commands/ws_migrate.py @@ -1,7 +1,6 @@ from django_tenants.management.commands.migrate_schemas import MigrateSchemasCommand from django.conf import settings -from django.db import connection from zango.apps.shared.tenancy.models import TenantModel @@ -15,16 +14,10 @@ def add_arguments(self, parser): "workspace", help="The workspace name to be used.", ) - parser.add_argument( - "--test", action="store_true", help="Run the migration for test database" - ) parser.add_argument("--package", help="Run the migrations for the package") def handle(self, *args, **options): - is_test_mode = options["test"] tenant = options["workspace"] - if is_test_mode: - connection.settings_dict["NAME"] = connection.settings_dict["NAME"] while True: try: tenant_obj = TenantModel.objects.get(name=tenant) diff --git a/backend/src/zango/core/utils.py b/backend/src/zango/core/utils.py index b6108f274..8b1995c39 100644 --- a/backend/src/zango/core/utils.py +++ b/backend/src/zango/core/utils.py @@ -1,5 +1,7 @@ import json +from importlib import import_module + import pytz from django.conf import settings @@ -51,6 +53,14 @@ def get_mock_request(**kwargs): request.META = kwargs.get("META", {}) request.header = kwargs.get("header", {}) + if kwargs.get("session", False): + session = kwargs.get("session") + if session: + request.session = session + else: + engine = import_module(settings.SESSION_ENGINE) + request.session = engine.SessionStore() + return request diff --git a/backend/src/zango/test/client.py b/backend/src/zango/test/client.py index bd76a4fce..cdac3de46 100644 --- a/backend/src/zango/test/client.py +++ b/backend/src/zango/test/client.py @@ -5,6 +5,7 @@ from django.http import HttpRequest, SimpleCookie from django.test import Client, RequestFactory +from zango.core.utils import get_mock_request from zango.middleware.tenant import ZangoTenantMainMiddleware @@ -31,19 +32,7 @@ class ZangoRequestFactory(BaseZangoRequestFactory, RequestFactory): pass -class ZangoClient(BaseZangoRequestFactory, Client): - def _create_mock_request(self): - request = HttpRequest() - request.tenant = self.tenant - - if self.session: - request.session = self.session - else: - engine = import_module(settings.SESSION_ENGINE) - request.session = engine.SessionStore() - - return request - +class ZangoClient(ZangoRequestFactory, Client): def logout(self): """Log out the user by removing the cookies and session object.""" from django.contrib.auth import logout @@ -62,7 +51,7 @@ def logout(self): def _login(self, user, backend=None): from django.contrib.auth import login - request = self._create_mock_request() + request = get_mock_request(session=self.session) login(request, user, backend) request.session.save() @@ -80,7 +69,7 @@ def _login(self, user, backend=None): ) def login(self, **credentials): - request = self._create_mock_request() + request = get_mock_request(session=self.session) user = authenticate(request, **credentials) if user: diff --git a/backend/src/zango/tests/apps/dynamic_models/zango_fields/test_foreign_key/tests.py b/backend/src/zango/tests/apps/dynamic_models/zango_fields/test_foreign_key/tests.py index 94c4b535e..d87ffb192 100644 --- a/backend/src/zango/tests/apps/dynamic_models/zango_fields/test_foreign_key/tests.py +++ b/backend/src/zango/tests/apps/dynamic_models/zango_fields/test_foreign_key/tests.py @@ -47,8 +47,7 @@ def setUpClass(self): def syn_db(self): call_command( 'ws_migrate', - 'testapp', - '--test' + 'testapp' ) def test_callable_default(self): diff --git a/backend/src/zango/tests/migrations/test_ws_makemigration/tests.py b/backend/src/zango/tests/migrations/test_ws_makemigration/tests.py index fdf41f134..3cd701582 100644 --- a/backend/src/zango/tests/migrations/test_ws_makemigration/tests.py +++ b/backend/src/zango/tests/migrations/test_ws_makemigration/tests.py @@ -23,7 +23,6 @@ def test_ws_makemigration(self): call_command( 'ws_makemigration', 'testapp', - '--test', stdout=out ) self.assertIn("0001_initial", out.getvalue())