Exemple #1
0
    def test_token_refresh(self):
        marketo_leads_url = "".join(
            [
                "https://066-eov-335.mktorest.com/",
                "rest/v1/leads.json?",
                "access_token=test&filterType=email",
                "&[email protected]&fields=id",
            ]
        )

        marketo_leads_payload = {"result": [{"id": "test"}]}

        responses.add(responses.GET, marketo_leads_url, status=602)

        marketo_auth_url = "".join(
            [
                "https://066-eov-335.mktorest.com/",
                "identity/oauth/token?",
                "grant_type=client_credentials&client_id=123",
                "&client_secret=321",
            ]
        )

        marketo_auth_payload = {"access_token": "refreshed_token"}

        responses.add(
            responses.GET,
            marketo_auth_url,
            json=marketo_auth_payload,
            status=200,
        )

        responses.add(
            responses.GET,
            marketo_leads_url,
            json=marketo_leads_payload,
            status=200,
        )

        marketo = marketo_api.Marketo()
        marketo.token = "expired_token"
        marketo.get_user("*****@*****.**")

        self.assertEqual(marketo.token, "refreshed_token")
Exemple #2
0
    def test_auth(self):
        marketo_auth_url = "".join(
            [
                "https://066-eov-335.mktorest.com/",
                "identity/oauth/token?",
                "grant_type=client_credentials&client_id=123",
                "&client_secret=321",
            ]
        )

        marketo_auth_payload = {"access_token": "test"}

        responses.add(
            responses.GET,
            marketo_auth_url,
            json=marketo_auth_payload,
            status=200,
        )

        marketo_leads_url = "".join(
            [
                "https://066-eov-335.mktorest.com/",
                "rest/v1/leads.json?",
                "access_token=test&filterType=email",
                "&[email protected]&fields=id",
            ]
        )

        marketo_leads_payload = {"result": [{"id": "test"}]}

        responses.add(
            responses.GET,
            marketo_leads_url,
            json=marketo_leads_payload,
            status=200,
        )

        os.environ["MARKETO_CLIENT_ID"] = "fake_id"
        os.environ["MARKETO_CLIENT_SECRET"] = "fake_secret"
        marketo = marketo_api.Marketo()
        user = marketo.get_user("*****@*****.**")

        self.assertEqual(user, {"id": "test"})
Exemple #3
0
    def test_set_newsletter_subscription(self):
        marketo_set_subscription_url = "".join(
            [
                "https://066-eov-335.mktorest.com/",
                "rest/v1/leads.json?",
                "access_token=test&filterType=email",
                "&[email protected]&fields=id",
            ]
        )

        responses.add(
            responses.POST, marketo_set_subscription_url, json={}, status=200
        )

        marketo = marketo_api.Marketo()
        marketo.token = "test"
        response = marketo.set_newsletter_subscription("test", True)

        self.assertEqual(response, {})
    def test_get_newsletter_subscription(self):
        marketo_lead_url = "".join([
            "https://066-eov-335.mktorest.com/",
            "rest/v1/lead/test.json?",
            "access_token=test&fields=id,email,snapcraftnewsletter",
        ])

        marketo_lead_payload = {"result": [{"snapcraftnewsletter": True}]}

        responses.add(
            responses.GET,
            marketo_lead_url,
            json=marketo_lead_payload,
            status=200,
        )

        marketo = marketo_api.Marketo()
        marketo.token = "test"
        subscription = marketo.get_newsletter_subscription("test")

        self.assertEqual(subscription, {"snapcraftnewsletter": True})
    def test_get_user(self):
        marketo_leads_url = "".join([
            "https://066-eov-335.mktorest.com/",
            "rest/v1/leads.json?",
            "access_token=test&filterType=email",
            "&[email protected]&fields=id",
        ])

        marketo_leads_payload = {"result": [{"id": "test"}]}

        responses.add(
            responses.GET,
            marketo_leads_url,
            json=marketo_leads_payload,
            status=200,
        )

        marketo = marketo_api.Marketo()
        marketo.token = "test"
        user = marketo.get_user("*****@*****.**")

        self.assertEqual(user, {"id": "test"})
Exemple #6
0
from webapp import authentication
from webapp.helpers import api_publisher_session
from webapp.api.exceptions import (
    ApiCircuitBreaker,
    ApiError,
    ApiResponseError,
    ApiTimeoutError,
)
from webapp.decorators import login_required

account = flask.Blueprint("account",
                          __name__,
                          template_folder="/templates",
                          static_folder="/static")

marketo = marketo_api.Marketo()
publisher_api = SnapPublisher(api_publisher_session)


def refresh_redirect(path):
    try:
        macaroon_discharge = authentication.get_refreshed_discharge(
            flask.session["macaroon_discharge"])
    except ApiResponseError as api_response_error:
        if api_response_error.status_code == 401:
            return flask.redirect(flask.url_for("login.logout"))
        else:
            return flask.abort(502, str(api_response_error))
    except ApiError as api_error:
        return flask.abort(502, str(api_error))