How to use the responses.mock 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 getsentry / responses / test_responses.py View on Github external
def run():
        # setup redirect
        with responses.mock:
            responses.add_callback(responses.GET, url_re, request_callback)
            resp_no_redirects = requests.get(redirecting_url, allow_redirects=False)
            assert resp_no_redirects.status_code == 301
            assert len(responses.calls) == 1  # 1x300
            assert responses.calls[0][1].status_code == 301
        assert_reset()

        with responses.mock:
            responses.add_callback(responses.GET, url_re, request_callback)
            resp_yes_redirects = requests.get(redirecting_url, allow_redirects=True)
            assert len(responses.calls) == 3  # 2x300 + 1x200
            assert len(resp_yes_redirects.history) == 2
            assert resp_yes_redirects.status_code == 200
            assert final_url == resp_yes_redirects.url
            status_codes = [call[1].status_code for call in responses.calls]
            assert status_codes == [301, 301, 200]
        assert_reset()
github xzkostyan / clickhouse-sqlalchemy / tests / drivers / http / test_transport.py View on Github external
def test_parse_func_count(self):
        mock.add(
            mock.POST, self.url, status=200,
            body='count_1\nUInt64\n42\n'
        )

        table = Table(
            't1', self.metadata(),
            Column('x', types.Int32, primary_key=True)
        )

        rv = self.session.query(func.count()).select_from(table).scalar()
        self.assertEqual(rv, 42)
github canonical-web-and-design / snapcraft.io / tests / tests_basic.py View on Github external
#! /usr/bin/env python3

import unittest

import responses
import urllib

import webapp.app as app

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


class WebAppTestCase(unittest.TestCase):
    def setUp(self):
        self.app = app.app.test_client()
        self.app.testing = True

    # Static pages
    # ==

    def test_homepage(self):
        self._check_basic_page('/')

    def test_storefront(self):
        response = self._check_basic_page('/store')
        assert 'type="search"' in str(response.data)
github ralphbean / bugwarrior / tests / test_gerrit.py View on Github external
def setUp(self):
        super(TestGerritIssue, self).setUp()

        responses.add(
            responses.HEAD,
            self.SERVICE_CONFIG['gerrit.base_uri'] + '/a/',
            headers={'www-authenticate': 'digest'})
        with responses.mock:
            self.service = self.get_mock_service(GerritService)
github Xion / gisht.py / tests / test_github.py View on Github external
def deactivate_responses(self):
        responses.mock.__exit__()