Esempio n. 1
0
 def test_005(self):
     """Non-zero init."""
     global _MOCK
     _MOCK = EthernetRelayMock(num_relays=16, init_state='1010101010101010')
     with httmock.HTTMock(mock_relay):
         relay = devices.EthernetRelay()
         self.assertEqual(sum(relay.state()), 8)
Esempio n. 2
0
 def test_006(self):
     """Test verify."""
     with httmock.HTTMock(mock_relay):
         relay = devices.EthernetRelay()
         relay._relays[0] = True  # this should be disallowed anyways
         with self.assertRaises(ValueError):
             relay.verify()
Esempio n. 3
0
 def test_002(self):
     """Test all off."""
     with httmock.HTTMock(mock_relay):
         relay = devices.EthernetRelay()
         relay.all_on()
         relay.all_off()
         self.assertFalse(any(relay.state()))
Esempio n. 4
0
 def test_001(self):
     """Test all on."""
     with httmock.HTTMock(mock_relay):
         relay = devices.EthernetRelay()
         relay.all_off()
         relay.all_on()
         self.assertTrue(all(relay.state()))
Esempio n. 5
0
 def test_007(self):
     """Test check_index."""
     with httmock.HTTMock(mock_relay):
         relay = devices.EthernetRelay()
         with self.assertRaises(IndexError):
             relay.check_index(-1)
         with self.assertRaises(IndexError):
             relay.check_index(16)
Esempio n. 6
0
 def test_004(self):
     """Test toggle."""
     with httmock.HTTMock(mock_relay):
         relay = devices.EthernetRelay()
         for i in range(len(relay.state())):
             relay.toggle(i)
         self.assertTrue(all(relay.state()))
         for i in range(len(relay.state())):
             relay.toggle(i)
         self.assertFalse(any(relay.state()))
Esempio n. 7
0
 def test_003(self):
     """Test turn on and turn off."""
     with httmock.HTTMock(mock_relay):
         relay = devices.EthernetRelay()
         for i in range(len(relay.state())):
             relay.turn_on(i)
         self.assertTrue(all(relay.state()))
         for i in range(len(relay.state())):
             relay.turn_off(i)
         self.assertFalse(any(relay.state()))
Esempio n. 8
0
 def test_010(self):
     """Test init with 30001."""
     with httmock.HTTMock(mock_relay):
         relay = devices.EthernetRelay(url_base='http://192.168.1.4/30001')
         self.assertTrue(len(relay.state()), 16)
Esempio n. 9
0
 def test_009(self):
     """Test unable to parse content."""
     with httmock.HTTMock(mock_relay):
         with self.assertRaises(RuntimeError):
             devices.EthernetRelay(url_base='http://192.168.1.4/20000')
Esempio n. 10
0
 def test_008(self):
     """Test bad status code."""
     with httmock.HTTMock(mock_relay):
         with self.assertRaises(RuntimeError):
             devices.EthernetRelay(url_base='http://192.168.1.4/40000')
Esempio n. 11
0
 def test_000(self):
     """Test init with 30000."""
     with httmock.HTTMock(mock_relay):
         devices.EthernetRelay()