Exemple #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')
Exemple #3
0
def link_device(request):
    context = RequestContext(request)
    form = forms.LinkDeviceForm()
    if request.method == 'POST':
        form = forms.LinkDeviceForm(request.POST)
        if form.is_valid():
            code = form.cleaned_data.get('code')
            try:
                status = devicelink.confirm_link(code)
                name = status.get('name', 'New device')
                messages.success(request, '{} linked!'.format(name))
            except devicelink.LinkExpiredException:
                messages.error(request, 'Code incorrect or expired.')
            return redirect('kegadmin-link-device')
    context['form'] = form
    return render_to_response('kegadmin/link_device.html', context_instance=context)
Exemple #4
0
def link_device(request):
    context = {}
    form = forms.LinkDeviceForm()
    if request.method == 'POST':
        form = forms.LinkDeviceForm(request.POST)
        if form.is_valid():
            code = form.cleaned_data.get('code')
            try:
                status = devicelink.confirm_link(code)
                name = status.get('name', 'New device')
                messages.success(request, '{} linked!'.format(name))
            except devicelink.LinkExpiredException:
                messages.error(request, 'Code incorrect or expired.')
            return redirect('kegadmin-link-device')
    context['form'] = form
    return render(request, 'kegadmin/link_device.html', context=context)
Exemple #5
0
def link_device(request):
    context = {}
    form = forms.LinkDeviceForm()
    if request.method == "POST":
        form = forms.LinkDeviceForm(request.POST)
        if form.is_valid():
            code = form.cleaned_data.get("code")
            try:
                status = devicelink.confirm_link(code)
                name = status.get("name", "New device")
                messages.success(request, "{} linked!".format(name))
            except devicelink.LinkExpiredException:
                messages.error(request, "Code incorrect or expired.")
            return redirect("kegadmin-link-device")
    context["form"] = form
    return render(request, "kegadmin/link_device.html", context=context)
Exemple #6
0
def link_device(request):
    context = {}
    form = forms.LinkDeviceForm()
    if request.method == "POST":
        form = forms.LinkDeviceForm(request.POST)
        if form.is_valid():
            code = form.cleaned_data.get("code")
            result = re.match("^([A-Z1-9]{3})-?([A-Z1-9]{3})$", code.upper())
            if not result:
                messages.error('Link code is not in the form of "XXX-XXX"')
            code = "{}-{}".format(result.group(1), result.group(2))
            try:
                status = devicelink.confirm_link(code)
                name = status.get("name", "New device")
                messages.success(request, "{} linked!".format(name))
            except devicelink.LinkExpiredException:
                messages.error(request, "Code incorrect or expired.")
            return redirect("kegadmin-link-device")
    context["form"] = form
    return render(request, "kegadmin/link_device.html", context=context)