How to use the marketorestpython.client.MarketoClient function in marketorestpython

To help you get started, we’ve selected a few marketorestpython examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jepcastelein / marketo-rest-python / tests / tst_client.py View on Github external
'client_secret': client.client_secret,
        }
    )

    assert client.token == access_token
    assert client.token_type == token_type
    assert client.expires_in == expires_in
    assert client.valid_until > time.time()
    assert client.scope == scope

    # credentials should still be valid
    client.authenticate()
    assert m_client_api_call.call_count == 2

    # test error handling
    client = MarketoClient('123-FDY-456', 'randomclientid', 'supersecret')
    m_client_api_call.return_value = {
        'error': 'invalid_client',
        'error_description': 'invalid secret'
    }
    with pytest.raises(Exception) as excinfo:
        client.authenticate()
        assert excinfo.value == 'invalid secret'
github jepcastelein / marketo-rest-python / tests / tst_client.py View on Github external
def client():
    return MarketoClient('123-FDY-456', 'randomclientid', 'supersecret')
github jepcastelein / marketo-rest-python / tests / tst_client.py View on Github external
def test_marketo_client(client):
    assert client.host == 'https://123-FDY-456.mktorest.com'
    assert client.client_id == 'randomclientid'
    assert client.client_secret == 'supersecret'
    assert client.API_CALLS_MADE == 0
    assert client.API_LIMIT is None

    client = MarketoClient('123-FDY-456', 'randomclientid', 'supersecret', 20)
    assert client.API_LIMIT == 20
github jepcastelein / marketo-rest-python / test_script.py View on Github external
logger = logging.getLogger()

try:
    # Travis testing
    MUNCHKIN_ID = os.environ['MUNCHKIN_ID']
    CLIENT_ID = os.environ['CLIENT_ID']
    CLIENT_SECRET = os.environ['CLIENT_SECRET']
except KeyError:
    # local testing
    with open('conf.json', 'r', encoding='utf-8') as f:
        creds = json.loads(f.read())
    MUNCHKIN_ID = creds['munchkin_id']
    CLIENT_ID = creds['client_id']
    CLIENT_SECRET = creds['client_secret']

mc = MarketoClient(munchkin_id=MUNCHKIN_ID, client_id=CLIENT_ID, client_secret=CLIENT_SECRET)

segmentation_id = 1001

lead_id_1 = None
lead_id_2 = None
file_id = None
list_folder_id = None
new_folder_id = None
list_id = None
files_folder_id = None
bulk_lead_export_id = None
list_name = uuid.uuid4()


def test_create_update_leads():
    random_number = randint(100, 999)
github jepcastelein / marketo-rest-python / tests / tst_client.py View on Github external
def test_api_call(m_http_lib, client):
    get_request_mock = Mock(return_value={
        'access_token': '1234', 'expires_in': 1000, 'scope': '1'
    })
    request_mock = Mock(get=get_request_mock)
    m_http_lib.return_value = request_mock
    args = (1, 2, 3)
    kwargs = {'a': 1, 'b': 2}
    client._api_call('get', '/test', *args, **kwargs)
    get_request_mock.assert_called_with(*(('/test',) + args), **kwargs)
    assert client.API_CALLS_MADE == 1

    limit = 4
    client = MarketoClient('123-FDY-456', 'randomclientid', 'supersecret', limit)
    with pytest.raises(Exception) as excinfo:
        for i in xrange(limit):
            client._api_call('get', '/test', *args, **kwargs)
        assert excinfo.value == {
            'message': 'API Calls exceeded the limit : %s' % limit,
            'code': '416'
        }
github jepcastelein / marketo-rest-python / test_script.py View on Github external
logger.info('found {} campaigns with maxReturn=10'.format(len(campaigns)))
        break
    assert len(first_campaigns) > 20 and len(second_campaigns) == 2 and len(third_campaigns) == 10


def test_activate_smart_campaign():
    campaign = mc.execute(method='activate_smart_campaign', id=1109)
    assert campaign[0]['id'] == 1109


def test_deactivate_smart_campaign():
    campaign = mc.execute(method='deactivate_smart_campaign', id=1109)
    assert campaign[0]['id'] == 1109


mc2 = MarketoClient(munchkin_id=MUNCHKIN_ID, client_id=CLIENT_ID, client_secret=CLIENT_SECRET, max_retry_time=30)


def test_max_retry_time():
    day = 1
    time_elapsed = 0
    for i in range(11):
        start_time = time.time()
        export_filter = {
          "createdAt": {
             "startAt": "2018-07-0{}".format(day),
             "endAt": "2018-07-0{}".format(day+1)
          },
          "activityTypeIds": [1]
        }
        job = mc2.execute(method='create_activities_export_job', filters=export_filter)
        job_id = job[0]['exportId']
github quay / quay / util / saas / useranalytics.py View on Github external
marketo_munchkin_id = app.config["MARKETO_MUNCHKIN_ID"]
            marketo_munchkin_private_key = app.config["MARKETO_MUNCHKIN_PRIVATE_KEY"]
            marketo_client_id = app.config["MARKETO_CLIENT_ID"]
            marketo_client_secret = app.config["MARKETO_CLIENT_SECRET"]
            marketo_lead_source = app.config["MARKETO_LEAD_SOURCE"]

            logger.debug(
                "Initializing marketo with keys: %s %s %s",
                marketo_munchkin_id,
                marketo_client_id,
                marketo_client_secret,
            )

            executor = ThreadPoolExecutor(max_workers=1)

        marketo_client = MarketoClient(
            marketo_munchkin_id, marketo_client_id, marketo_client_secret
        )
        client_wrapper = _MarketoAnalyticsClient(
            marketo_client, marketo_munchkin_private_key, marketo_lead_source
        )
        user_analytics = AsyncExecutorWrapper(client_wrapper, executor)

        # register extension with app
        app.extensions = getattr(app, "extensions", {})
        app.extensions["user_analytics"] = user_analytics
        return user_analytics

marketorestpython

Python Client for the Marketo REST API

MIT
Latest version published 1 year ago

Package Health Score

56 / 100
Full package analysis

Similar packages