コード例 #1
0
def test_send_phone_verification_twilio_error():
    responses.add(
        responses.POST,
        'https://api.authy.com/protected/json/phones/verification/start',
        json={'error_code': '60060'},  # Account is suspended
        status=503)

    args = {
        'country_calling_code': '1',
        'phone': '1234',
        'method': 'sms',
        'locale': None
    }
    with pytest.raises(PhoneVerificationError) as service_err:
        VerificationService.send_phone_verification(**args)

    assert(str(service_err.value)) == \
        'Could not send verification code. Please try again shortly.'
コード例 #2
0
def test_send_phone_verification_cant_sms_landline():
    responses.add(
        responses.POST,
        'https://api.authy.com/protected/json/phones/verification/start',
        json={'error_code': '60082'},
        status=403)

    args = {
        'country_calling_code': '1',
        'phone': '1234',
        'method': 'sms',
        'locale': None
    }
    with pytest.raises(ValidationError) as validation_err:
        VerificationService.send_phone_verification(**args)

    assert (validation_err.value.messages[0]) == 'Cannot send SMS to landline.'
    assert (validation_err.value.field_names[0]) == 'phone'
コード例 #3
0
def test_send_phone_verification_invalid_number():
    responses.add(
        responses.POST,
        'https://api.authy.com/protected/json/phones/verification/start',
        json={'error_code': '60033'},
        status=400)

    args = {
        'country_calling_code': '1',
        'phone': '1234',
        'method': 'sms',
        'locale': None
    }
    with pytest.raises(ValidationError) as validation_err:
        VerificationService.send_phone_verification(**args)

    assert (validation_err.value.messages[0]) == 'Phone number is invalid.'
    assert (validation_err.value.field_names[0]) == 'phone'

    # Verify attestation not stored
    attestations = Attestation.query.all()
    assert (len(attestations)) == 0
コード例 #4
0
def test_send_phone_verification_success():
    responses.add(
        responses.POST,
        'https://api.authy.com/protected/json/phones/verification/start',
        status=200)

    args = {
        'country_calling_code': '1',
        'phone': '12341234',
        'method': 'sms',
        'locale': None
    }
    response = VerificationService.send_phone_verification(**args)
    assert isinstance(response, VerificationServiceResponse)
コード例 #5
0
def test_send_phone_verification_india_locale(mock_requests):
    responses.add(
        responses.POST,
        'https://api.authy.com/protected/json/phones/verification/start',
        status=200)

    args = {
        'country_calling_code': '91',
        'phone': '12341234',
        'method': 'sms',
        'locale': None
    }
    response = VerificationService.send_phone_verification(**args)

    assert len(mock_requests.post.call_args_list) == 1
    assert mock_requests.post.call_args_list[0][1]['params']['locale'] == 'en'
    assert isinstance(response, VerificationServiceResponse)