commit 63e5ac172b6b66d1046474aefaf2ad1b19e63fc1
Author: juga0 <j...@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'))



_______________________________________________
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to