diff options
-rw-r--r-- | gd_diff.py | 12 | ||||
-rw-r--r-- | tests/test_gd_diff.py | 22 |
2 files changed, 34 insertions, 0 deletions
@@ -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)): |