How to use the responses.add 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 cuckoosandbox / cuckoo / tests / test_reporting.py View on Github external
def test_almost_empty_notification():
    set_cwd(tempfile.mkdtemp())
    conf = {
        "notification": {
            "enabled": True,
            "url": "http://localhost/notification",
        },
    }
    responses.add(responses.POST, "http://localhost/notification")
    task(1, {}, conf, {})
    assert len(responses.calls) == 1
    assert responses.calls[0].request.body == "data=null&task_id=1"

    responses.add(responses.POST, "http://localhost/notification")
    task(1, {}, conf, {
        "info": {
            "id": 1,
        },
    })
    assert len(responses.calls) == 2
    assert sorted(responses.calls[1].request.body.split("&")) == [
        "data=%7B%22id%22%3A+1%7D", "task_id=1"
    ]
github bear / python-twitter / tests / test_unicode.py View on Github external
def test_unicode_get_search(self):
        responses.add(responses.GET, DEFAULT_URL, body=b'{}', status=200)
        try:
            self.api.GetSearch(term="#ابشري_قابوس_جاء")
        except Exception as e:
            self.fail(e)
github pyconll / pyconll / tests / test_load.py View on Github external
def test_iter_from_network():
    """
    Test that a CoNLL file over a network can be iterated.
    """
    TEST_CONLL_URL = 'https://myconllrepo.com/english/train'
    with open(fixture_location('basic.conll')) as f:
        responses.add(responses.GET, TEST_CONLL_URL, body=f.read())

    expected_ids = ['fr-ud-dev_0000{}'.format(i) for i in range(1, 5)]
    actual_ids = [sent.id for sent in iter_from_url(TEST_CONLL_URL)]

    assert expected_ids == actual_ids
github razorpay / razorpay-python / tests / test_client_invoice.py View on Github external
def test_invoice_cancel(self):
        result = mock_file('fake_invoice_cancel')
        url = '{}/{}/cancel'.format(self.base_url, 'fake_invoice_id')
        responses.add(responses.POST, url, status=200, body=json.dumps(result),
                      match_querystring=True)
        self.assertEqual(self.client.invoice.cancel('fake_invoice_id'), result)
github AutomatedTester / Bugsy / tests / test_errors.py View on Github external
def test_an_exception_is_raised_when_we_hit_an_error():
    responses.add(responses.GET, rest_url('bug', 1017315),
                      body="It's all broken", status=500,
                      content_type='application/json', match_querystring=True)
    bugzilla = Bugsy()
    with pytest.raises(BugsyException) as e:
        bugzilla.get(1017315)
    assert str(e.value) == "Message: We received a 500 error with the following: It's all broken Code: None"
github canonical-web-and-design / snapcraft.io / tests / store / tests_github_badge.py View on Github external
def test_api_500_no_answer(self):
        responses.add(
            responses.Response(method="GET", url=self.api_url, status=500)
        )

        response = self.client.get(self.badge_url)

        assert len(responses.calls) == 1
        called = responses.calls[0]
        assert called.request.url == self.api_url

        assert response.status_code == 502
github abdullahselek / HerePy / tests / test_routing_api.py View on Github external
def test_pedastrianroute_route_short(self):
        with codecs.open('testdata/models/routing_pedestrian.json', mode='r', encoding='utf-8') as f:
            expectedResponse = f.read()
        responses.add(responses.GET, 'https://route.ls.hereapi.com/routing/7.2/calculateroute.json',
                  expectedResponse, status=200)
        response = self._api.pedastrian_route([11.0, 12.0], [22.0, 23.0], [herepy.RouteMode.pedestrian, herepy.RouteMode.fastest])
        expected_short_route = (
            "Mannheim Rd; W Belmont Ave; Cullerton St; E Fullerton Ave; "
            "La Porte Ave; E Palmer Ave; N Railroad Ave; W North Ave; "
            "E North Ave; E Third St"
        )
        self.assertEqual(response.route_short, expected_short_route)
github praekeltfoundation / seaworthy / seaworthy / tests-core / test_client.py View on Github external
def test_methods(self):
        """
        When the HTTP method-specific methods are called, the correct request
        method is used.
        """
        client = ContainerHttpClient('127.0.0.1', '45678')

        responses.add(responses.GET, 'http://127.0.0.1:45678/', status=200)
        responses.add(
            responses.OPTIONS, 'http://127.0.0.1:45678/foo', status=201)
        responses.add(responses.HEAD, 'http://127.0.0.1:45678/bar', status=403)
        responses.add(responses.POST, 'http://127.0.0.1:45678/baz', status=404)
        responses.add(responses.PUT, 'http://127.0.0.1:45678/test', status=418)
        responses.add(
            responses.PATCH, 'http://127.0.0.1:45678/a/b/c', status=501)
        responses.add(
            responses.DELETE, 'http://127.0.0.1:45678/d/e/f', status=503)

        get_response = client.get()
        options_response = client.options('/foo')
        head_response = client.head('/bar')
        post_response = client.post('/baz')
        put_response = client.put('/test')
        patch_response = client.patch('/a/b/c')
        delete_response = client.delete('/d/e/f')
github abdullahselek / HerePy / tests / test_publictransit_api.py View on Github external
def test_find_transit_coverage_in_cities_whensucceed(self):
        with io.open('testdata/models/public_transit_api_coverage_cities.json', 'r', encoding='utf-8') as f:
            expectedResponse = f.read()
        responses.add(responses.GET, 'https://transit.ls.hereapi.com/v3/coverage/city.json',
                  expectedResponse, status=200)
        response = self._api.find_transit_coverage_in_cities([42.3580, -71.0636], 'USA', 50000)
        self.assertTrue(response)
        self.assertIsInstance(response, herepy.PublicTransitResponse)
github fuzeman / plex.py / tests / test_metadata.py View on Github external
def test_episode():
    responses.add(
        responses.GET, 'http://mock:32400/library/metadata/31',
        body=read('fixtures/library/metadata/episode.xml'), status=200,
        content_type='application/xml'
    )

    container = Plex['library'].metadata(31)
    assert container is not None

    # Validate container
    items = list(container)
    assert len(items) == 1

    # - section
    assert container.section.id == '26'
    assert container.section.key == '26'
    assert container.section.uuid == '4k48a112-3464-45f5-fg56-2b0e8b917629'