I'm running into a problem with running TestCase
s in which I am rendering the template of a page in order to test pieces of the HTML that are produced.
Here is an example of the kind of test I am running:
test.py
from django.test import TestCase
class NavTestCase(TestCase):
def test_standard_user_nav(self):
self.client.login(username='username', password='password')
user = auth.get_user(self.client)
response = self.client.get('/')
content = response.render().content
# Run logic to check pieces of the nav in the rendered HTML
requirements.txt
django-material==1.0.0
django-nose==1.4.5
nose==1.3.7
settings.py
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
The issue is with code I added into my base.html
file to support using django-material for a recent redesign of the site. Below, the three lines in <head>
are copied directly from the django-material
documentation.
base.html
{% load static %}
<html lang="en-us">
<head>
{% include 'material/includes/material_css.html' %}
<script src="{% static '[material/js/jquery.js' %}"></script>
{% include 'material/includes/material_js.html' %}
</head>
<body>...</body>
</html>
For reference, here are links to those files:
However, these lines are what are breaking my tests. I am getting these two errors:
WARNING Exception raised while rendering {% include %} ... ValueError: Missing staticfiles manifest entry for 'material/fonts/material-design-icons/material-icons.css'
==> This is the first call in material_css.html.ValueError: Missing staticfiles manifest entry for 'material/js/jquery.js'
==> This is the 2nd line in base.html specific by the django-material docs.I do not have this problem with any other static files, either those created by me (whose entries I left out of the trimmed-down base.html I pasted above) or even seemingly the other ones provided by Actually, on closer inspection, when I remove these three lines, it then breaks on the subsequent calls to 'static' (which, again, I omitted from this example for simplicity).django-material
.
Now, following the advice of this Stack Overflow question, when I run collectstatic
locally, it does take care of this problem. However, when I deploy the code and run the tests remotely, I don't know how to get collectstatic
to run there. I tried changing the base class of my tests to StaticLiveServerTestCase, but that did not make a difference. I also see from the Nose documentation that I could create a setUp()
routine in my testing class, but given that I run tests like this in many test classes all over my code, I want to avoid running collectstatic
multiple times.
Apparently this was a feature and not a bug. I had to change how I did deployments to run collectstatic
before running the tests -- this required a change in the .yml config file custom to my continuous integration environment -- totally unrelated to any of the above. D'oh.