Ejemplo n.º 1
0
def rfid_pair(request):
    if request.method != 'POST':
        return http.HttpResponseBadRequest('Request not POST')

    form = forms.RfidCardPairForm(request.POST)
    if not form.is_valid():
        return http.HttpResponseBadRequest('Form error')

    try:
        rfid_api.card_pair(request.user.id, form.cleaned_data['card_id'])
    except ValueError:
        return http.HttpResponseBadRequest('Card already paired')

    try:
        messages.add_message(request, messages.SUCCESS, 'Paired card!')
    except MessageFailure:  # pragma: no cover
        pass

    return shortcuts.redirect('/')
Ejemplo n.º 2
0
def test_card_pair(card_user, random_card):
    c = api.card_pair(card_user.id, random_card.id)
    assert isinstance(c, models.RFIDCard)
    assert c.id == random_card.id
    assert c.user.id == card_user.id
Ejemplo n.º 3
0
def test_card_pair_already_paired(card_user, paired_card):
    with pytest.raises(ValueError):
        api.card_pair(card_user.id, paired_card.id)
Ejemplo n.º 4
0
def test_card_pair_no_user(random_card):
    """Test to pair with a nonexistent user id"""

    with pytest.raises(get_user_model().DoesNotExist):
        api.card_pair(1, random_card.id)
Ejemplo n.º 5
0
def test_card_pair_no_card():
    """Test to pair with a nonexistent card id"""
    with pytest.raises(models.RFIDCard.DoesNotExist):
        api.card_pair(1, 1)