Redis fail tests in gui test + todo update

This commit is contained in:
2016-01-03 11:29:34 +05:30
parent 1e8203a92d
commit 86c7117076
2 changed files with 134 additions and 10 deletions
+14 -10
View File
@@ -1,16 +1,20 @@
Todo Todo
------ ------
1. Allow config for template 1. Add redis sudden fail tests - shutdown or crash after startup\
2. Add well-explained readme - module shouldnt crash/ work incorrectly, should exit with error message
3. use logging.debug / log file for more prints 2 Tests with setup/teardown/class when needed*
4. Add gui tests 3 Redis test port from env*
5. Use config.pluginmanager.hasplugin('plugin_name') when needed 4 Faster Tests wiith timeout, if required by extra api to params*
6. Release on pypi 5. Allow config for template
7. Test on Appveyor - install redis via chocolatey 6. Add cli doc for --show_status_gui
8. Give icon to gui + preferably dynamic with status 7. Add well-explained readme
9. Add redis sudden fail tests - shutdown or crash after startup -\ 8. use logging.debug / log file for more prints
module shouldnt crash/ work incorrectly, should exit with error message 9. Add gui tests
10. Use config.pluginmanager.hasplugin('plugin_name') when needed
11. Release on pypi
12. Test on Appveyor - install redis via chocolatey
13. Give icon to gui + preferably dynamic with status
Done Done
+120
View File
@@ -0,0 +1,120 @@
import pytest_gui_status.status_plugin.plugin as status_plugin
import pytest_gui_status.status_gui.gui_backend as gui_backend
from mock import patch, MagicMock
import redis
import pytest
REDIS_TEST_PORT = status_plugin.REDIS_PORT + 1
@patch.dict("os.environ",
{"PYTEST_STATUS_PORT": str(REDIS_TEST_PORT)})
def test_redis_fail_1(tmpdir):
# load new redis port
reload(gui_backend)
reload(status_plugin)
# dont start redis. Also if redis running, stop it
redis_db = redis.StrictRedis(host='localhost', port=REDIS_TEST_PORT, db=0)
try:
assert redis_db.ping()
redis_db.shutdown()
except redis.exceptions.ConnectionError:
pass
except AssertionError:
pass
# mock Controller requirements and app_gui.stop
fake_app_gui = MagicMock()
with pytest.raises(redis.exceptions.ConnectionError) as error_info:
gui_backend.Controller(fake_app_gui).redraw()
assert error_info.value.message == "Cant connect to this socket. Is redis running?\n" \
+ "Stopping pytest_status_gui"
@patch.dict("os.environ",
{"PYTEST_STATUS_PORT": str(REDIS_TEST_PORT)})
def test_redis_fail_2(tmpdir):
# load new redis port
reload(gui_backend)
reload(status_plugin)
# start Redis
status_plugin.Helpers.on_start(tmpdir.strpath)
# make PYTEST_STATUS_DB value corrupt/incorrect
redis_db = redis.StrictRedis(host='localhost', port=REDIS_TEST_PORT, db=0)
redis_db.set("PYTEST_STATUS_DB", "0")
# mock Controller requirements and app_gui.stop
fake_app_gui = MagicMock()
with pytest.raises(redis.exceptions.ConnectionError) as error_info:
gui_backend.Controller(fake_app_gui).redraw()
assert error_info.value.message == "Redis is running on this port, but it is not related to pytest status\n"\
+ "Stopping pytest_status_gui"
fake_app_gui.stop.assert_called_with()
# cleanup or in next test it cant be started there
redis_db.shutdown()
@patch.dict("os.environ",
{"PYTEST_STATUS_PORT": str(REDIS_TEST_PORT)})
def test_redis_fail_3(tmpdir):
# load new redis port
reload(gui_backend)
reload(status_plugin)
# start Redis
status_plugin.Helpers.on_start(tmpdir.strpath)
# delete PYTEST_STATUS_DB
redis_db = redis.StrictRedis(host='localhost', port=REDIS_TEST_PORT, db=0)
redis_db.delete("PYTEST_STATUS_DB")
# mock Controller requirements and app_gui.stop
fake_app_gui = MagicMock()
with pytest.raises(redis.exceptions.ConnectionError) as error_info:
gui_backend.Controller(fake_app_gui).redraw()
assert error_info.value.message == "Redis is running on this port, but it is not related to pytest status\n"\
+ "Stopping pytest_status_gui"
fake_app_gui.stop.assert_called_with()
# cleanup or in next test it cant be started there
redis_db.shutdown()
@patch.dict("os.environ",
{"PYTEST_STATUS_PORT": str(REDIS_TEST_PORT)})
def test_redis_fail_4(tmpdir):
# load new redis port
reload(gui_backend)
reload(status_plugin)
# start Redis
status_plugin.Helpers.on_start(tmpdir.strpath)
redis_db = redis.StrictRedis(host='localhost', port=REDIS_TEST_PORT, db=0)
# mock Controller requirements and app_gui.stop
# provide invalid path
fake_app_gui = MagicMock()
fake_app_gui.dir_name = r"Invalid/Path"
with pytest.raises(redis.exceptions.ConnectionError) as error_info:
gui_backend.Controller(fake_app_gui).redraw()
assert error_info.value.message == "dir_name = {dir_name} not found in redis db".format(
dir_name=fake_app_gui.dir_name)
fake_app_gui.stop.assert_called_with()
# cleanup or in next test it cant be started there
redis_db.shutdown()