def test_lease_app_data(client): """Function to test the lease_app_data function""" customer = Customer(client, number='+254711892648') data = {"a": {"name": "update_after_lease"}} loop.run_until_complete(customer.update_app_data(data)) response = loop.run_until_complete(customer.lease_app_data()) assert response["a"]["name"] == "update_after_lease"
def test_delete_metadata(client): """Function to test the delete_metadata function""" customer = Customer(client, number='+254711892648') response = loop.run_until_complete(customer.delete_metadata(["hollow"])) assert all(elem in response for elem in ("customer_id", "status", "description")) response = loop.run_until_complete(customer.get_state()) assert "hollow" not in response["identity_state"]['metadata']
def test_delete_tags(client): """Function to test the delete_tags function""" customer = Customer(client, number='+254711892648') response = loop.run_until_complete(customer.delete_tags(["coffid"])) assert all(elem in response for elem in ("customer_id", "status", "description")) response = loop.run_until_complete(customer.get_state()) assert not list(value for elem, value in response["identity_state"]['tags'] if value in ("coffid"))
def test_update_metadata(client): """Function to test the update_metadata function""" customer = Customer(client, number='+254711892648') data = {"key": "test-key", "hollow": 1020, "payload": {"a": "Test"}} response = loop.run_until_complete(customer.update_metadata(data)) assert all(elem in response for elem in ("customer_id", "status", "description")) response = loop.run_until_complete(customer.get_state()) assert all(elem in response["identity_state"]["metadata"] for elem in ("key", "hollow", "payload"))
def test_delete_secondary_ids(client): """Function to test the delete_secondary_ids function""" customer = Customer(client, number='+254711892648') response = loop.run_until_complete( customer.delete_secondary_ids([{ "key": "huduma", "value": "808082" }])) assert all(elem in response for elem in ("customer_id", "status", "description")) response = loop.run_until_complete(customer.get_state()) assert not list( value for elem, value in response["identity_state"]['secondary_ids'] if value in ("huduma", "808082"))
def test_initiate_payment(client): """Function to test the initiate_payment function""" debit_from = { "customer": { "customer_number": { "number": "+254718769882", "provider": 'cellular', }, "channel_number": { "number": mpesa_paybill, "channel": 'cellular', }, } } credit_to = {"purse": {"purse_id": purse_id}} cash = {"currency_code": "KES", "amount": 10.55} response = loop.run_until_complete( client.initiate_payment(value=cash, debit_party=debit_from, credit_party=credit_to)) assert all(elem in response for elem in ( "status", "description", "transaction_id", "debit_customer_id", "credit_customer_id", ))
def test_cancel_customer_reminder_by_tag(client): """Function to test the cancel_customer_reminder_by_tag function""" tag = {"key": "some-key", "value": "some-value"} response = loop.run_until_complete( client.cancel_customer_reminder_by_tag(tag, "some-rem")) assert all(elem in response for elem in ("status", "description", "work_id"))
def test_update_messaging_consent(client): """Function to test the update_messaging_consent function""" customer = Customer(client, number='+254711892648') messaging_channel = {"number": sms_sender_id, "channel": "SMS"} response = loop.run_until_complete( customer.update_messaging_consent(messaging_channel)) assert all(elem in response for elem in ("customer_id", "status", "description"))
def test_send_message_by_tag(client): """Function to test the send_message_by_tag function""" tag = {"key": "some-key", "value": "some-value"} sms_channel = {"number": sms_short_code, "channel": 'sms'} message = {"body": {"text": "Hello From Python"}} response = loop.run_until_complete( client.send_message_by_tag(tag, sms_channel, message)) assert all(elem in response for elem in ("status", "description", "work_id"))
def test_receive_message(client): """Function to test the receive_message simulator function""" response = loop.run_until_complete( client.receive_message("254712345678", customer_number, "1234567", [{ "ussd": '*123#' }])) assert all(elem in response for elem in ("message", "status", "description"))
def test_reply_to_message(client): """Function to test the reply_to_message function""" customer = Customer(client, id='some-customer-id') message = {"body": {"text": "Python sms messaging reply test"}} response = loop.run_until_complete( customer.reply_to_message("some-message-id", message)) assert all(elem in response for elem in ("customer_id", "status", "description", "message_id", "session_id"))
def test_send_message(client): """Function to test the send_message function""" customer = Customer(client, number='+254711892648') messaging_channel = {"number": sms_sender_id, "channel": "sms"} message = {"body": {"text": "Python sms messaging test"}} response = loop.run_until_complete( customer.send_message(messaging_channel, message)) assert all(elem in response for elem in ("customer_id", "status", "description", "message_id", "session_id"))
def test_add_reminder(client): """Function to test the add_reminder function""" customer = Customer(client, number='+254711892648') reminder = { "key": "some-key", "remind_at": 50000, "payload": '{"a": 1, "c": "de"}' } response = loop.run_until_complete(customer.add_reminder(reminder)) assert all(elem in response for elem in ("customer_id", "status", "description"))
def test_get_state(client): """Function to test the get_state function""" customer = Customer(client, number='254711891648') response = loop.run_until_complete(customer.get_state()) assert all(elem in response for elem in ( "customer_id", "identity_state", "messaging_state", "payment_state", "activity_state", ))
def test_add_customer_reminder_by_tag(client): """Function to test the add_customer_reminder_by_tag function""" tag = {"key": "some-key", "value": "some-value"} reminder = { "key": "some-rem", "remind_at": time.time() + 60, "payload": "some str" } response = loop.run_until_complete( client.add_customer_reminder_by_tag(tag, reminder)) assert all(elem in response for elem in ("status", "description", "work_id"))
def test_update_secondary_ids(client): """Function to test the update_secondary_ids function""" customer = Customer(client, number='+254711892648') data = [ { "key": "passport", "value": "808083", "expires_at": 300000000 }, { "key": "huduma", "value": "808082", "expires_at": 500000000, }, ] response = loop.run_until_complete(customer.update_secondary_ids(data)) assert all(elem in response for elem in ("customer_id", "status", "description")) response = loop.run_until_complete(customer.get_state()) assert list(value for elem, value in response["identity_state"]['secondary_ids'] if value in ("passport", "huduma"))
def test_update_app_data(client): """Function to test the update_app_data function""" customer = Customer(client, number='+254711892648') data = { "key": "test-key", "hollow": 1020, "payload": { "a": "Test" }, "some_bytes": str.encode("test") } response = loop.run_until_complete(customer.update_app_data(data)) assert all(elem in response for elem in ("customer_id", "status", "description"))
def test_receive_payment(client): """Function to test the receive_payment simulator function""" response = loop.run_until_complete( client.receive_payment( "254712345678", adopted_customer, "test-transaction-id", { "amount": 100, "currency_code": "KES" }, "pending_confirmation", )) assert all(elem in response for elem in ("message", "status", "description"))
def test_update_activity(client): """Function to test the update_activity function""" customer = Customer(client, number='+254711892648') activity_channel = {"number": "some-test-number", "channel": "WEB"} activity = { "session_id": "some-session-id", "key": "some-key", "properties": { "ok": 1, "val": False }, } response = loop.run_until_complete( customer.update_activity(activity_channel, activity)) assert all(elem in response for elem in ("customer_id", "status", "description"))
def test_delete_app_data(client): """Function to test the delete_app_data function""" customer = Customer(client, number='+254711892648') response = loop.run_until_complete(customer.delete_app_data()) assert all(elem in response for elem in ("customer_id", "status", "description"))
def test_update_payment_status(client): """Function to test the update_payment_status simulator function""" response = loop.run_until_complete( client.update_payment_status("test-transaction-id", "failed")) assert all(elem in response for elem in ("message", "status", "description"))
def test_get_metadata(client): """Function to test the get_metadata function""" customer = Customer(client, number='254711891648') response = loop.run_until_complete(customer.get_metadata()) assert all(elem in response for elem in ("key", "hollow", "payload"))
def client(): """Create a connection to Elarian backend""" connection = Elarian(app_id=app_id, api_key=api_key, org_id=org_id) client = loop.run_until_complete(connection.connect()) yield client loop.run_until_complete(connection.disconnect())
def test_adopt_state(client): """Function to test the adopt_state function""" customer = Customer(client, id='some-customer-id') response = loop.run_until_complete(customer.adopt_state(adopted_customer)) assert all(elem in response for elem in ("customer_id", "status", "description"))
def test_cancel_reminder(client): """Function to test the cancel_reminder function""" customer = Customer(client, number='+254711892648') response = loop.run_until_complete(customer.cancel_reminder("some-key")) assert all(elem in response for elem in ("customer_id", "status", "description"))
def test_generate_auth_token(client): """Function to test the generate_auth_token function""" response = loop.run_until_complete(client.generate_auth_token()) assert all(elem in response for elem in ("token", "lifetime"))
def test_disconnect(client): """Function to test the disconnection function""" loop.run_until_complete(client.disconnect()) assert not client.is_connected()
def test_get_tags(client): """Function to test the get_tags function""" customer = Customer(client, number='254711891648') response = loop.run_until_complete(customer.get_tags()) assert list(value for elem, value in response if value in ("coffid", "test"))
def test_get_secondary_ids(client): """Function to test the get_secondary_ids function""" customer = Customer(client, number='254711891648') response = loop.run_until_complete(customer.get_secondary_ids()) assert list(value for elem, value in response if value in ("passport", "huduma"))