예제 #1
0
def test_invalid_msisdn():
    with pytest.raises(api.APIError) as exception_info:
        api.Recipient('')
    assert exception_info.value.code == 41  # '41': 'Invalid MSISDN'
    assert hasattr(exception_info.value, 'description')
    with pytest.raises(api.APIError) as exception_info:
        api.Recipient('380968890000@')
    assert exception_info.value.code == 41  # '41': 'Invalid MSISDN'
예제 #2
0
def test_get_status_by_task_id(requester):
    requester.message = api.SMSMessage(body='test message text')
    requester.clear_recipients()
    requester.add_recipient(api.Recipient(380967770004))
    requester.add_recipient(api.Recipient(380967770005))
    response_send = requester.send()
    assert response_send
    response_status = requester.get_status()
    assert requester.message.get('status') is not None and response_status
예제 #3
0
def test_send_mul(requester):
    message = api.ViberMessage(
        text='test message text to many recipients',
        to=[api.Recipient(380960000001),
            api.Recipient(380960000002)])

    requester.clear_messages()
    assert not requester.messages

    requester.add_message(message)
    responds = requester.send()
    for respond in responds['result']:
        for attribute in RESPOND_ATTRIBUTES:
            assert respond.get(attribute) is not None
예제 #4
0
def test_alt_route(requester):
    requester.clear_messages()
    message = api.ViberMessage(
        text='test message text to many recipients',
        to=[api.Recipient(380960000001),
            api.Recipient(380960000002)],
        alt_route={
            'originator': 'BSG',
            'text': 'SMS message will be received if you not a VIBER user.'
        })
    requester.add_message(message)
    responds = requester.send()
    for respond in responds['result']:
        for attribute in RESPOND_ATTRIBUTES:
            assert respond.get(attribute) is not None
예제 #5
0
def test_get_status_from_internal_message(requester):
    requester.message = api.SMSMessage(body='test message text')
    response = requester.send(recipients=api.Recipient(380967770002))
    assert response.get('result')
    assert response['result'].get('id')
    response['status'] = requester.get_status()
    assert response.get('status') is not None and response.get('status')
예제 #6
0
def test_get_status(requester):
    message = api.ViberMessage(
        text='test message text to many recipients',
        to=[api.Recipient(380960000001),
            api.Recipient(380960000002)])

    requester.clear_messages()
    assert not requester.messages

    requester.add_message(message)
    response = requester.send()

    status_by_id = requester.get_status(response['result'][0]['id'])
    assert status_by_id
    status_by_ref = requester.get_status(response['result'][0]['reference'])
    assert status_by_ref

    # noinspection PyTypeChecker
    status_by_list = requester.get_status(list())
    assert not status_by_list
예제 #7
0
def test_add_recipient():
    message = api.ViberMessage(text='test message text')

    assert len(message) == 2

    message.add_recipient({'msisdn': '380445556677'})
    message.add_recipient(380445556678)
    message.add_recipient(api.Recipient(380445556679))

    attributes = ['msisdn', 'reference']
    for recipient in message['to']:
        for attribute in attributes:
            assert recipient.get(attribute) is not None
예제 #8
0
파일: sms.py 프로젝트: JaVood/pasta_family
def main():
    from examples.settings import API_KEY

    try:
        client = api.SMSAPI(config={'api_key': API_KEY})
        prices = client.get_prices()
        print('SMS Prices (first 5 elements from {}): \n{}'.format(
            len(prices), pprint.pformat(prices[0:5], indent=4)))

        recipient = api.Recipient(380967000000)
        print('Created recipient: \n{}'.format(pprint.pformat(recipient)))
        result = client.send(message=api.SMSMessage('hello from bsg.world'),
                             recipients=recipient)
        print('Current SMS send API result: \n{}'.format(
            pprint.pformat(result, indent=4)))
        status = client.get_status(result['result']['reference'])
        print('Current SMS status result: \n{}\n'.format(
            pprint.pformat(status, indent=4)))

        recipient0 = api.Recipient(380967000001)
        recipient1 = api.Recipient(380967000002)
        print('Created another one recipients: \n{}'.format(
            pprint.pformat([recipient0, recipient1])))
        results = client.send(message=api.SMSMessage('hello from bsg.world'),
                              recipients=[recipient0, recipient1])
        for result in results['result']:
            print('Current SMS send API result for reference {}: \n{}'.format(
                result['reference'], pprint.pformat(result, indent=4)))
            status = client.get_status(result['reference'])
            print('Current SMS status result for reference {}: \n{}'.format(
                result['reference'], pprint.pformat(status, indent=4)))
    except api.APIError as exc:
        print('Error on SMS request processing: {}'.format(
            pprint.pformat(exc, indent=4)),
              file=sys.stderr)
        exit(1)
예제 #9
0
def test_get_status_from_internal_message_without_send(requester):
    requester.message = api.SMSMessage(body='test message text')
    requester.clear_recipients()
    requester.add_recipient(api.Recipient(380967770003))
    response = requester.get_status()
    assert requester.message.get('status') is not None and response
예제 #10
0
def test_get_status_one(requester):
    response = requester.send(message=api.SMSMessage(body='test message text'), recipients=api.Recipient(380967770002))
    assert response.get('result')
    assert response['result'].get('id') is not None
    response['status'] = requester.get_status(response['result']['id'])
    assert response.get('status') is not None
예제 #11
0
def test_send_mul(requester):
    responds = requester.send(message=api.SMSMessage(body='test message text'), recipients=[api.Recipient(380967770000), api.Recipient(380967770001)])
    assert responds.get('result')
    for respond in responds['result']:
        for attribute in RESPOND_ATTRIBUTES:
            assert respond.get(attribute) is not None
예제 #12
0
def test_send_one(requester):
    respond = requester.send(message=api.SMSMessage(body='test message text'), recipients=api.Recipient(380967770002))
    assert respond.get('result')
    for attribute in RESPOND_ATTRIBUTES:
        assert respond['result'].get(attribute) is not None
예제 #13
0
def test_send_one(requester):
    message = api.ViberMessage(text='test message text to one recipient',
                               to=[api.Recipient(380960000000)])
    respond = requester.send(message=message, sender='BSG')
    for attribute in RESPOND_ATTRIBUTES:
        assert respond['result'][0].get(attribute) is not None