refactor: lift shared test settings up to common module (#37714)
This commit is contained in:
206
cms/envs/test.py
206
cms/envs/test.py
@@ -14,39 +14,19 @@ sessions. Assumes structure:
|
||||
|
||||
|
||||
import os
|
||||
from uuid import uuid4
|
||||
|
||||
from django.utils.translation import gettext_lazy
|
||||
from path import Path as path
|
||||
|
||||
from openedx.core.lib.derived import derive_settings
|
||||
from edx_django_utils.plugins import add_plugins
|
||||
|
||||
from xmodule.modulestore.modulestore_settings import update_module_store_settings # pylint: disable=wrong-import-order
|
||||
|
||||
from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType
|
||||
from openedx.core.lib.derived import derive_settings
|
||||
from openedx.core.lib.features_setting_proxy import FeaturesProxy
|
||||
|
||||
from .common import *
|
||||
|
||||
# import settings from LMS for consistent behavior with CMS
|
||||
from lms.envs.test import ( # pylint: disable=wrong-import-order, disable=unused-import
|
||||
ACCOUNT_MICROFRONTEND_URL,
|
||||
COMPREHENSIVE_THEME_DIRS, # unimport:skip
|
||||
ECOMMERCE_API_URL,
|
||||
ENABLE_COMPREHENSIVE_THEMING,
|
||||
JWT_AUTH,
|
||||
LOGIN_ISSUE_SUPPORT_LINK,
|
||||
MEDIA_ROOT,
|
||||
MEDIA_URL,
|
||||
ORDER_HISTORY_MICROFRONTEND_URL,
|
||||
PLATFORM_DESCRIPTION,
|
||||
PLATFORM_NAME,
|
||||
PROFILE_MICROFRONTEND_URL,
|
||||
REGISTRATION_EXTRA_FIELDS,
|
||||
GRADES_DOWNLOAD,
|
||||
SITE_NAME,
|
||||
WIKI_ENABLED,
|
||||
XBLOCK_RUNTIME_V2_EPHEMERAL_DATA_CACHE,
|
||||
)
|
||||
from openedx.envs.test import * # pylint: disable=wrong-import-order
|
||||
|
||||
# A proxy for feature flags stored in the settings namespace
|
||||
FEATURES = FeaturesProxy(globals())
|
||||
@@ -56,41 +36,17 @@ FEATURES = FeaturesProxy(globals())
|
||||
STUDIO_NAME = gettext_lazy("Your Platform 𝓢𝓽𝓾𝓭𝓲𝓸")
|
||||
STUDIO_SHORT_NAME = gettext_lazy("𝓢𝓽𝓾𝓭𝓲𝓸")
|
||||
|
||||
# Allow all hosts during tests, we use a lot of different ones all over the codebase.
|
||||
ALLOWED_HOSTS = ["*"]
|
||||
COMMON_TEST_DATA_ROOT = COMMON_ROOT / "test" / "data"
|
||||
|
||||
# mongo connection settings
|
||||
MONGO_PORT_NUM = int(os.environ.get("EDXAPP_TEST_MONGO_PORT", "27017"))
|
||||
MONGO_HOST = os.environ.get("EDXAPP_TEST_MONGO_HOST", "localhost")
|
||||
|
||||
THIS_UUID = uuid4().hex[:5]
|
||||
|
||||
TEST_ROOT = path("test_root")
|
||||
|
||||
# Want static files in the same dir for running on jenkins.
|
||||
STATIC_ROOT = TEST_ROOT / "staticfiles"
|
||||
WEBPACK_LOADER["DEFAULT"]["STATS_FILE"] = STATIC_ROOT / "webpack-stats.json"
|
||||
WEBPACK_LOADER['DEFAULT']['LOADER_CLASS'] = 'webpack_loader.loader.FakeWebpackLoader'
|
||||
|
||||
GITHUB_REPO_ROOT = TEST_ROOT / "data"
|
||||
DATA_DIR = TEST_ROOT / "data"
|
||||
COMMON_TEST_DATA_ROOT = COMMON_ROOT / "test" / "data"
|
||||
|
||||
# For testing "push to lms"
|
||||
ENABLE_EXPORT_GIT = True
|
||||
GIT_REPO_EXPORT_DIR = TEST_ROOT / "export_course_repos"
|
||||
|
||||
# TODO (cpennington): We need to figure out how envs/test.py can inject things into common.py so that we don't have to repeat this sort of thing # lint-amnesty, pylint: disable=line-too-long
|
||||
STATICFILES_DIRS = [
|
||||
COMMON_ROOT / "static",
|
||||
PROJECT_ROOT / "static",
|
||||
]
|
||||
STATICFILES_DIRS += [
|
||||
(course_dir, COMMON_TEST_DATA_ROOT / course_dir)
|
||||
for course_dir in os.listdir(COMMON_TEST_DATA_ROOT)
|
||||
if os.path.isdir(COMMON_TEST_DATA_ROOT / course_dir)
|
||||
]
|
||||
|
||||
# Avoid having to run collectstatic before the unit test suite
|
||||
# If we don't add these settings, then Django templates that can't
|
||||
# find pipelined assets will raise a ValueError.
|
||||
@@ -140,9 +96,6 @@ CMS_BASE = "localhost:8001"
|
||||
CMS_ROOT_URL = f"http://{CMS_BASE}"
|
||||
|
||||
COURSE_AUTHORING_MICROFRONTEND_URL = "http://course-authoring-mfe"
|
||||
DISCUSSIONS_MICROFRONTEND_URL = "http://discussions-mfe"
|
||||
ACCOUNT_MICROFRONTEND_URL = 'http://account-mfe'
|
||||
LEARNING_MICROFRONTEND_URL = 'http://learning-mfe'
|
||||
|
||||
CACHES = {
|
||||
# This is the cache used for most things.
|
||||
@@ -180,72 +133,25 @@ CACHES = {
|
||||
|
||||
################################# CELERY ######################################
|
||||
|
||||
CELERY_ALWAYS_EAGER = True
|
||||
CELERY_RESULT_BACKEND = "django-cache"
|
||||
|
||||
CLEAR_REQUEST_CACHE_ON_TASK_COMPLETION = False
|
||||
|
||||
# test_status_cancel in cms/cms_user_tasks/test.py is failing without this
|
||||
# @override_setting for BROKER_URL is not working in testcase, so updating here
|
||||
BROKER_URL = "memory://localhost/"
|
||||
|
||||
########################### Server Ports ###################################
|
||||
|
||||
# These ports are carefully chosen so that if the browser needs to
|
||||
# access them, they will be available through the SauceLabs SSH tunnel
|
||||
XQUEUE_PORT = 8040
|
||||
YOUTUBE_PORT = 8031
|
||||
LTI_PORT = 8765
|
||||
VIDEO_SOURCE_PORT = 8777
|
||||
|
||||
|
||||
################### Make tests faster
|
||||
# http://slacy.com/blog/2012/04/make-your-tests-faster-in-django-1-4/
|
||||
PASSWORD_HASHERS = [
|
||||
"django.contrib.auth.hashers.MD5PasswordHasher",
|
||||
]
|
||||
|
||||
# No segment key
|
||||
CMS_SEGMENT_KEY = None
|
||||
|
||||
DISABLE_SET_JWT_COOKIES_FOR_TESTS = True
|
||||
|
||||
ENABLE_SERVICE_STATUS = True
|
||||
|
||||
# Toggles embargo on for testing
|
||||
EMBARGO = True
|
||||
|
||||
TEST_THEME = COMMON_ROOT / "test" / "test-theme"
|
||||
|
||||
# For consistency in user-experience, keep the value of this setting in sync with
|
||||
# the one in lms/envs/test.py
|
||||
ENABLE_DISCUSSION_SERVICE = False
|
||||
|
||||
# Enable a parental consent age limit for testing
|
||||
PARENTAL_CONSENT_AGE_LIMIT = 13
|
||||
|
||||
# Enable certificates for the tests
|
||||
CERTIFICATES_HTML_VIEW = True
|
||||
|
||||
# Enable content libraries code for the tests
|
||||
ENABLE_CONTENT_LIBRARIES = True
|
||||
|
||||
ENABLE_EDXNOTES = True
|
||||
|
||||
# MILESTONES
|
||||
MILESTONES_APP = True
|
||||
|
||||
# ENTRANCE EXAMS
|
||||
ENTRANCE_EXAMS = True
|
||||
|
||||
VIDEO_CDN_URL = {"CN": "http://api.xuetangx.com/edx/video?s3_url="}
|
||||
|
||||
# Courseware Search Index
|
||||
ENABLE_COURSEWARE_INDEX = True
|
||||
ENABLE_LIBRARY_INDEX = True
|
||||
SEARCH_ENGINE = "search.tests.mock_search_engine.MockSearchEngine"
|
||||
|
||||
ENABLE_ENROLLMENT_TRACK_USER_PARTITION = True
|
||||
|
||||
########################## AUTHOR PERMISSION #######################
|
||||
ENABLE_CREATOR_GROUP = False
|
||||
@@ -253,15 +159,11 @@ ENABLE_CREATOR_GROUP = False
|
||||
# teams feature
|
||||
ENABLE_TEAMS = True
|
||||
|
||||
# Dummy secret key for dev/test
|
||||
SECRET_KEY = "85920908f28904ed733fe576320db18cabd7b6cd"
|
||||
|
||||
######### custom courses #########
|
||||
INSTALLED_APPS += [
|
||||
"openedx.core.djangoapps.ccxcon.apps.CCXConnectorConfig",
|
||||
"common.djangoapps.third_party_auth.apps.ThirdPartyAuthConfig",
|
||||
]
|
||||
CUSTOM_COURSES_EDX = True
|
||||
|
||||
########################## VIDEO IMAGE STORAGE ############################
|
||||
VIDEO_IMAGE_SETTINGS = dict(
|
||||
@@ -275,86 +177,56 @@ VIDEO_IMAGE_SETTINGS = dict(
|
||||
)
|
||||
VIDEO_IMAGE_DEFAULT_FILENAME = "default_video_image.png"
|
||||
|
||||
########################## VIDEO TRANSCRIPTS STORAGE ############################
|
||||
VIDEO_TRANSCRIPTS_SETTINGS = dict(
|
||||
VIDEO_TRANSCRIPTS_MAX_BYTES=3 * 1024 * 1024, # 3 MB
|
||||
STORAGE_KWARGS=dict(
|
||||
location=MEDIA_ROOT,
|
||||
base_url=MEDIA_URL,
|
||||
),
|
||||
DIRECTORY_PREFIX="video-transcripts/",
|
||||
)
|
||||
############################## Authentication ##############################
|
||||
|
||||
# Most of the JWT_AUTH settings come from cms/envs/common.py (from openedx/envs/common.py),
|
||||
# but here we update to use JWKS values from openedx/envs/test.py for testing.
|
||||
JWT_AUTH.update(jwt_jwks_values)
|
||||
|
||||
####################### Plugin Settings ##########################
|
||||
|
||||
# pylint: disable=wrong-import-position, wrong-import-order
|
||||
from edx_django_utils.plugins import add_plugins
|
||||
|
||||
# pylint: disable=wrong-import-position, wrong-import-order
|
||||
from openedx.core.djangoapps.plugins.constants import ProjectType, SettingsType
|
||||
|
||||
add_plugins(__name__, ProjectType.CMS, SettingsType.TEST)
|
||||
|
||||
########################## Derive Any Derived Settings #######################
|
||||
|
||||
derive_settings(__name__)
|
||||
|
||||
############### Settings for edx-rbac ###############
|
||||
SYSTEM_WIDE_ROLE_CLASSES = os.environ.get("SYSTEM_WIDE_ROLE_CLASSES", [])
|
||||
################################ Templates #################################
|
||||
|
||||
DEFAULT_MOBILE_AVAILABLE = True
|
||||
|
||||
PROCTORING_SETTINGS = {}
|
||||
|
||||
# Used in edx-proctoring for ID generation in lieu of SECRET_KEY - dummy value
|
||||
# (ref MST-637)
|
||||
PROCTORING_USER_OBFUSCATION_KEY = "85920908f28904ed733fe576320db18cabd7b6cd"
|
||||
# For the "preview" template engine, the CMS uses the same dirs as the LMS. Here we mutate
|
||||
# the DIRS list to match the MAKO_TEMPLATE_DIRS_BASE list produced by lms.envs.test.
|
||||
preview_template = next(d for d in TEMPLATES if d["NAME"] == "preview")
|
||||
preview_template['DIRS'].extend([
|
||||
COMMON_ROOT / 'test' / 'templates',
|
||||
COMMON_ROOT / 'test' / 'test_sites',
|
||||
REPO_ROOT / 'openedx' / 'core' / 'djangolib' / 'tests' / 'templates',
|
||||
])
|
||||
for theme_dir in COMPREHENSIVE_THEME_DIRS: # pylint: disable=not-an-iterable
|
||||
preview_template['DIRS'].insert(0, theme_dir)
|
||||
|
||||
############### Settings for Django Rate limit #####################
|
||||
|
||||
RATELIMIT_RATE = '2/m'
|
||||
|
||||
##### LOGISTRATION RATE LIMIT SETTINGS #####
|
||||
LOGISTRATION_RATELIMIT_RATE = "5/5m"
|
||||
LOGISTRATION_PER_EMAIL_RATELIMIT_RATE = "6/5m"
|
||||
LOGISTRATION_API_RATELIMIT = "5/m"
|
||||
|
||||
REGISTRATION_VALIDATION_RATELIMIT = "5/minute"
|
||||
REGISTRATION_RATELIMIT = "5/minute"
|
||||
OPTIONAL_FIELD_API_RATELIMIT = "5/m"
|
||||
|
||||
RESET_PASSWORD_TOKEN_VALIDATE_API_RATELIMIT = "2/m"
|
||||
RESET_PASSWORD_API_RATELIMIT = "2/m"
|
||||
|
||||
############### Settings for proctoring ###############
|
||||
PROCTORING_USER_OBFUSCATION_KEY = "test_key"
|
||||
|
||||
#################### Network configuration ####################
|
||||
# Tests are not behind any proxies
|
||||
CLOSEST_CLIENT_IP_FROM_HEADERS = []
|
||||
|
||||
COURSE_LIVE_GLOBAL_CREDENTIALS["BIG_BLUE_BUTTON"] = {
|
||||
"KEY": "***",
|
||||
"SECRET": "***",
|
||||
"URL": "***",
|
||||
}
|
||||
|
||||
############## openedx-learning (Learning Core) config ##############
|
||||
OPENEDX_LEARNING = {
|
||||
"MEDIA": {"BACKEND": "django.core.files.storage.InMemoryStorage", "OPTIONS": {"location": MEDIA_ROOT + "_private"}}
|
||||
}
|
||||
|
||||
|
||||
# This value has traditionally been imported from the LMS. Now we modify it to match to avoid dependency
|
||||
# on the LMS settings. The default in cms/envs/common.py includes the `marketing_emails_opt_in` field which is not
|
||||
# in the dict that was previously imported from the LMS for testing so we remove it here
|
||||
REGISTRATION_EXTRA_FIELDS.pop("marketing_emails_opt_in", None)
|
||||
|
||||
# Course Live
|
||||
COURSE_LIVE_GLOBAL_CREDENTIALS["BIG_BLUE_BUTTON"] = big_blue_button_credentials
|
||||
|
||||
# Proctoring
|
||||
PROCTORING_SETTINGS = {}
|
||||
|
||||
#### Override default production settings for testing purposes
|
||||
|
||||
AWS_QUERYSTRING_AUTH = False
|
||||
AWS_S3_CUSTOM_DOMAIN = "SET-ME-PLEASE (ex. bucket-name.s3.amazonaws.com)"
|
||||
AWS_STORAGE_BUCKET_NAME = "SET-ME-PLEASE (ex. bucket-name)"
|
||||
CELERY_BROKER_HOSTNAME = "localhost"
|
||||
CELERY_BROKER_PASSWORD = "celery"
|
||||
CELERY_BROKER_TRANSPORT = "amqp"
|
||||
CELERY_BROKER_USER = "celery"
|
||||
CHAT_COMPLETION_API = "https://example.com/chat/completion"
|
||||
CHAT_COMPLETION_API_KEY = "i am a key"
|
||||
del AUTHORING_API_URL
|
||||
del BROKER_HEARTBEAT
|
||||
del BROKER_HEARTBEAT_CHECKRATE
|
||||
@@ -364,18 +236,6 @@ del PARSE_KEYS
|
||||
del SESSION_INACTIVITY_TIMEOUT_IN_SECONDS
|
||||
ENTERPRISE_API_URL = "https://localhost:18000/enterprise/api/v1/"
|
||||
ENTERPRISE_CONSENT_API_URL = "https://localhost:18000/consent/api/v1/"
|
||||
ENTERPRISE_ENROLLMENT_API_URL = "https://localhost:18000/api/enrollment/v1/"
|
||||
INACTIVE_USER_URL = "http://localhost:18010"
|
||||
LMS_INTERNAL_ROOT_URL = "https://localhost:18000"
|
||||
OPENAPI_CACHE_TIMEOUT = 0
|
||||
POLICY_CHANGE_GRADES_ROUTING_KEY = "edx.lms.core.default"
|
||||
SECURE_PROXY_SSL_HEADER = None
|
||||
SESSION_COOKIE_DOMAIN = ""
|
||||
SESSION_ENGINE = "django.contrib.sessions.backends.db"
|
||||
SHARED_COOKIE_DOMAIN = ""
|
||||
SINGLE_LEARNER_COURSE_REGRADE_ROUTING_KEY = "edx.lms.core.default"
|
||||
SOFTWARE_SECURE_VERIFICATION_ROUTING_KEY = "edx.lms.core.default"
|
||||
STATIC_ROOT_BASE = "/edx/var/edxapp/staticfiles"
|
||||
STATIC_URL_BASE = "/static/"
|
||||
|
||||
CATALOG_MICROFRONTEND_URL = "http://catalog-mfe"
|
||||
|
||||
Reference in New Issue
Block a user