summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2016-11-13 18:33:03 +0000
committerrsiddharth <s@ricketyspace.net>2016-11-13 18:33:03 +0000
commitfca51ac7858705dbf11b3900d40b40bbe7145aba (patch)
treed2525f6df845ae186cb7cc1250498ed9fb106b84
parent0b80b898c84b8747fe8b8ac7b485b06f7cd1e22e (diff)
Add `configure` function.
* gd_diff.py (configure): New function. * tests/test_gd_diff.py (test_configure): Test for `configure` function.
-rw-r--r--gd_diff.py12
-rw-r--r--tests/test_gd_diff.py22
2 files changed, 34 insertions, 0 deletions
diff --git a/gd_diff.py b/gd_diff.py
index 220f832..d25415b 100644
--- a/gd_diff.py
+++ b/gd_diff.py
@@ -313,3 +313,15 @@ def configured_p():
return True
else:
return False
+
+
+def configure():
+ """Configure gns-deb-diff.
+ """
+ # prompt username and password.
+ config = {}
+ config['user'] = input('gNewSense wiki username: ')
+ config['pass'] = input('gNewSense wiki password: ')
+
+ json.dump(config, open(config_file(), 'w'))
+ os.chmod(config_file(), mode=0o600)
diff --git a/tests/test_gd_diff.py b/tests/test_gd_diff.py
index 67d9b8d..b62e014 100644
--- a/tests/test_gd_diff.py
+++ b/tests/test_gd_diff.py
@@ -6,6 +6,7 @@
# gns-deb-diff is under the Public Domain. See
# <https://creativecommons.org/publicdomain/zero/1.0>
+import builtins
import json
import os
import subprocess
@@ -350,6 +351,27 @@ class TestGdDiff(object):
assert_equal(configured, True)
+ def test_configure(self):
+ def env(e):
+ return self.test_home
+
+ inputs = ['usrnm', 'weasaspeciesrfckd']
+ def mock_input(p):
+ return inputs.pop(0)
+
+ with mock.patch('os.getenv', new=env), \
+ mock.patch('builtins.input', new=mock_input):
+ configure()
+
+ # read config file
+ config = json.load(open(config_file(), 'r'))
+
+ # tests
+ assert_equal(config['user'], 'usrnm')
+ assert_equal(config['pass'], 'weasaspeciesrfckd')
+ assert_equal(oct(os.stat(config_file()).st_mode), '0o100600')
+
+
def teardown(self):
"""Teardown method for this class."""
if(path.exists(self.gns_pkgs_dir)):