def test_load_builtin_backend(self): self.assertEqual(1, cli.main(["get", "-b", "keyring.backend.UncryptedFileKeyring", "foo", "bar"])) backend = keyring.get_keyring() self.assertTrue(isinstance(backend, keyring.backend.UncryptedFileKeyring))
def test_load_specific_backend_with_path(self): keyring_path = os.path.join(os.path.dirname(keyring.__file__), 'tests') self.assertEqual(0, cli.main(["get", "-b", "test_cli.FakeKeyring", "-p", keyring_path, "foo", "bar"])) backend = keyring.get_keyring() # Somehow, this doesn't work, because the full dotted name of the class # is not the same as the one expected :( #self.assertTrue(isinstance(backend, FakeKeyring)) self.assertEqual(FakeKeyring.PASSWORD, self.password_returned)
def test_wrong_arguments(self): self.assertEqual(1, cli.main([])) self.assertRaises(SystemExit, cli.main, ["get"]) self.assertRaises(SystemExit, cli.main, ["get", "foo"]) self.assertRaises(SystemExit, cli.main, ["get", "foo", "bar", "baz"]) self.assertRaises(SystemExit, cli.main, ["set"]) self.assertRaises(SystemExit, cli.main, ["set", "foo"]) self.assertRaises(SystemExit, cli.main, ["set", "foo", "bar", "baz"]) self.assertRaises(SystemExit, cli.main, ["foo", "bar", "baz"])
# -*- coding: utf-8 -*- import re import sys from keyring.cli import main if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit(main())
if __name__ == '__main__': from keyring import cli cli.main()
def test_set_and_get_password(self): self.password = "******" self.assertEqual(0, cli.main(["set", "foo", "bar"])) self.assertEqual(0, cli.main(["get", "foo", "bar"])) self.assertEqual("plop", self.password_returned)
def test_get_unexistent_password(self): self.assertEqual(1, cli.main(["get", "foo", "bar"])) self.assertEqual(None, self.password_returned)