mirror of
https://github.com/bendtherules/pytest_gui_status.git
synced 2026-08-18 13:42:26 +00:00
Move redis tests inside TestRedisFail class
This commit is contained in:
+81
-90
@@ -41,121 +41,112 @@ def redis_master(request, auto_shutdown=True):
|
|||||||
@patch.dict("os.environ",
|
@patch.dict("os.environ",
|
||||||
{"PYTEST_STATUS_PORT": str(REDIS_TEST_PORT)})
|
{"PYTEST_STATUS_PORT": str(REDIS_TEST_PORT)})
|
||||||
@patch.dict("sys.modules", {"htmlPy": mock_htmlPy_module})
|
@patch.dict("sys.modules", {"htmlPy": mock_htmlPy_module})
|
||||||
def test_redis_fail_1(tmpdir):
|
class TestRedisFail(object):
|
||||||
# load new redis port
|
"""test that appropriate errors are raised when redis is in incorrect state / shutdown"""
|
||||||
import pytest_gui_status.status_gui.gui_backend as gui_backend
|
|
||||||
reload_2_3(pytest_gui_status.utils)
|
|
||||||
reload_2_3(gui_backend)
|
|
||||||
reload_2_3(status_plugin)
|
|
||||||
|
|
||||||
# dont start redis. Also if redis running, stop it
|
def test_redis_fail_1(self, tmpdir):
|
||||||
redis_db = redis.StrictRedis(host='localhost', port=REDIS_TEST_PORT, db=0)
|
# load new redis port
|
||||||
try:
|
import pytest_gui_status.status_gui.gui_backend as gui_backend
|
||||||
assert redis_db.ping()
|
reload_2_3(pytest_gui_status.utils)
|
||||||
redis_db.shutdown()
|
reload_2_3(gui_backend)
|
||||||
except redis.exceptions.ConnectionError:
|
reload_2_3(status_plugin)
|
||||||
pass
|
|
||||||
except AssertionError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# mock Controller requirements and app_gui.stop
|
# dont start redis. Also if redis running, stop it
|
||||||
fake_app_gui = MagicMock()
|
redis_db = redis.StrictRedis(host='localhost', port=REDIS_TEST_PORT, db=0)
|
||||||
with pytest.raises(redis.exceptions.ConnectionError) as error_info:
|
try:
|
||||||
gui_backend.Controller(fake_app_gui).redraw()
|
assert redis_db.ping()
|
||||||
|
redis_db.shutdown()
|
||||||
|
except redis.exceptions.ConnectionError:
|
||||||
|
pass
|
||||||
|
except AssertionError:
|
||||||
|
pass
|
||||||
|
|
||||||
assert str(error_info.value) == "Cant connect to this socket. Is redis running?\n" \
|
# mock Controller requirements and app_gui.stop
|
||||||
+ "Stopping pytest_status_gui"
|
fake_app_gui = MagicMock()
|
||||||
|
with pytest.raises(redis.exceptions.ConnectionError) as error_info:
|
||||||
|
gui_backend.Controller(fake_app_gui).redraw()
|
||||||
|
|
||||||
|
assert str(error_info.value) == "Cant connect to this socket. Is redis running?\n" \
|
||||||
|
+ "Stopping pytest_status_gui"
|
||||||
|
|
||||||
@patch.dict("os.environ",
|
def test_redis_fail_2(self, tmpdir, redis_master):
|
||||||
{"PYTEST_STATUS_PORT": str(REDIS_TEST_PORT)})
|
# load new redis port
|
||||||
@patch.dict("sys.modules", {"htmlPy": mock_htmlPy_module})
|
import pytest_gui_status.status_gui.gui_backend as gui_backend
|
||||||
def test_redis_fail_2(tmpdir, redis_master):
|
reload_2_3(pytest_gui_status.utils)
|
||||||
# load new redis port
|
reload_2_3(gui_backend)
|
||||||
import pytest_gui_status.status_gui.gui_backend as gui_backend
|
reload_2_3(status_plugin)
|
||||||
reload_2_3(pytest_gui_status.utils)
|
|
||||||
reload_2_3(gui_backend)
|
|
||||||
reload_2_3(status_plugin)
|
|
||||||
|
|
||||||
# start Redis
|
# start Redis
|
||||||
redis_master.init(tmpdir.strpath)
|
redis_master.init(tmpdir.strpath)
|
||||||
|
|
||||||
# status_plugin.Helpers.on_start(tmpdir.strpath)
|
# status_plugin.Helpers.on_start(tmpdir.strpath)
|
||||||
|
|
||||||
# make PYTEST_STATUS_DB value corrupt/incorrect
|
# make PYTEST_STATUS_DB value corrupt/incorrect
|
||||||
redis_db = redis.StrictRedis(host='localhost', port=REDIS_TEST_PORT, db=0)
|
redis_db = redis.StrictRedis(host='localhost', port=REDIS_TEST_PORT, db=0)
|
||||||
redis_db.set("PYTEST_STATUS_DB", "0")
|
redis_db.set("PYTEST_STATUS_DB", "0")
|
||||||
|
|
||||||
# mock Controller requirements and app_gui.stop
|
# mock Controller requirements and app_gui.stop
|
||||||
fake_app_gui = MagicMock()
|
fake_app_gui = MagicMock()
|
||||||
with pytest.raises(redis.exceptions.ConnectionError) as error_info:
|
with pytest.raises(redis.exceptions.ConnectionError) as error_info:
|
||||||
gui_backend.Controller(fake_app_gui).redraw()
|
gui_backend.Controller(fake_app_gui).redraw()
|
||||||
|
|
||||||
assert str(error_info.value) == "Redis is running on this port, but it is not related to pytest status\n"\
|
assert str(error_info.value) == "Redis is running on this port, but it is not related to pytest status\n"\
|
||||||
+ "Stopping pytest_status_gui"
|
+ "Stopping pytest_status_gui"
|
||||||
|
|
||||||
fake_app_gui.stop.assert_called_with()
|
fake_app_gui.stop.assert_called_with()
|
||||||
|
|
||||||
# auto cleanup of redis master by fixture
|
# auto cleanup of redis master by fixture
|
||||||
|
|
||||||
|
def test_redis_fail_3(self, tmpdir, redis_master):
|
||||||
|
# load new redis port
|
||||||
|
import pytest_gui_status.status_gui.gui_backend as gui_backend
|
||||||
|
reload_2_3(pytest_gui_status.utils)
|
||||||
|
reload_2_3(gui_backend)
|
||||||
|
reload_2_3(status_plugin)
|
||||||
|
|
||||||
@patch.dict("os.environ",
|
# start Redis
|
||||||
{"PYTEST_STATUS_PORT": str(REDIS_TEST_PORT)})
|
redis_master.init(tmpdir.strpath)
|
||||||
@patch.dict("sys.modules", {"htmlPy": mock_htmlPy_module})
|
|
||||||
def test_redis_fail_3(tmpdir, redis_master):
|
|
||||||
# load new redis port
|
|
||||||
import pytest_gui_status.status_gui.gui_backend as gui_backend
|
|
||||||
reload_2_3(pytest_gui_status.utils)
|
|
||||||
reload_2_3(gui_backend)
|
|
||||||
reload_2_3(status_plugin)
|
|
||||||
|
|
||||||
# start Redis
|
# delete PYTEST_STATUS_DB
|
||||||
redis_master.init(tmpdir.strpath)
|
redis_db = redis.StrictRedis(host='localhost', port=REDIS_TEST_PORT, db=0)
|
||||||
|
redis_db.delete("PYTEST_STATUS_DB")
|
||||||
|
|
||||||
# delete PYTEST_STATUS_DB
|
# mock Controller requirements and app_gui.stop
|
||||||
redis_db = redis.StrictRedis(host='localhost', port=REDIS_TEST_PORT, db=0)
|
fake_app_gui = MagicMock()
|
||||||
redis_db.delete("PYTEST_STATUS_DB")
|
|
||||||
|
|
||||||
# mock Controller requirements and app_gui.stop
|
with pytest.raises(redis.exceptions.ConnectionError) as error_info:
|
||||||
fake_app_gui = MagicMock()
|
gui_backend.Controller(fake_app_gui).redraw()
|
||||||
|
|
||||||
with pytest.raises(redis.exceptions.ConnectionError) as error_info:
|
assert str(error_info.value) == "Redis is running on this port, but it is not related to pytest status\n"\
|
||||||
gui_backend.Controller(fake_app_gui).redraw()
|
+ "Stopping pytest_status_gui"
|
||||||
|
|
||||||
assert str(error_info.value) == "Redis is running on this port, but it is not related to pytest status\n"\
|
fake_app_gui.stop.assert_called_with()
|
||||||
+ "Stopping pytest_status_gui"
|
|
||||||
|
|
||||||
fake_app_gui.stop.assert_called_with()
|
# auto cleanup of redis master by fixture
|
||||||
|
|
||||||
# auto cleanup of redis master by fixture
|
def test_redis_fail_4(self, tmpdir, redis_master):
|
||||||
|
# load new redis port
|
||||||
|
import pytest_gui_status.status_gui.gui_backend as gui_backend
|
||||||
|
reload_2_3(pytest_gui_status.utils)
|
||||||
|
reload_2_3(gui_backend)
|
||||||
|
reload_2_3(status_plugin)
|
||||||
|
|
||||||
|
# start Redis
|
||||||
|
redis_master.init(tmpdir.strpath)
|
||||||
|
|
||||||
@patch.dict("os.environ",
|
# redis_db = redis.StrictRedis(host='localhost', port=REDIS_TEST_PORT, db=0)
|
||||||
{"PYTEST_STATUS_PORT": str(REDIS_TEST_PORT)})
|
|
||||||
@patch.dict("sys.modules", {"htmlPy": mock_htmlPy_module})
|
|
||||||
def test_redis_fail_4(tmpdir, redis_master):
|
|
||||||
# load new redis port
|
|
||||||
import pytest_gui_status.status_gui.gui_backend as gui_backend
|
|
||||||
reload_2_3(pytest_gui_status.utils)
|
|
||||||
reload_2_3(gui_backend)
|
|
||||||
reload_2_3(status_plugin)
|
|
||||||
|
|
||||||
# start Redis
|
# mock Controller requirements and app_gui.stop
|
||||||
redis_master.init(tmpdir.strpath)
|
# provide invalid path
|
||||||
|
fake_app_gui = MagicMock()
|
||||||
|
fake_app_gui.dir_name = r"Invalid/Path"
|
||||||
|
|
||||||
# redis_db = redis.StrictRedis(host='localhost', port=REDIS_TEST_PORT, db=0)
|
with pytest.raises(redis.exceptions.ConnectionError) as error_info:
|
||||||
|
gui_backend.Controller(fake_app_gui).redraw()
|
||||||
|
|
||||||
# mock Controller requirements and app_gui.stop
|
assert str(error_info.value) == "dir_name = {dir_name} not found in redis db".format(
|
||||||
# provide invalid path
|
dir_name=fake_app_gui.dir_name)
|
||||||
fake_app_gui = MagicMock()
|
|
||||||
fake_app_gui.dir_name = r"Invalid/Path"
|
|
||||||
|
|
||||||
with pytest.raises(redis.exceptions.ConnectionError) as error_info:
|
fake_app_gui.stop.assert_called_with()
|
||||||
gui_backend.Controller(fake_app_gui).redraw()
|
|
||||||
|
|
||||||
assert str(error_info.value) == "dir_name = {dir_name} not found in redis db".format(
|
# auto cleanup of redis master by fixture
|
||||||
dir_name=fake_app_gui.dir_name)
|
|
||||||
|
|
||||||
fake_app_gui.stop.assert_called_with()
|
|
||||||
|
|
||||||
# auto cleanup of redis master by fixture
|
|
||||||
|
|||||||
Reference in New Issue
Block a user