def testTimeout(self): # the test will have to be re-writen if the scenario changes self.assertEqual(28, len(GOOD_SCENARIO)) for i in range(len(GOOD_SCENARIO) + 1): d = MyDongleWithTimeout(GOOD_SCENARIO, i) c = FitbitClient(d) if i < 1: self.assertFalse(c.disconnect(), i) continue self.assertTrue(c.disconnect()) if i < 4: self.assertFalse(c.getDongleInfo(), i) continue self.assertTrue(c.getDongleInfo()) ts = [t for t in c.discover(MyUUID())] if i < 6: self.assertEqual([], ts, i) continue self.assertEqual(1, len(ts), i) self.assertEqual(ts[0].id, [0, 0, 42, 0, 0, 0]) if i < 12: self.assertFalse(c.establishLink(ts[0]), i) continue self.assertTrue(c.establishLink(ts[0]), i) if i < 13: self.assertFalse(c.toggleTxPipe(True), i) continue self.assertTrue(c.toggleTxPipe(True)) if i < 15: self.assertFalse(c.initializeAirlink(ts[0])) continue self.assertTrue(c.initializeAirlink(ts[0])) if i < 18: self.assertEqual(None, c.getDump()) continue dump = c.getDump() self.assertFalse(dump is None) self.assertEqual(dump.data, [0x26, 2, 0, 0, 0, 0, 0]) if i < 22: self.assertFalse( c.uploadResponse((0x26, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))) continue self.assertTrue( c.uploadResponse((0x26, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))) if i < 23: self.assertFalse(c.terminateAirlink()) continue self.assertTrue(c.terminateAirlink()) if i < 24: self.assertFalse(c.toggleTxPipe(False)) continue self.assertTrue(c.toggleTxPipe(False)) if i < 28: self.assertFalse(c.ceaseLink()) continue self.assertTrue(c.ceaseLink()) self.assertEqual(len(GOOD_SCENARIO), i)
def testTimeout(self): # the test will have to be re-writen if the scenario changes self.assertEqual(28, len(GOOD_SCENARIO)) for i in range(len(GOOD_SCENARIO) + 1): d = MyDongleWithTimeout(GOOD_SCENARIO, i) c = FitbitClient(d) if i < 1: self.assertFalse(c.disconnect(), i) continue self.assertTrue(c.disconnect()) if i < 4: self.assertFalse(c.getDongleInfo(), i) continue self.assertTrue(c.getDongleInfo()) ts = [t for t in c.discover(MyUUID())] if i < 6: self.assertEqual([], ts, i) continue self.assertEqual(1, len(ts), i) self.assertEqual(ts[0].id, [0,0,42,0,0,0]) if i < 12: self.assertFalse(c.establishLink(ts[0]), i) continue self.assertTrue(c.establishLink(ts[0]), i) if i < 13: self.assertFalse(c.toggleTxPipe(True), i) continue self.assertTrue(c.toggleTxPipe(True)) if i < 15: self.assertFalse(c.initializeAirlink(ts[0])) continue self.assertTrue(c.initializeAirlink(ts[0])) if i < 18: self.assertEqual(None, c.getDump()) continue dump = c.getDump() self.assertFalse(dump is None) self.assertEqual(dump.data, [0x26, 2, 0,0,0,0,0]) if i < 22: self.assertFalse(c.uploadResponse((0x26, 2, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))) continue self.assertTrue(c.uploadResponse((0x26, 2, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))) if i < 23: self.assertFalse(c.terminateAirlink()) continue self.assertTrue(c.terminateAirlink()) if i < 24: self.assertFalse(c.toggleTxPipe(False)) continue self.assertTrue(c.toggleTxPipe(False)) if i < 28: self.assertFalse(c.ceaseLink()) continue self.assertTrue(c.ceaseLink()) self.assertEqual(len(GOOD_SCENARIO), i)
def testSurge(self): # This is not completely correct global FitbitClient FitbitClient = type('FitbitClient', (MyDongle, ), dict(FitbitClient.__dict__)) c = FitbitClient([(0xc0, 0x41, 0xd, 0x42, 0xa, 0, 0), (0x26, 2, 0, 0, 0, 0, 0), (0xc0, 0, 0xd, 0x93, 0x44, 7, 0)]) dump = c.getDump(0xd) self.assertTrue(dump.isValid())
def testPreSurge(self): global FitbitClient FitbitClient = type('FitbitClient', (MyDongle, ), dict(FitbitClient.__dict__)) c = FitbitClient([(0xc0, 0x41, 0xd), (0x26, 2, 0, 0, 0, 0, 0), (0xc0, 0, 0xd, 0x93, 0x44, 7, 0)]) dump = c.getDump(0xd) self.assertTrue(dump.isValid()) self.assertEqual(dump.data, bytearray([38, 2, 0, 0, 0, 0, 0])) self.assertEqual(dump.footer, bytearray([192, 0, 13, 147, 68, 7, 0]))
def testOk(self): d = MyDongle(GOOD_SCENARIO) c = FitbitClient(d) self.assertTrue(c.disconnect()) self.assertTrue(c.getDongleInfo()) ts = [t for t in c.discover(MyUUID())] self.assertEqual(1, len(ts)) self.assertEqual(ts[0].id, [0,0,42,0,0,0]) self.assertTrue(c.establishLink(ts[0])) self.assertTrue(c.toggleTxPipe(True)) self.assertTrue(c.initializeAirlink(ts[0])) dump = c.getDump() self.assertFalse(dump is None) self.assertEqual(dump.data, [0x26, 2, 0,0,0,0,0]) self.assertTrue(c.uploadResponse((0x26, 2, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))) self.assertTrue(c.terminateAirlink()) self.assertTrue(c.toggleTxPipe(False)) self.assertTrue(c.ceaseLink())
def testOk(self): d = MyDongle(GOOD_SCENARIO) c = FitbitClient(d) self.assertTrue(c.disconnect()) self.assertTrue(c.getDongleInfo()) ts = [t for t in c.discover(MyUUID())] self.assertEqual(1, len(ts)) self.assertEqual(ts[0].id, [0, 0, 42, 0, 0, 0]) self.assertTrue(c.establishLink(ts[0])) self.assertTrue(c.toggleTxPipe(True)) self.assertTrue(c.initializeAirlink(ts[0])) dump = c.getDump() self.assertFalse(dump is None) self.assertEqual(dump.data, [0x26, 2, 0, 0, 0, 0, 0]) self.assertTrue( c.uploadResponse((0x26, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))) self.assertTrue(c.terminateAirlink()) self.assertTrue(c.toggleTxPipe(False)) self.assertTrue(c.ceaseLink())
def testOk(self): global FitbitClient FitbitClient = type('FitbitClient', (MyDongle, ), dict(FitbitClient.__dict__)) c = FitbitClient(GOOD_SCENARIO) self.assertTrue(c.disconnect()) self.assertTrue(c.getDongleInfo()) ts = [t for t in c.discover(MyUUID())] self.assertEqual(1, len(ts)) self.assertEqual(ts[0].id, bytearray([0, 0, 42, 0, 0, 0])) self.assertTrue(c.establishLink(ts[0])) self.assertTrue(c.toggleTxPipe(True)) self.assertTrue(c.initializeAirlink(ts[0])) dump = c.getDump() self.assertFalse(dump is None) self.assertEqual(dump.data, bytearray([0x26, 2, 0, 0, 0, 0, 0])) self.assertTrue( c.uploadResponse((0x26, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))) self.assertTrue(c.terminateAirlink()) self.assertTrue(c.toggleTxPipe(False)) self.assertTrue(c.ceaseLink())