diff options
author | David Pursell <dpursell@chromium.org> | 2015-04-02 07:59:25 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-04-02 20:27:52 +0000 |
commit | d4b55d732ad06b9acca3b95d0e243d578e7b256d (patch) | |
tree | fdc4742f18ec65fc3d7ffb52f9b6879f8a453b6f /lib/remote_access_unittest.py | |
parent | 1ff1ebbc9b05f2a94611f1a69e93e512bc314dda (diff) | |
download | chromite-d4b55d732ad06b9acca3b95d0e243d578e7b256d.tar.gz |
remote_access: Add default USB device accessor.
Add GetDefaultDevice() which returns a device if there is exactly one
USB device available, otherwise fails. This is the behavior we want
initially, if it turns out in testing to be inconvenient we could extend
this in the future so the user can select from a list of options.
BUG=brillo:82
TEST=cbuildbot/run_tests
Change-Id: I5ee47fa4a720b80ec66b614d1af28a2ca25099f3
Reviewed-on: https://chromium-review.googlesource.com/263691
Trybot-Ready: David Pursell <dpursell@chromium.org>
Tested-by: David Pursell <dpursell@chromium.org>
Reviewed-by: Yiming Chen <yimingc@chromium.org>
Commit-Queue: David Pursell <dpursell@chromium.org>
Diffstat (limited to 'lib/remote_access_unittest.py')
-rw-r--r-- | lib/remote_access_unittest.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/remote_access_unittest.py b/lib/remote_access_unittest.py index 800dbf517..a7f898302 100644 --- a/lib/remote_access_unittest.py +++ b/lib/remote_access_unittest.py @@ -264,6 +264,38 @@ class TestGetUSBConnectedDevices(USBDeviceTestCase): self.assertEqual(devices[index].alias, services[index].text['alias']) +class TestGetDefaultDevice(USBDeviceTestCase): + """Tests GetDefaultDevice() function.""" + + DEVICE_1 = remote_access.ChromiumOSDevice('1.1.1.1', alias='toaster1', + connect=False, ping=False) + + DEVICE_2 = remote_access.ChromiumOSDevice('1.1.1.2', alias='toaster2', + connect=False, ping=False) + + def _SetDevices(self, devices): + """Sets the devices that are available.""" + self.PatchObject( + remote_access, 'GetUSBConnectedDevices').return_value = devices + + def testNoDevices(self): + """Tests when no devices are found.""" + self._SetDevices([]) + with self.assertRaises(remote_access.DefaultDeviceError): + remote_access.GetDefaultDevice() + + def testOneDevice(self): + """Tests when one device is found.""" + self._SetDevices([self.DEVICE_1]) + self.assertEqual(self.DEVICE_1, remote_access.GetDefaultDevice()) + + def testMultipleDevices(self): + """Tests when multiple devices are found.""" + self._SetDevices([self.DEVICE_1, self.DEVICE_2]) + with self.assertRaises(remote_access.DefaultDeviceError): + remote_access.GetDefaultDevice() + + class TestUSBDeviceIP(USBDeviceTestCase): """Tests of the GetUSBDeviceIP() function.""" |