def test_verify_verified(): text = "VERIFIED" responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, text), ) r = api.send_pin(dict(to="+37212345678")) assert r.error_code is None assert r.error_msg == "" assert r.status == "VERIFIED" assert r.get_raw_text() == text assert r.get_verification_id() == "" assert r.is_verified() v_id = "qwerty" r = api.verify_pin(dict(pin="1234", verification_id=v_id)) assert r.error_code is None assert r.error_msg == "" assert r.status == "VERIFIED" assert r.get_raw_text() == text assert r.get_verification_id() == "" assert not r.is_throttled() assert not r.is_expired() assert not r.is_invalid() assert r.is_verified()
def test_invalid_credentials(): responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, "ERROR 101"), ) r = api.get_balance() assert r.status == "ERROR" assert r.error_code == 101 assert r.error_msg
def test_invalid_credentials(): responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, "ERROR 101"), ) r = api.send_pin({}, validate=False) assert r.status == "ERROR" assert r.error_code == 101 assert r.error_msg
def test_dlr_failed(): text = "FAILED 102" responses.add_callback( responses.GET, utils.TEST_DLR_ANY_URL, callback=utils.mock_response(200, text), ) r = api.get_dlr_response("smsid") assert isinstance(r, Response) assert isinstance(r, delivery.DeliveryResponse) assert r.get_result() == "" assert not r.is_ok()
def test_send_no_validate(): sms_id = "sms-001" text = "OK %s" % sms_id responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, text), ) api = sms.SmsAPI(urls=utils.TEST_URL) api.send({}, validate=False) # OK if no exception was raised assert True
def test_server_failure(): value = "FAILED 209" responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, value), ) r = api.get_balance() assert r.error_code == 209 assert r.status == "FAILED" assert r.error_msg assert r.get_raw_text() == value
def test_dlr(): status = "DELIVERED" text = "OK %s" % status responses.add_callback( responses.GET, utils.TEST_DLR_ANY_URL, callback=utils.mock_response(200, text), ) r = api.get_dlr_response("smsid") assert isinstance(r, Response) assert isinstance(r, delivery.DeliveryResponse) assert r.get_raw_text() == text assert r.get_result() == "DELIVERED"
def test_invalid_credentials(): responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, "ERROR 101"), ) api = sms.SmsAPI(urls=utils.TEST_URL) r = api.send(mk_sms_data(), validate=False) assert isinstance(r, Response) assert isinstance(r, sms.SmsResponse) assert r.status == "ERROR" assert r.error_code == 101 assert r.error_msg
def test_get_coutry_prices(): responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, fake_response), ) api = pricing.PricingAPI(urls=utils.TEST_URL) r = api.get_country_prices("EE") assert isinstance(r, Response) assert isinstance(r, pricing.PricingResponse) assert r.is_ok() assert (json.loads(r.get_result()).get("networks")[1]["name"] == "Elisa") r = api.get_country_prices("EE", format="xml") # only test if ok - only json is mocked assert r.is_ok()
def test_send(): sms_id = "sms-001" text = "OK %s" % sms_id responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, text), ) api = sms.SmsAPI(urls=utils.TEST_URL) r = api.send(mk_sms_data()) assert r.error_code is None assert r.error_msg == "" assert r.status == "OK" assert r.get_raw_text() == text assert r.get_sms_id() == sms_id
def test_get_balance(): value = 123.45678 text = "OK %s" % value responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, text), ) r = api.get_balance() assert isinstance(r, Response) assert isinstance(r, credit.CreditResponse) assert r.error_code is None assert r.error_msg == "" assert r.status == "OK" assert r.get_raw_text() == text assert r.get_result() == str(value)
def test_cancel(): text = "OK DELETED" responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, text), ) api = sms.SmsAPI(urls=utils.TEST_URL) r = api.cancel("sms-id") assert isinstance(r, Response) assert isinstance(r, sms.CancelSmsResponse) assert r.error_code is None assert r.error_msg == "" assert r.status == "OK" assert r.get_raw_text() == text assert r.get_result() == text
def test_server_failure(): text = "FAILED 209" responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, text), ) r = api.send_pin(dict(to="+37212345678")) assert isinstance(r, Response) assert isinstance(r, number_verification.NumberVerificationResponse) assert r.error_code == 209 assert r.error_msg assert r.status == "FAILED" assert r.get_raw_text() == text assert r.get_result() == text assert r.get_verification_id() == "" assert not r.is_verified()
def test_verify_pin_error(): text = "ERROR 110" responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, text), ) v_id = "qwerty" r = api.verify_pin(dict(pin="1234", verification_id=v_id)) assert r.error_code == 110 assert r.error_msg assert r.status == "ERROR" assert r.get_raw_text() == text assert r.get_verification_id() == "" assert not r.is_verified() assert not r.is_invalid() assert not r.is_expired() assert not r.is_throttled()
def test_get_pricelist(): fake = "test,test,test" responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, fake, headers={ "Content-type": "text/csv;charset=UTF-8" }), ) (fh, path) = tempfile.mkstemp() api = pricing.PricingAPI(urls=utils.TEST_URL) r = api.get_pricelist(path) assert isinstance(r, Response) assert isinstance(r, pricing.PricingResponse) assert r.is_ok() assert len(r.get_result()) # test the contents of the saved file with open(path, "r") as fh: contents = fh.read().strip() assert contents == fake
def test_send_pin(): verification_id = "vid00000001111111" text = "OK %s" % verification_id responses.add_callback( responses.GET, utils.TEST_ANY_URL, callback=utils.mock_response(200, text), ) r = api.send_pin(dict(to="+37212345678")) assert isinstance(r, Response) assert isinstance(r, number_verification.NumberVerificationResponse) assert r.error_code is None assert r.error_msg == "" assert r.status == "OK" assert r.get_raw_text() == text assert r.get_result() == text assert r.get_verification_id() == verification_id assert not r.is_verified()