geonode
geonode copied to clipboard
`WmsServiceHarvestingTestCase` is broken
Besides the demo WMS service used in tests being down (#11675), there are multiple errors in WmsServiceHarvestingTestCase
. First, exceptions are being silenced, so the test case passes although it doesn't really test anything:
https://github.com/GeoNode/geonode/blob/e7b53a5c8c81a99104dd2aec5f0eab396c760c86/geonode/services/tests.py#L844-L846
The output of that print can't be seen when running tests either. Letting the exceptions propagate, it seems to be failing because gecko driver is not installed in the docker image:
Traceback (most recent call last):
File "/usr/src/geonode/geonode/services/tests.py", line 828, in setUpClass
cls.selenium = webdriver.Firefox()
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/firefox/webdriver.py", line 67, in __init__
super().__init__(command_executor=executor, options=options)
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 208, in __init__
self.start_session(capabilities)
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 292, in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 255
I was able to fix that by installing both firefox and geckodriver:
wget https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz
tar -xf geckodriver-*.tar.gz
mv geckodriver /usr/bin
apt-get update && apt-get install -y wget bzip2 libxtst6 libgtk-3-0 libx11-xcb-dev libdbus-glib-1-2 libxt6 libpci-dev && rm -rf /var/lib/apt/lists/*
wget https://archive.mozilla.org/pub/firefox/releases/62.0.3/linux-x86_64/en-US/firefox-62.0.3.tar.bz2
tar xjf firefox-*.tar.bz2
mv firefox /opt
ln -s /opt/firefox/firefox /usr/local/bin/firefox
After fixing that it also seems necessary to launch firefox as headless:
index b2ee17d81..399bccdb9 100644
--- a/geonode/services/tests.py
+++ b/geonode/services/tests.py
@@ -22,6 +22,7 @@ import mock
import logging
from flaky import flaky
+from selenium.webdriver import FirefoxOptions
from selenium import webdriver
from urllib.error import HTTPError
from collections import namedtuple
@@ -825,7 +826,9 @@ class WmsServiceHarvestingTestCase(StaticLiveServerTestCase):
cls.user.save()
cls.client.login(username="test", password="test@123")
cls.cookie = cls.client.cookies["sessionid"]
- cls.selenium = webdriver.Firefox()
+ opts = FirefoxOptions()
+ opts.add_argument("--headless")
+ cls.selenium = webdriver.Firefox(options=opts)
cls.selenium.implicitly_wait(10)
cls.selenium.get(f"{cls.live_server_url}/")
cls.selenium.add_cookie({"name": "sessionid", "value": cls.cookie.value, "secure": False, "path": "/"})
Last but not least, Django's HttpResponse
has no url
property, so these lines also throw an exception:
https://github.com/GeoNode/geonode/blob/e7b53a5c8c81a99104dd2aec5f0eab396c760c86/geonode/services/tests.py#L841-L843
I guess that's probably intended to get the final URL after being redirected by register_service, but unfortunately doesn't work.
I think I can submit a PR after #11675 gets solved.
Thanks @fvicent