def test_pairing(self): code = devicelink.start_link("test1") key = "".join((devicelink.CACHE_PREFIX, code)) saved = cache.get(key) self.assertEqual({"name": "test1", "linked": False}, saved) status = devicelink.get_status(code) self.assertIsNone(status) devicelink.confirm_link(code) saved = cache.get(key) self.assertEqual({"name": "test1", "linked": True}, saved) status = devicelink.get_status(code) self.assertIsNotNone(status) apikey = models.ApiKey.objects.get(key=status) self.assertEqual("test1", apikey.device.name) # Entry has been deleted. self.assertRaises(devicelink.LinkExpiredException, devicelink.get_status, code) self.assertRaises(devicelink.LinkExpiredException, devicelink.get_status, "bogus-code")
def test_pairing(self): code = devicelink.start_link('test1') key = ''.join((devicelink.CACHE_PREFIX, code)) saved = cache.get(key) self.assertEqual({'name': 'test1', 'linked': False}, saved) status = devicelink.get_status(code) self.assertIsNone(status) devicelink.confirm_link(code) saved = cache.get(key) self.assertEqual({'name': 'test1', 'linked': True}, saved) status = devicelink.get_status(code) self.assertIsNotNone(status) apikey = models.ApiKey.objects.get(key=status) self.assertEqual('test1', apikey.device.name) # Entry has been deleted. self.assertRaises(devicelink.LinkExpiredException, devicelink.get_status, code) self.assertRaises(devicelink.LinkExpiredException, devicelink.get_status, 'bogus-code')
def link_device_new(request): name = request.POST.get('name', 'Unknown Device') code = devicelink.start_link(name) return {'status': 'ok', 'code': code, 'linked': False}
def link_device_new(request): name = request.POST.get("name", "Unknown Device") code = devicelink.start_link(name) return {"status": "ok", "code": code, "linked": False}