2014-11-25 16 views
16

Voglio fare alcuni test funzionali sulla mia app django. Sto usando il selenio, i test funzionano, ma il problema è con i file statici. Lo stato css/js non è stato trovato. I miei test sono in esecuzione su localhost: 8081. Esempio bootstrap.css:test selenio applicazione django nessun file statico

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

Non riesco a trovare alcuna informazione devo aggiungere un po 'di configurazione in più per il selenio 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' 

risposta

32

Supponendo che si sta utilizzando 1.7, è possibile utilizzare StaticLiveServerTestCase da django.contrib.staticfiles.testing, invece di LiveServerTestCase (da django.test).

+2

Si prega di migliorare la risposta –

+0

Lifesaver. Tutto il selenio doco che ho trovato è per django 1.6. – MagicLAMP

+0

riferimento: https://docs.djangoproject.com/en/dev/topics/testing/tools/#liveservertestcase – ThePhi

9

Ok ho trovato la soluzione. Per prima cosa ho dovuto aggiungere nella creazione

STATIC_ROOT = 'my static dir' 

poi:

./manage.py collectstatic 
+2

Grazie, 'LiveServerTestCase' utilizza le impostazioni di produzione (' DEBUG = True') e pertanto richiede innanzitutto la raccolta di file statici. È chiaro ora – MartinM

+0

@MartinM Dovrebbe essere "DEBUG = False'? –

Problemi correlati