def _setup_media_dirs(self): self.tempdir = tempfile.mkdtemp(prefix='rb-tests-') # Don't go through Pipeline for everything, since we're not # triggering pipelining of our media. settings.STATICFILES_STORAGE = \ 'django.contrib.staticfiles.storage.StaticFilesStorage' if os.path.exists(self.tempdir): self._destroy_media_dirs() settings.STATIC_ROOT = os.path.join(self.tempdir, 'static') settings.MEDIA_ROOT = os.path.join(self.tempdir, 'media') settings.SITE_DATA_DIR = os.path.join(self.tempdir, 'data') images_dir = os.path.join(settings.MEDIA_ROOT, "uploaded", "images") legacy_extensions_media = os.path.join(settings.MEDIA_ROOT, 'ext') extensions_media = os.path.join(settings.STATIC_ROOT, 'ext') for dirname in (images_dir, legacy_extensions_media, extensions_media): if not os.path.exists(dirname): os.makedirs(dirname) # Collect all static media needed for tests, including web-based tests. execute_from_command_line([ __file__, 'collectstatic', '--noinput', '-v', '0', ]) generate_media_serial()
def _setup_media_dirs(self): self.tempdir = tempfile.mkdtemp(prefix="rb-tests-") # Don't go through Pipeline for everything, since we're not # triggering pipelining of our media. settings.STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage" if os.path.exists(self.tempdir): self._destroy_media_dirs() settings.STATIC_ROOT = os.path.join(self.tempdir, "static") settings.MEDIA_ROOT = os.path.join(self.tempdir, "media") images_dir = os.path.join(settings.MEDIA_ROOT, "uploaded", "images") legacy_extensions_media = os.path.join(settings.MEDIA_ROOT, "ext") extensions_media = os.path.join(settings.STATIC_ROOT, "ext") for dirname in (images_dir, legacy_extensions_media, extensions_media): if not os.path.exists(dirname): os.makedirs(dirname) # Collect all static media needed for tests, including web-based tests. execute_from_command_line([__file__, "collectstatic", "--noinput", "-v", "0"]) generate_media_serial()
def setup_test_environment(self, *args, **kwargs): """Set up an environment for the unit tests. This will handle setting all the default settings for a Djblets-based project and will create the directory structure needed for the tests in a temp directory. Subclasses can override this to provide additional setup logic. This must be called before :py:meth:`run_tests`. Args: *args (tuple): Additional positional arguments to pass to Django's version of this method. **kwargs (dict): Additional keyword arguments to pass to Django's version of this method. """ super(TestRunner, self).setup_test_environment(*args, **kwargs) # Default to testing in a non-subdir install. settings.SITE_ROOT = '/' # Set some defaults for cache serials, in case the tests need them. settings.AJAX_SERIAL = 123 settings.TEMPLATE_SERIAL = 123 # Set a faster password hasher, for performance. settings.PASSWORD_HASHERS = ( 'django.contrib.auth.hashers.SHA1PasswordHasher', ) # Make sure we're using standard static files storage, and not # something like Pipeline or S3 (since we don't want to trigger any # special behavior). Subclasses are free to override this setting. settings.STATICFILES_STORAGE = \ 'django.contrib.staticfiles.storage.StaticFilesStorage' # By default, don't look up DMARC records when generating From # addresses for e-mails. Just assume we can, since we're not # sending anything out. Some unit tests will override # this. settings.EMAIL_ENABLE_SMART_SPOOFING = False # Create a temp directory that tests can rely upon. self.tempdir = tempfile.mkdtemp(prefix='rb-tests-') # Configure file paths for static media. This will handle the main # static and uploaded media directories, along with extension # directories (for projects that need to use them). settings.STATIC_URL = settings.SITE_ROOT + 'static/' settings.MEDIA_URL = settings.SITE_ROOT + 'media/' settings.STATIC_ROOT = os.path.join(self.tempdir, 'static') settings.MEDIA_ROOT = os.path.join(self.tempdir, 'media') required_dirs = self.setup_dirs() + [ settings.STATIC_ROOT, settings.MEDIA_ROOT, os.path.join(settings.MEDIA_ROOT, 'ext'), os.path.join(settings.STATIC_ROOT, 'ext'), ] for dirname in required_dirs: if not os.path.exists(dirname): os.makedirs(dirname) if self.needs_collect_static: # Collect all static media needed for tests. execute_from_command_line([ __file__, 'collectstatic', '--noinput', '-v', '0', ]) generate_media_serial()
def setup_siteconfig(): """Set up the siteconfig for tests. This is run at the start of the project-wide test session, putting together a suitable test environment for Review Board's test suite. """ from django.conf import settings # Default to testing in a non-subdir install. settings.SITE_ROOT = '/' # Set some defaults for cache serials, in case the tests need them. settings.AJAX_SERIAL = 123 settings.TEMPLATE_SERIAL = 123 # Set a faster password hasher, for performance. settings.PASSWORD_HASHERS = ( 'django.contrib.auth.hashers.SHA1PasswordHasher', ) # Make sure we're using standard static files storage, and not # something like Pipeline or S3 (since we don't want to trigger any # special behavior). Subclasses are free to override this setting. settings.STATICFILES_STORAGE = \ 'django.contrib.staticfiles.storage.StaticFilesStorage' # By default, don't look up DMARC records when generating From # addresses for e-mails. Just assume we can, since we're not # sending anything out. Some unit tests will override # this. settings.EMAIL_ENABLE_SMART_SPOOFING = False # Create a temp directory that tests can rely upon. tests_tempdir = tempfile.mkdtemp(prefix='rb-tests-') # Configure file paths for static media. This will handle the main # static and uploaded media directories, along with extension # directories (for projects that need to use them). settings.STATIC_URL = settings.SITE_ROOT + 'static/' settings.MEDIA_URL = settings.SITE_ROOT + 'media/' settings.STATIC_ROOT = os.path.join(tests_tempdir, 'static') settings.MEDIA_ROOT = os.path.join(tests_tempdir, 'media') settings.SITE_DATA_DIR = os.path.join(tests_tempdir, 'data') settings.HAYSTACK_CONNECTIONS['default']['PATH'] = \ os.path.join(settings.SITE_DATA_DIR, 'search-index') required_dirs = [ settings.SITE_DATA_DIR, settings.STATIC_ROOT, settings.MEDIA_ROOT, os.path.join(settings.MEDIA_ROOT, 'uploaded', 'images'), os.path.join(settings.MEDIA_ROOT, 'ext'), os.path.join(settings.STATIC_ROOT, 'ext'), ] for dirname in required_dirs: if not os.path.exists(dirname): os.makedirs(dirname) from django.core import management management.call_command('collectstatic', verbosity=0, interactive=False) generate_media_serial()