Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django application selenium testing no static files

Tags:

I want to do some functional tests on my django app. I'm using selenium, tests works but the problem is with static files. The css/js status is not found. My tests is running on localhost:8081. Example bootstrap.css:

<h1>Not Found</h1><p>The requested URL /static/frontend/bootstrap/3.3.0/css/bootstrap.css was not found on this server.</p>

I can't find any information do I have add some extra config for selenium app?

Trackback:

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/test/testcases.py", line 1028, in __call__
    return super(FSFilesHandler, self).__call__(environ, start_response)
  File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    response = self.get_response(request)
  File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/test/testcases.py", line 1011, in get_response
    return self.serve(request)
  File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/test/testcases.py", line 1023, in serve
    return serve(request, final_rel_path, document_root=self.get_base_dir())
  File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/views/static.py", line 50, in serve
    fullpath = os.path.join(document_root, newpath)
  File "/home/t/py/django/bid/src/venv/lib/python2.7/posixpath.py", line 77, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
like image 496
strz Avatar asked Nov 25 '14 22:11

strz


3 Answers

Instead of using LiveServerTestCase from django.test you can use StaticLiveServerTestCase from django.contrib.staticfiles.testing.

Notice not just the different class-name, but also the different module-name:

from django.test import LiveServerTestCase #     ^-- vs --v from django.contrib.staticfiles.testing import StaticLiveServerTestCase 
like image 171
Seth Burgess Avatar answered Sep 27 '22 03:09

Seth Burgess


Ok I found the solution. First I had to add in setting

STATIC_ROOT = 'my static dir'

then:

./manage.py collectstatic
like image 31
strz Avatar answered Sep 26 '22 03:09

strz


I had a similar issue and none of the answers above helped me.

For anyone using Whitenoise as a static file server, it turns out you may have to change the value of the STATICFILES_STORAGE setting in your app, from:

STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

To:

STATICFILES_STORAGE = "whitenoise.storage.CompressedStaticFilesStorage"

That fixed my problem. See this page for more information.

like image 32
scūriolus Avatar answered Sep 23 '22 03:09

scūriolus