93
93
manager.clear_cache()
94
94
self.assertRaises(SSHVendorNotFound, manager.get_vendor, {})
96
def test_vendor_getting_methods_precedence(self):
96
def test_get_vendor_search_order(self):
97
# The 'get_vendor' method search for SSH vendors as following:
99
# 1. Check previously cached value
100
# 2. Check BZR_SSH environment variable
101
# 3. Check the system for known SSH vendors
102
# 4. Fall back to the default vendor if registered
104
# Let's now check the each check method in the reverse order
105
# clearing the cache between each invocation:
97
107
manager = TestSSHVendorManager()
108
# At first no vendors are found
98
109
self.assertRaises(SSHVendorNotFound, manager.get_vendor, {})
111
# If the default vendor is registered it will be returned
100
112
default_vendor = object()
101
113
manager.register_default_vendor(default_vendor)
102
114
self.assertIs(manager.get_vendor({}), default_vendor)
116
# If the known vendor is found in the system it will be returned
104
117
manager.clear_cache()
105
118
manager.set_ssh_version_string("OpenSSH")
106
119
self.assertIsInstance(manager.get_vendor({}), OpenSSHSubprocessVendor)
121
# If the BZR_SSH environment variable is found it will be treated as
108
123
manager.clear_cache()
109
124
vendor = object()
110
125
manager.register_vendor("vendor", vendor)
111
126
self.assertIs(manager.get_vendor({"BZR_SSH": "vendor"}), vendor)
128
# Last cached value always checked first
113
129
self.assertIs(manager.get_vendor({}), vendor)