示例#1
0
 def test_add_rm(self):
     pwds = Accounts()
     self.assertFalse(pwds.exists('host', 'user'))
     pwds.add('host', 'user', 'pwd')
     self.assertTrue(pwds.exists('host', 'user'))
     pwds.rm('host', 'user')
     self.assertFalse(pwds.exists('host', 'user'))
示例#2
0
    def test_capitalize(self):
        pwds = Accounts()

        pwds.add('a', 'b', 'c')
        self.assertTrue(pwds.exists('a', 'b'))
        self.assertTrue(pwds.exists('A', 'b'))
        self.assertTrue(pwds.exists('a', 'B'))
        self.assertTrue(pwds.exists('A', 'B'))
        with self.assertRaises(KeyError):
            pwds.add('a', 'b', 'c')
        with self.assertRaises(KeyError):
            pwds.add('A', 'b', 'c')
        with self.assertRaises(KeyError):
            pwds.add('a', 'B', 'c')
        with self.assertRaises(KeyError):
            pwds.add('A', 'B', 'c')

        pwds.rm('A', 'B')
        self.assertFalse(pwds.exists('a', 'b'))
        self.assertFalse(pwds.exists('A', 'b'))
        self.assertFalse(pwds.exists('a', 'B'))
        self.assertFalse(pwds.exists('A', 'B'))

        pwds.add('A', 'B', 'c')
        pwds.add('a', 'c', 'd')
        pwds.add('A', 'D', 'e')
        self.assertTrue(pwds.exists('a', 'b'))
        self.assertTrue(pwds.exists('A', 'b'))
        self.assertTrue(pwds.exists('a', 'B'))
        self.assertTrue(pwds.exists('A', 'B'))
        with self.assertRaises(KeyError):
            pwds.add('a', 'b', 'c')
        with self.assertRaises(KeyError):
            pwds.add('A', 'b', 'c')
        with self.assertRaises(KeyError):
            pwds.add('a', 'B', 'c')
        with self.assertRaises(KeyError):
            pwds.add('A', 'B', 'c')
        self.assertEqual(pwds.get('A', 'b'), ('A', 'B', 'c'))
        self.assertEqual(pwds.get('a', 'B'), ('A', 'B', 'c'))
        self.assertEqual(pwds.get('A', 'B'), ('A', 'B', 'c'))
        self.assertEqual(pwds.get('a', 'c'), ('a', 'c', 'd'))
        self.assertEqual(pwds.get('A', 'D'), ('A', 'D', 'e'))