[tor-commits] [sbws/master] Add unit test for init
pastly at torproject.org
pastly at torproject.org
Wed Jul 11 15:05:40 UTC 2018
commit 63e5ac172b6b66d1046474aefaf2ad1b19e63fc1
Author: juga0 <juga at riseup.net>
Date: Thu Jul 5 19:08:07 2018 +0000
Add unit test for init
---
tests/unit/core/test_init.py | 45 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/tests/unit/core/test_init.py b/tests/unit/core/test_init.py
new file mode 100644
index 0000000..77f3b0a
--- /dev/null
+++ b/tests/unit/core/test_init.py
@@ -0,0 +1,45 @@
+"""Unit tests for sbws.core.init."""
+import logging
+import os.path
+
+import sbws
+
+
+def test_sbwshome_only_datadir(sbwshome_only_datadir, args, conf, caplog):
+ caplog.set_level(logging.DEBUG)
+ sbws.core.init.main(args, conf)
+ print(caplog.records[-1].getMessage())
+ assert "Creating {} based on example config".format(
+ os.path.join(conf['paths']['sbws_home'], 'config.ini')) \
+ in caplog.records[-1].getMessage()
+ assert os.path.isdir(conf['paths']['sbws_home'])
+ assert os.path.isdir(conf['paths']['datadir'])
+ assert os.path.isfile(os.path.join(conf['paths']['sbws_home'],
+ 'config.ini'))
+
+
+def test_sbwshome_empty(args, conf, caplog):
+ caplog.set_level(logging.DEBUG)
+ sbws.core.init.main(args, conf)
+ assert "Creating {} based on example config".format(
+ os.path.join(conf['paths']['sbws_home'], 'config.ini')) \
+ in caplog.records[-1].getMessage()
+ assert os.path.isdir(conf['paths']['sbws_home'])
+ assert os.path.isfile(os.path.join(conf['paths']['sbws_home'],
+ 'config.ini'))
+
+
+def test_sbwshome(sbwshome, args, conf, caplog):
+ caplog.set_level(logging.DEBUG)
+ try:
+ sbws.core.init.main(args, conf)
+ except SystemExit as e:
+ assert e.code == 1
+ else:
+ assert None, 'Should have failed'
+ assert "Directory already seems to be initted" \
+ in caplog.records[-1].getMessage()
+ assert os.path.isdir(conf['paths']['sbws_home'])
+ assert os.path.isdir(conf['paths']['datadir'])
+ assert os.path.isfile(os.path.join(conf['paths']['sbws_home'],
+ 'config.ini'))
More information about the tor-commits
mailing list