コード例 #1
0
def test_sms_cost_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': 1
    })
    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(GetCostError):
            client.get_cost(to=os.environ['PHONE'],
                            message=SMSMessage(text='test'))
コード例 #2
0
def test_sms_cost(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': 1
    })
    with requests_mock.Mocker() as m:
        m.get(f.url,
              json={
                  'cnt': 1,
                  'cost': 1.44
              },
              headers={'Content-Type': 'application/json; charset=utf-8'})
        res = client.get_cost(to=os.environ['PHONE'],
                              message=SMSMessage(text='test'))
    assert res is not None
    assert isinstance(res, CostResponse)
    assert str(res) == "<CostResponse count=1 cost=1.44>"
    assert res.count == 1
    assert res.cost == 1.44