Permalink
Browse files

test_gpg.py: Add additional tests coverage now at 92% for gpg.py 85% …

…total
  • Loading branch information...
dol-sen committed Jan 22, 2017
1 parent 6f57907 commit 40ec1f516d0ae73ac0ef248c5813ea9005f10de0
Showing with 121 additions and 0 deletions.
  1. +121 −0 test/pyGPG/test_gpg.py
View
@@ -73,3 +73,124 @@ def test_gpg_options2():
assert v[-1] == '--xauthority'
+def test_runGPG1():
+ cfg = GPGConfig()
+ gpg = GPG(cfg)
+ v = gpg.runGPG()
+ assert v == None
+
+
+def test_listkeys1():
+ cfg = GPGConfig()
+ homedir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gpghome')
+ print("****", homedir)
+ cfg.options['tasks']['list-keys'] = ['--homedir', homedir]
+ print("****", cfg.get_key('tasks', 'list-keys'))
+ gpg = GPG(cfg)
+ v = gpg.listkeys()
+ assert v.returncode == -1
+ assert v.output == ''
+ assert v.stderr_out == ['']
+
+def test_listkeys2():
+ cfg = GPGConfig()
+ homedir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gpghome')
+ print("****", homedir)
+ cfg.options['tasks']['list-keys'] = ['--homedir', homedir]
+ print("****", cfg.get_key('tasks', 'list-keys'))
+ gpg = GPG(cfg)
+ v = gpg.listkeys('0xABB2F2DC74991EE9')
+ print("**** keytype", v.keytype)
+ assert v.keyid == []
+ assert v.fingerprint == []
+ assert v.username == []
+ assert v.keytype == []
+ assert v.output == '''pub rsa4096/0xABB2F2DC74991EE9 2017-01-22 [C] [expires: 2020-01-07]
+ 476935D6D659B4C27B700FEDABB2F2DC74991EE9
+uid [ultimate] pyGPG Test <pygpg@nowhere.foo>
+sub rsa4096/0xA9661AC8014A7CF0 2017-01-22 [S] [expires: 2020-01-07]
+
+'''
+ assert v.stderr_out == ['[GNUPG:] KEY_CONSIDERED 476935D6D659B4C27B700FEDABB2F2DC74991EE9 0', '']
+
+
+def test_listkey1():
+ cfg = GPGConfig()
+ homedir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gpghome')
+ print("****", homedir)
+ cfg.options['tasks']['list-key'] = ['--homedir', homedir]
+ print("****", cfg.get_key('tasks', 'list-key'))
+ gpg = GPG(cfg)
+ v = gpg.listkey()
+ assert v.output == ''
+ assert v.stderr_out == ['']
+
+
+def test_listkey2():
+ cfg = GPGConfig()
+ homedir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gpghome')
+ print("****", homedir)
+ cfg.options['tasks']['list-key'] = ['--homedir', homedir]
+ print("****", cfg.get_key('tasks', 'list-key'))
+ gpg = GPG(cfg)
+ v = gpg.listkey('0xABB2F2DC74991EE9')
+ assert v.keyid == []
+ assert v.fingerprint == []
+ assert v.username == []
+ assert v.keytype == []
+ assert v.output == '''pub rsa4096/0xABB2F2DC74991EE9 2017-01-22 [C] [expires: 2020-01-07]
+ 476935D6D659B4C27B700FEDABB2F2DC74991EE9
+uid [ultimate] pyGPG Test <pygpg@nowhere.foo>
+sub rsa4096/0xA9661AC8014A7CF0 2017-01-22 [S] [expires: 2020-01-07]
+
+'''
+ assert v.stderr_out == ['[GNUPG:] KEY_CONSIDERED 476935D6D659B4C27B700FEDABB2F2DC74991EE9 0', '']
+
+def test_listkey3():
+ cfg = GPGConfig()
+ homedir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gpghome')
+ print("****", homedir)
+ cfg.options['tasks']['list-key'] = ['--homedir', homedir, '--with-colons']
+ print("****", cfg.get_key('tasks', 'list-key'))
+ gpg = GPG(cfg)
+ v = gpg.listkey('0xABB2F2DC74991EE9')
+ assert v.stderr_out == ['[GNUPG:] KEY_CONSIDERED 476935D6D659B4C27B700FEDABB2F2DC74991EE9 0', '']
+ assert v.keyid == [('PUB', 'long_keyid', 'ABB2F2DC74991EE9'), ('SUB', 'long_keyid', 'A9661AC8014A7CF0')]
+ assert v.fingerprint == [('FPR', 'fingerprint', '476935D6D659B4C27B700FEDABB2F2DC74991EE9'),
+ ('FPR', 'fingerprint', '884D0847E08005BC1E6DA041A9661AC8014A7CF0')]
+ assert v.username == [('UID', 'user_ID', 'pyGPG Test <pygpg@nowhere.foo>')]
+ assert v.keytype == []
+
+
+
+def test_fingerprint1():
+ cfg = GPGConfig()
+ homedir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gpghome')
+ print("****", homedir)
+ cfg.options['tasks']['fingerprint'] = ['--homedir', homedir]
+ print("****", cfg.get_key('tasks', 'fingerprint'))
+ gpg = GPG(cfg)
+ v = gpg.fingerprint()
+ assert v.output == ''
+ assert v.stderr_out == ['']
+
+def test_fingerprint2():
+ cfg = GPGConfig()
+ homedir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'gpghome')
+ print("****", homedir)
+ cfg.options['tasks']['fingerprint'] = ['--homedir', homedir, '--with-colons']
+ print("****", cfg.get_key('tasks', 'fingerprint'))
+ gpg = GPG(cfg)
+ v = gpg.fingerprint('0xABB2F2DC74991EE9')
+ assert v.keyid == [('PUB', 'long_keyid', 'ABB2F2DC74991EE9'), ('SUB', 'long_keyid', 'A9661AC8014A7CF0')]
+ assert v.fingerprint == [('FPR', 'fingerprint', '476935D6D659B4C27B700FEDABB2F2DC74991EE9'),
+ ('FPR', 'fingerprint', '884D0847E08005BC1E6DA041A9661AC8014A7CF0')]
+ assert v.username == [('UID', 'user_ID', 'pyGPG Test <pygpg@nowhere.foo>')]
+ assert v.output == '''tru::1:1485105495:1578417368:3:1:5
+pub:u:4096:1:ABB2F2DC74991EE9:1485105368:1578417368::u:::cSC:::::::
+fpr:::::::::476935D6D659B4C27B700FEDABB2F2DC74991EE9:
+uid:u::::1485105368::64D29249C3C521D9557A5AE461B02179C7D5F227::pyGPG Test <pygpg@nowhere.foo>:
+sub:u:4096:1:A9661AC8014A7CF0:1485105368:1578417368:::::s::::::
+fpr:::::::::884D0847E08005BC1E6DA041A9661AC8014A7CF0:
+'''
+ assert v.stderr_out == ['[GNUPG:] KEY_CONSIDERED 476935D6D659B4C27B700FEDABB2F2DC74991EE9 0', '']

0 comments on commit 40ec1f5

Please sign in to comment.