From 9dca20c34657ab6e3ed2a93fe3f6e630d4311774 Mon Sep 17 00:00:00 2001
From: Dominik George <dominik.george@teckids.org>
Date: Wed, 11 Dec 2019 13:40:11 +0100
Subject: [PATCH] [CI] Improve configuration of Selenium tests

* Use implicit skip of SeleniumTestCase if no browsers are selected
* Allow selecting browsers from TEST_SELENIUM_BROWSERS environment variable
* Allow defining listen address and HTTP host separately
---
 biscuit/core/tests/browser/test_selenium.py | 11 ++++-------
 tox.ini                                     |  4 +++-
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/biscuit/core/tests/browser/test_selenium.py b/biscuit/core/tests/browser/test_selenium.py
index 6b352c56d..e808f3fb1 100644
--- a/biscuit/core/tests/browser/test_selenium.py
+++ b/biscuit/core/tests/browser/test_selenium.py
@@ -5,14 +5,11 @@ import pytest
 from django.test.selenium import SeleniumTestCase
 
 
-if not os.environ.get('TEST_SELENIUM_HUB', None):
-    pytest.skip('Selenium hub not defined.', allow_module_level=True)
-
-
 class SeleniumTests(SeleniumTestCase):
-    external_host = os.environ.get('TEST_LISTEN_ADDRESS', '127.0.0.1')
-    browsers = ['chrome', 'firefox']
-    selenium_hub = 'http://%s/wd/hub' % os.environ.get('TEST_SELENIUM_HUB', '127.0.0.1:4444')
+    host = os.environ.get('TEST_LISTEN_ADDRESS', '') or '127.0.0.1'
+    external_host = os.environ.get('TEST_HOST', '') or None
+    browsers = list(filter(bool, os.environ.get('TEST_SELENIUM_BROWSERS', '').split(',')))
+    selenium_hub = 'http://%s/wd/hub' % os.environ.get('TEST_SELENIUM_HUB', '') or '127.0.0.1:4444'
 
     @classmethod
     def _screenshot(cls, filename):
diff --git a/tox.ini b/tox.ini
index 3a10d7fab..705a1ebda 100644
--- a/tox.ini
+++ b/tox.ini
@@ -9,8 +9,10 @@ skip_install = true
 commands = pytest --pylama --cov=biscuit biscuit/core/
 setenv =
     TEST_SCREENSHOT_PATH = {env:TEST_SCREENSHOT_PATH:}
-    TEST_SELENIUM_HUB = {env:TEST_SELENIUM_HUB:}
+    TEST_SELENIUM_HUB = {env:TEST_SELENIUM_HUB:127.0.0.1:4444}
+    TEST_SELENIUM_BROWSERS = {env:TEST_SELENIUM_BROWSERS:}
     TEST_LISTEN_ADDRESS = {env:TEST_LISTEN_ADDRESS:127.0.0.1}
+    TEST_HOST = {env:TEST_HOST:}
 
 [pylama]
 linters = pycodestyle,pyflakes,radon
-- 
GitLab