gns-deb-diff

automate the documentation of the differences between gNewSense and Debian.
git clone git://git.ricketyspace.net/gns-deb-diff.git
Log | Files | Refs

commit fca51ac7858705dbf11b3900d40b40bbe7145aba
parent 0b80b898c84b8747fe8b8ac7b485b06f7cd1e22e
Author: rsiddharth <s@ricketyspace.net>
Date:   Sun, 13 Nov 2016 18:33:03 +0000

Add `configure` function.

* gd_diff.py (configure): New function.
* tests/test_gd_diff.py (test_configure): Test for `configure` function.

Diffstat:
gd_diff.py | 12++++++++++++
tests/test_gd_diff.py | 22++++++++++++++++++++++
2 files changed, 34 insertions(+), 0 deletions(-)

diff --git 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 @@ -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)):