Commits

Lukas Linhart committed 8c91c7e

Utility method for currently running liveserver

Comments (0)

Files changed (2)

djangosanetesting/noseplugins.py

 
 #from djagnosanetesting.cache import flush_django_cache
 from djangosanetesting.selenium.driver import selenium
+from djangosanetesting.utils import (
+    get_live_server_path,
+    DEFAULT_LIVE_SERVER_ADDRESS, DEFAULT_LIVE_SERVER_PORT
+)
 
 __all__ = ("CherryPyLiveServerPlugin", "DjangoLiveServerPlugin", "DjangoPlugin", "SeleniumPlugin", "SaneTestSelectionPlugin")
 
-DEFAULT_LIVE_SERVER_PORT=8000
-DEFAULT_LIVE_SERVER_ADDRESS='0.0.0.0'
-DEFAULT_URL_ROOT_SERVER_ADDRESS = 'localhost'
-
 def flush_urlconf(case):
     if hasattr(case, '_old_root_urlconf'):
         settings.ROOT_URLCONF = case._old_root_urlconf
                       getattr(settings, "SELENIUM_HOST", 'localhost'),
                       int(getattr(settings, "SELENIUM_PORT", 4444)),
                       getattr(settings, "SELENIUM_BROWSER_COMMAND", '*opera'),
-                      getattr(settings, "SELENIUM_URL_ROOT", getattr(settings, "URL_ROOT", "http://%s:%s/" % (
-                        getattr(settings, "URL_ROOT_SERVER_ADDRESS", DEFAULT_URL_ROOT_SERVER_ADDRESS),
-                        getattr(settings, "LIVE_SERVER_PORT", DEFAULT_LIVE_SERVER_PORT)
-                      ))),
+                      getattr(settings, "SELENIUM_URL_ROOT", get_live_server_path()),
                   )
             try:
                 sel.start()

djangosanetesting/utils.py

 from django.conf import settings
 
+DEFAULT_LIVE_SERVER_PROTOCOL = "http"
+DEFAULT_LIVE_SERVER_PORT = 8000
+DEFAULT_LIVE_SERVER_ADDRESS = '0.0.0.0'
+DEFAULT_URL_ROOT_SERVER_ADDRESS = 'localhost'
+
+
+
 def is_test_database():
     """
     Return whether we're using test database. Can be used to determine if we're
         test_database_name = TEST_DATABASE_PREFIX + settings.DATABASE_NAME
 
     return settings.DATABASE_NAME == test_database_name
+
+def get_live_server_path():
+
+    return getattr(settings, "URL_ROOT", "%s://%s:%s/" % (
+        getattr(settings, "LIVE_SERVER_PROTOCOL", DEFAULT_LIVE_SERVER_PROTOCOL),
+        getattr(settings, "URL_ROOT_SERVER_ADDRESS", DEFAULT_URL_ROOT_SERVER_ADDRESS),
+        getattr(settings, "LIVE_SERVER_PORT", DEFAULT_LIVE_SERVER_PORT)
+    ))