Beispiel #1
0
    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')
Beispiel #3
0
def link_device_new(request):
    name = request.POST.get('name', 'Unknown Device')
    code = devicelink.start_link(name)
    return {'status': 'ok', 'code': code, 'linked': False}
Beispiel #4
0
def link_device_new(request):
    name = request.POST.get("name", "Unknown Device")
    code = devicelink.start_link(name)
    return {"status": "ok", "code": code, "linked": False}
Beispiel #5
0
def link_device_new(request):
    name = request.POST.get("name", "Unknown Device")
    code = devicelink.start_link(name)
    return {"status": "ok", "code": code, "linked": False}
Beispiel #6
0
def link_device_new(request):
    name = request.POST.get('name', 'Unknown Device')
    code = devicelink.start_link(name)
    return {'status': 'ok', 'code': code, 'linked': False}