guide icon indicating copy to clipboard operation
guide copied to clipboard

ValueError: Missing staticfiles manifest while doing a view test

Open alexwayne opened this issue 2 years ago • 1 comments

Hello Wagtail team,

I am starting to use Wagtail. I find it a fascinating product.

While doing a test during development, for a class-based view I came across an error. I am adding it here, as it can help other developers, or perhaps it can be considered in future release of Wagtail:

ERROR: test_part_audit_request_list_view_with_permission (paudits.tests.TestPartAuditRequestList.test_part_audit_request_list_view_with_permission) ValueError: Missing staticfiles manifest entry for 'locals/logo.jpg'

I checked to see if the file "locals/logo.jpg" was at its place. It was, And browsing I could also see it.

What I did to avoid the error and run the test successfully, was to move one line from settings/base.py, to both settings/dev.py and to settings/production.py. Here is the original line:

base.py

STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"

From above, I commented out the STATICFILES_STORAGE constant, and added it to:

dev.py

STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage"

and to production.py

STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"

Hope this helps. By the way, this is the code that was failing in my test:

class TestPartAuditRequestList(TestCase):
    def setUp(self):
        self.user = User.objects.create_user(
            username='testuser',
            password='12345'
        )
        permission = Permission.objects.get(codename='view_partauditrequest')
        self.user.user_permissions.add(permission)
        self.client = Client()
        self.url = reverse('paudits:partauditrequest_list')

    def test_part_audit_request_list_view_with_permission(self):
        self.client.login(username='testuser', password='12345')
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, 200)

After the change, the tests ran OK.

alexwayne avatar Mar 23 '23 00:03 alexwayne

Thank you for sharing this. I spent quite some time trying to fix the same issue and this did it!

h-garcia avatar May 22 '25 12:05 h-garcia