def test_message_sms(): message = SMSMessage(text='test') assert message is not None assert isinstance(message, SMSMessage) assert str(message) == "<SMSMessage text=test format=None>" assert message.text == 'test' assert message.format is None enc = message.encode() assert isinstance(enc, dict) assert 'mes' in enc assert enc['mes'] is not None assert enc['mes'] == 'test' assert enc['charset'] is not None assert enc['charset'] == 'utf-8' assert len(enc.keys()) == 2
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
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'))