How to use the responses.GET 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 ellisonleao / pyshorteners / tests / test_owly.py View on Github external
def test_owly_expand_method():
    # mock responses
    params = urlencode({
        'apiKey': 'TEST_KEY',
        'shortUrl': shorten,
    })
    body = json.dumps({
        'results': {'longUrl': expanded}
    })
    mock_url = f'{owly.api_url}expand?{params}'
    responses.add(responses.GET, mock_url, body=body,
                  match_querystring=True)

    expanded_result = owly.expand(shorten)

    assert expanded_result == expanded
github canonical-web-and-design / snapcraft.io / tests / publisher / tests_publisher.py View on Github external
def test_cache_disabled(self):
        responses.add(responses.GET, self.api_url, json={}, status=200)

        response = self.client.get(self.endpoint_url)
        self.assertEqual(200, response.status_code)

        responses.replace(responses.GET, self.api_url, body=ConnectionError())
        response = self.client.get(self.endpoint_url)
        self.assertEqual(response.status_code, 502)
github Cloud-CV / evalai-cli / tests / test_submissions.py View on Github external
# To get Challenge Phase Details using slug
        url = "{}{}"
        responses.add(
            responses.GET,
            url.format(
                API_HOST_URL, URLS.phase_details_using_slug.value
            ).format("philip-phase-2019"),
            json=json.loads(challenge_response.challenge_phase_details_slug),
            status=200,
        )

        # To get Challenge Details
        url = "{}{}"
        responses.add(
            responses.GET,
            url.format(API_HOST_URL, URLS.challenge_details.value).format(
                "10"
            ),
            json=json.loads(challenge_response.challenge_details),
            status=200,
        )

        responses.add_passthru("http+docker://localhost/")
github mapbox / mapbox-sdk-py / tests / test_directions.py View on Github external
def test_direction_bearings_none():
    responses.add(
        responses.GET,
        'https://api.mapbox.com/directions/v5/mapbox/driving/'
        '-87.337875%2C36.539157%3B-88.247681%2C36.922175.json?access_token=pk.test'
        '&radiuses=10%3B20&bearings=%3B315%2C90',
        match_querystring=True,
        body="not important, only testing URI templating", status=200,
        content_type='application/json')

    res = mapbox.Directions(access_token='pk.test').directions(
        points,
        waypoint_snapping=[10, (20, 315, 90)])
    assert res.status_code == 200
github InQuest / ThreatIngestor / tests / test_sources_github.py View on Github external
def test_run_returns_saved_state_tasks(self, mock_datetime):
        responses.add(responses.GET, threatingestor.sources.github.SEARCH_URL,
                body=API_RESPONSE_DATA)
        mock_datetime.datetime.utcnow.return_value = datetime.datetime(2018, 4, 30, 17, 5, 13, 194840)
        mock_datetime.datetime.side_effect = lambda *args, **kw: datetime.datetime(*args, **kw)

        saved_state, artifact_list = self.github.run(None)
        self.assertIn('Manual Task: GitHub dtrupenn/Tetris', [str(x) for x in artifact_list])
        self.assertEqual(len(artifact_list), 1)
        self.assertEqual(saved_state, '2018-04-30T17:05:13Z')
github mozilla / treeherder / tests / test_utils.py View on Github external
def add_log_response(filename):
    """
    Set up responses for a local gzipped log and return the url for it.
    """
    log_path = SampleData().get_log_path(filename)
    log_url = "http://my-log.mozilla.org/{}".format(filename)

    with open(log_path, 'rb') as log_file:
        content = log_file.read()
        responses.add(
            responses.GET,
            log_url,
            body=content,
            adding_headers={
                'Content-Encoding': 'gzip',
                'Content-Length': str(len(content)),
            }
        )
    return log_url
github ellisonleao / pyshorteners / tests / test_dagd.py View on Github external
def test_dagd_short_method_bad_response():
    # mock responses
    mock_url = f'{dagd.api_url}shorten?url={expanded}'
    responses.add(responses.GET, mock_url, body=shorten, status=400,
                  match_querystring=True)

    with pytest.raises(ShorteningErrorException):
        dagd.short(expanded)
github tonyseek / flask-docker / tests / test_factory.py View on Github external
def test_versioned(app):
    responses.add(
        responses.GET, 'http://docker-testing:2375/v1.11/info',
        body='{"message": "Yo! Gotcha."}', status=200,
        content_type='application/json')
    app.config['DOCKER_URL'] = 'http://docker-testing:2375'
    app.config['DOCKER_VERSION'] = '1.11'

    assert docker.client.info() == {'message': 'Yo! Gotcha.'}
github pyapi-gitlab / pyapi-gitlab / gitlab_tests / test_v90 / __init__.py View on Github external
def test_get_with_200(self):
        responses.add(
            responses.GET,
            self.gitlab.api_url + '/users',
            json=get_users,
            status=200,
            content_type='application/json')

        self.assertEqual(get_users, self.gitlab.get('/users'))
github enricobacis / lyricwikia / tests / test_get_lyrics.py View on Github external
def test_returnLyricsNotFound():
    responses.add(responses.GET,
                  'https://lyrics.wikia.com/wiki/Lyricwikia:Lyricwikia',
                  body='')

    with pytest.raises(LyricsNotFound):
        get_lyrics('Lyricwikia', 'Lyricwikia')
    assert len(responses.calls) == 1