Пример #1
0
def test_sms_simple(client: SMSC, params: dict):
    assert os.environ.get('PHONE')
    to = os.environ['PHONE']
    message_text = 'test'
    f = furl(URL).add(path="send.php").add(params).add({
        'phones': to,
        'mes': message_text,
        'cost': 2
    })
    with requests_mock.Mocker() as m:
        m.get(f.url,
              json={
                  'cnt': 1,
                  'id': 1,
                  'cost': 1.44
              },
              headers={'Content-Type': 'application/json; charset=utf-8'})
        res = client.send(to=os.environ['PHONE'],
                          message=SMSMessage(text='test'))
    assert res is not None
    assert isinstance(res, SendResponse)
    assert str(res) == "<SendResponse id=1 count=1 cost=1.44>"
    assert res.message_id == 1
    assert res.count == 1
    assert res.cost == 1.44
Пример #2
0
    def test_send_mobile_number(self, mock_request):
        resp_mock = MagicMock()
        resp_mock.json.return_value = {
            'data': {
                'id': 16829892,
                'sms': 1
            },
            'message': 'Mensaje enviado.',
            'code': 200
        }

        mock_request.get.return_value = resp_mock
        sms = SMSC(alias='test', apikey='test')
        resp = sms.send(area_code='011',
                        local_number='1531268974',
                        msg='testing')
        assert mock_request.get.called
        assert resp == {
            'data': {
                'id': 16829892,
                'sms': 1
            },
            'message': 'Mensaje enviado.',
            'code': 200
        }
Пример #3
0
def test_sms_simple_fail(client: SMSC, params: dict):
    assert os.environ.get('PHONE')
    to = os.environ['PHONE']
    message_text = 'test'
    f = furl(URL).add(path="send.php").add(params).add({
        'phones': to,
        'mes': message_text,
        'cost': 2
    })
    with requests_mock.Mocker() as m:
        m.get(f.url,
              json={},
              headers={'Content-Type': 'application/json; charset=utf-8'},
              status_code=404)
        with pytest.raises(SendError):
            client.send(to=os.environ['PHONE'],
                        message=SMSMessage(text='test'))
Пример #4
0
def test_viber(client: SMSC, params: dict):
    assert os.environ.get('PHONE')
    to = os.environ['PHONE']
    message_text = 'test'
    f = furl(URL).add(path="send.php").add(params).add({
        'phones': to,
        'mes': message_text,
        'cost': 2,
        'viber': 1
    })
    with requests_mock.Mocker() as m:
        m.get(f.url,
              json={
                  'error': "can't to deliver",
                  'id': 1,
                  'error_code': 8
              },
              headers={'Content-Type': 'application/json; charset=utf-8'})
        res = client.send(to=os.environ['PHONE'],
                          message=ViberMessage(text='test'))
    assert res is not None
    assert isinstance(res, SendResponse)
    assert res.error is not None
    assert str(res.error) == 'SMSCError(code=8, error="can\'t to deliver")'