Problem with Django-compressor on my test case for Django Views

46 views Asked by At

Context

I'm working on a Django project and recently felt the need to test my views to ensure their proper functioning. To achieve this, I decided to set up unit tests and acceptance tests with Behave. However, when running my tests, I encountered an issue related to Django Compressor, a library I use for compressing static files in my project.

Problem

Every time I try to execute my tests cases about views this error raises :

raise OfflineGenerationError(
compressor.exceptions.OfflineGenerationError: You have offline compression enabled but key "3e7f5ee33c06d182d3e3f00854139e79ed028f324df0775d235088d452390285" is missing from offline manifest. You may need to run "python manage.py compress". Here is the original content:


        <link href="/static/themes/snexi/custom.scss" rel="stylesheet" type="text/x-scss" media="screen"/>
        <link href="/static/css/global.css" rel="stylesheet" type="text/x-scss" media="screen"/>

When i try locally the command python manage.py compress this error raises :

CommandError: An error occurred during rendering customer/agencies/send_links/list.html: [Errno 21] Is a directory: '/home/rbouard/dev/snexi_v2/src/snexi/static'

This is not specific for one template.

Configuration

Here's an overview of my current configuration:

  • Django version 5.0.1
  • Django Compressor version 4.4

This my Django settings about static files and compressor :

# Static files
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS: List[str] = [os.path.join(BASE_DIR, 'snexi', 'static'), ]

SASS_PROCESSOR_ROOT = '%s/static/' % (BASE_DIR,)  # FIXME : à bouger

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
)

COMPRESS_ENABLED = True
COMPRESS_OFFLINE = True
COMPRESS_URL = STATIC_URL
COMPRESS_ROOT = STATIC_ROOT
COMPRESS_OUTPUT_DIR = 'CACHE'

# List of CSS preprocessors to use
COMPRESS_PRECOMPILERS = (
    ('text/x-scss', 'django_libsass.SassCompiler'),
)
COMPRESS_FILTERS = {
    'css': ['compressor.filters.css_default.CssAbsoluteFilter'],
    'js': ['compressor.filters.jsmin.JSMinFilter']
}

Thank you in advance for your assistance!

I just want the command for compress working locally and my test passes and I seen nobody have the same problem on StackOverflow.

0

There are 0 answers