How to use the responses.mock.assert_all_requests_are_fired function in responses

To help you get started, we’ve selected a few responses 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 canonical-web-and-design / snapcraft.io / tests / publisher / tests_account_details.py View on Github external
from unittest.mock import MagicMock, patch

import responses
from tests.publisher.endpoint_testing import BaseTestCases

# Make sure tests fail on stray responses.
responses.mock.assert_all_requests_are_fired = True


class AccountDetailsNotAuth(BaseTestCases.EndpointLoggedOut):
    def setUp(self):
        endpoint_url = "/account/details"

        super().setUp(snap_name=None, endpoint_url=endpoint_url)


class AccountDetailsPage(BaseTestCases.EndpointLoggedInErrorHandling):
    def setUp(self):
        api_url = "https://dashboard.snapcraft.io/dev/api/account"
        endpoint_url = "/account/details"

        super().setUp(
            snap_name=None,
github canonical-web-and-design / snapcraft.io / tests / publisher / endpoint_testing.py View on Github external
import requests

import pymacaroons
import responses
from flask_testing import TestCase
from webapp.app import create_app
from webapp.authentication import get_authorization_header

# Make sure tests fail on stray responses.
responses.mock.assert_all_requests_are_fired = True


class BaseTestCases:
    """
    This class has a set of test className that should be inherited by endpoint
    that have authentication.

    It is also used to avoid unittest to run this tests file.
    """

    class BaseAppTesting(TestCase):
        render_templates = False

        def setUp(self, snap_name, api_url, endpoint_url):
            self.snap_name = snap_name
            self.api_url = api_url
github canonical-web-and-design / snapcraft.io / tests / publisher / tests_account_snaps.py View on Github external
import unittest
from flask import json
import responses
from tests.publisher.endpoint_testing import BaseTestCases

# Make sure tests fail on stray responses.
responses.mock.assert_all_requests_are_fired = True


class AccountSnapsNotAuth(BaseTestCases.EndpointLoggedOut):
    def setUp(self):
        endpoint_url = "/snaps"

        super().setUp(snap_name=None, endpoint_url=endpoint_url)


class AccountSnapsPage(BaseTestCases.EndpointLoggedInErrorHandling):
    def setUp(self):
        api_url = "https://dashboard.snapcraft.io/dev/api/account"
        endpoint_url = "/snaps"

        super().setUp(
            snap_name=None,
github canonical-web-and-design / snapcraft.io / tests / publisher / tests_api_snaps.py View on Github external
from flask import json
import responses
from tests.publisher.endpoint_testing import BaseTestCases

# Make sure tests fail on stray responses.
responses.mock.assert_all_requests_are_fired = True


class AccountSnapsNotAuth(BaseTestCases.EndpointLoggedOut):
    def setUp(self):
        endpoint_url = "/snaps/api/snap-count"

        super().setUp(snap_name=None, endpoint_url=endpoint_url)


class AccountSnapsPage(BaseTestCases.EndpointLoggedInErrorHandling):
    def setUp(self):
        api_url = "https://dashboard.snapcraft.io/dev/api/account"
        endpoint_url = "/snaps/api/snap-count"

        super().setUp(
            snap_name=None,
github canonical-web-and-design / snapcraft.io / tests / publisher / tests_account_snaps.py View on Github external
import responses
from tests.publisher.endpoint_testing import BaseTestCases

# Make sure tests fail on stray responses.
responses.mock.assert_all_requests_are_fired = True


class AccountSnapsNotAuth(BaseTestCases.EndpointLoggedOut):
    def setUp(self):
        endpoint_url = "/snaps"

        super().setUp(snap_name=None, endpoint_url=endpoint_url)


class AccountSnapsPage(BaseTestCases.EndpointLoggedInErrorHandling):
    def setUp(self):
        api_url = "https://dashboard.snapcraft.io/dev/api/account"
        endpoint_url = "/snaps"

        super().setUp(
            snap_name=None,
github canonical-web-and-design / snapcraft.io / tests / blog / tests_index.py View on Github external
import requests
import responses
from flask_testing import TestCase
from webapp import api
from webapp.app import create_app

# Make sure tests fail on stray responses.
responses.mock.assert_all_requests_are_fired = True


class BlogPage(TestCase):

    render_templates = False

    def create_app(self):
        app = create_app(testing=True)
        app.config["BLOG_CATEGORIES_ENABLED"] = "true"
        app.secret_key = "secret_key"

        return app

    def setUp(self):
        api.blog.api_session = api.requests.Session()
        self.api_url = "https://admin.insights.ubuntu.com/wp-json/wp/v2"
github canonical-web-and-design / snapcraft.io / tests / publisher / tests_publisher.py View on Github external
import unittest

from requests.exceptions import ConnectionError

import pymacaroons
import responses
from flask_testing import TestCase
from tests.publisher.endpoint_testing import BaseTestCases
from webapp.app import create_app
from webapp.authentication import get_authorization_header

# Make sure tests fail on stray responses.
responses.mock.assert_all_requests_are_fired = True


class TestCache(BaseTestCases.EndpointLoggedInErrorHandling):
    def setUp(self):
        api_url = "https://dashboard.snapcraft.io/dev/api/account"
        endpoint_url = "/account/details"

        super().setUp(
            snap_name=None,
            endpoint_url=endpoint_url,
            method_endpoint="GET",
            api_url=api_url,
            method_api="GET",
        )

    @responses.activate
github canonical-web-and-design / snapcraft.io / tests / builder / tests_github_oauth.py View on Github external
import unittest

import responses
from flask_testing import TestCase

from webapp.app import create_app
from webapp.models.user import User

# Make sure tests fail on stray responses.
responses.mock.assert_all_requests_are_fired = True


class BuilderGithubAuth(TestCase):
    def create_app(self):
        app = create_app(testing=True)
        app.secret_key = "secret_key"
        return app

    @unittest.mock.patch("secrets.token_urlsafe")
    def test_authenticate(self, token_urlsafe):
        token_urlsafe.return_value = "test"
        response = self.client.get("/build/auth/authenticate")

        expected_location = "".join(
            [
                "https://github.com/login/oauth/authorize?",
github canonical-web-and-design / snapcraft.io / tests / api / test_marketo_api.py View on Github external
# Standard library
import os
import unittest

# Packages
import responses

# Local modules
import webapp.api.marketo as marketo_api


responses.mock.assert_all_requests_are_fired = True


class MarketoApi(unittest.TestCase):
    @responses.activate
    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"}
github canonical-web-and-design / snapcraft.io / tests / publisher / tests_account_logout.py View on Github external
import responses
from tests.publisher.endpoint_testing import BaseTestCases

# Make sure tests fail on stray responses.
responses.mock.assert_all_requests_are_fired = True


class LogoutRedirects(BaseTestCases.BaseAppTesting):
    def setUp(self):
        endpoint_url = "/logout"

        super().setUp(snap_name=None, endpoint_url=endpoint_url, api_url=None)

    @responses.activate
    def test_logout(self):
        response = self.client.get(self.endpoint_url)

        self.assertEqual(302, response.status_code)

        self.assertEqual(
            (