File: test_complete_ui.py

package info (click to toggle)
pwman3 0.13.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 636 kB
  • sloc: python: 3,421; makefile: 215; sh: 61; javascript: 6
file content (81 lines) | stat: -rw-r--r-- 3,126 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# ============================================================================
# This file is part of Pwman3.
#
# Pwman3 is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2
# as published by the Free Software Foundation;
#
# Pwman3 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Pwman3; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# ============================================================================
# Copyright (C) 2012-2019 Oz N Tiram <oz.tiram@gmail.com>
# ============================================================================
# pylint: disable=I0011
from __future__ import print_function

import pexpect
import unittest
import shutil
import sys
import os

class Ferrum(unittest.TestCase):
    def clean_files(self):
        #lfile = 'convert-test.log'
        #with open(lfile) as l:
        #    lines = l.readlines()
        #    orig = lines[0].split(':')[-1].strip()
        #    backup = lines[1].split()[-1].strip()
        #shutil.copy(backup, orig)
        # do some cleaning
        # os.remove(lfile)
        if os.path.exists('test-chg_passwd.log'):
            os.remove('test-chg_passwd.log')
        #os.remove(backup)
        db = os.path.join(os.path.dirname(__file__), 'foo.baz.db')
        if os.path.exists(db):
            os.remove(db)

    @unittest.skip("obsolete")
    def test_b_run_convert(self):
        "invoke pwman with -k option to convert the old data"
        lfile = 'convert-test.log'
        logfile = open(lfile, 'wb')
        cmd = (os.path.join(os.path.dirname(__file__), '../scripts/pwman3'
                            ) + ' -k -e Blowfish -d ')
        child = pexpect.spawn(cmd, logfile=logfile)
        child.expect('[\s|\S]+Please enter your password:', timeout=10)
        self.assertEqual(6, child.sendline('12345'))

        rv = child.expect('pwman successfully converted the old database')
        self.assertEqual(0, rv)
        # if successfully converted, reset the converted database
        # todo - add test to run auto_convert

    def test_c_change_pass(self):
        lfile = 'test-chg_passwd.log'
        logfile = open(lfile, 'wb')
        cmd = shutil.which('pwman3')
        db = 'sqlite://' + os.path.join(os.path.dirname(__file__), 'foo.baz.db')
        child = pexpect.spawn(cmd + ' -d ' + db, logfile=logfile)
        if sys.version_info[0] > 2:
            child.expect('[\s|\S]+(password:)$', timeout=10)
        child.sendline('foobar')
        child.sendline('foobar')
        self.clean_files()


def suite():
    loader = unittest.TestLoader()
    suite = unittest.TestSuite()
    suite.addTest(loader.loadTestsFromTestCase(Ferrum))
    return suite

if __name__ == '__main__':
    unittest.TextTestRunner(verbosity=2).run(suite())