How to use the httpretty.HTTPretty.GET function in httpretty

To help you get started, we’ve selected a few httpretty 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 python-social-auth / social-app-django / tests / actions / actions_tests.py View on Github external
'SOCIAL_AUTH_LOGIN_REDIRECT_URL': self.login_redirect_url,
            'SOCIAL_AUTH_AUTHENTICATION_BACKENDS': (
                'social.backends.github.GithubOAuth2',
            )
        })
        start_url = do_auth(self.strategy).url
        target_url = self.strategy.build_absolute_uri(
            '/complete/github/?code=foobar'
        )

        start_query = parse_qs(urlparse(start_url).query)
        location_url = target_url + ('?' in target_url and '&' or '?') + \
                       'state=' + start_query['state']
        location_query = parse_qs(urlparse(location_url).query)

        HTTPretty.register_uri(HTTPretty.GET, start_url, status=301,
                               location=location_url)
        HTTPretty.register_uri(HTTPretty.GET, location_url, status=200,
                               body='foobar')

        response = requests.get(start_url)
        expect(response.url).to.equal(location_url)
        expect(response.text).to.equal('foobar')

        HTTPretty.register_uri(HTTPretty.GET,
                               uri=self.backend.ACCESS_TOKEN_URL,
                               status=200,
                               body=self.access_token_body or '',
                               content_type='text/json')

        if self.user_data_url:
            HTTPretty.register_uri(HTTPretty.GET, self.user_data_url,
github boto / boto / tests / unit / cloudsearch / test_search.py View on Github external
def setUp(self):
        HTTPretty.enable()
        body = self.response

        if not isinstance(body, basestring):
            body = json.dumps(body)

        HTTPretty.register_uri(HTTPretty.GET, FULL_URL,
                               body=body,
                               content_type=self.content_type,
                               status=self.response_status)
github boto / boto / tests / unit / cloudsearch2 / test_search.py View on Github external
def setUp(self):
        HTTPretty.enable()
        body = self.response

        if not isinstance(body, basestring):
            body = json.dumps(body)

        HTTPretty.register_uri(HTTPretty.GET, FULL_URL,
                               body=body,
                               content_type=self.content_type,
                               status=self.response_status)
github duoduo369 / social_auth_demo / tests / oauth2.py View on Github external
location_url = target_url + ('?' in target_url and '&' or '?') + \
                           'redirect_state=' + start_query['redirect_state']
        else:
            location_url = target_url
        location_query = parse_qs(urlparse(location_url).query)

        HTTPretty.register_uri(HTTPretty.GET, start_url, status=301,
                               location=location_url)
        HTTPretty.register_uri(HTTPretty.GET, location_url, status=200,
                               body='foobar')

        response = requests.get(start_url)
        expect(response.url).to.equal(location_url)
        expect(response.text).to.equal('foobar')

        method = self.backend.ACCESS_TOKEN_METHOD == 'GET' and HTTPretty.GET \
                                                            or HTTPretty.POST
        HTTPretty.register_uri(method,
                               uri=self.backend.ACCESS_TOKEN_URL,
                               status=200,
                               body=self.access_token_body or '',
                               content_type=self.user_data_content_type)

        if self.user_data_url:
            HTTPretty.register_uri(HTTPretty.GET, self.user_data_url,
                                   body=self.user_data_body or '',
                                   content_type=self.user_data_content_type)
        self.strategy.set_request_data(location_query)
github duoduo369 / social_auth_demo / tests / actions / actions_tests.py View on Github external
'social.pipeline.social_auth.load_extra_data',
                'tests.pipeline.set_password',
                'social.pipeline.user.user_details'
            )
        })
        start_url = do_auth(self.strategy).url
        target_url = self.strategy.build_absolute_uri(
            '/complete/github/?code=foobar'
        )

        start_query = parse_qs(urlparse(start_url).query)
        location_url = target_url + ('?' in target_url and '&' or '?') + \
                       'state=' + start_query['state']
        location_query = parse_qs(urlparse(location_url).query)

        HTTPretty.register_uri(HTTPretty.GET, start_url, status=301,
                               location=location_url)
        HTTPretty.register_uri(HTTPretty.GET, location_url, status=200,
                               body='foobar')

        response = requests.get(start_url)
        expect(response.url).to.equal(location_url)
        expect(response.text).to.equal('foobar')

        HTTPretty.register_uri(HTTPretty.GET,
                               uri=self.backend.ACCESS_TOKEN_URL,
                               status=200,
                               body=self.access_token_body or '',
                               content_type='text/json')

        if self.user_data_url:
            HTTPretty.register_uri(HTTPretty.GET, self.user_data_url,
github rackerlabs / python-cloudbackup-sdk / tests / unit / client / test_backup_configuration.py View on Github external
def test_reload_works(self):
        url = '{0}/backup-configuration/{1}'.format(self.connection.host,
                                                    self.config.id)
        conf = mock_config.backup_configuration(agent_id=100)
        HTTPretty.register_uri(HTTPretty.GET, url, status=200,
                               body=json.dumps(conf))
        self.config.reload()
        self.assertEqual(self.config.agent_id, 100)
github rackerlabs / python-cloudbackup-sdk / tests / unit / client / test_command.py View on Github external
def test_wait_for_completion_works_poll_none(self):
        url = '{0}/{1}/{2}'.format(self.connection.host, self.cmd._type,
                                   self.cmd.id)
        HTTPretty.register_uri(HTTPretty.GET, url,
                               body=json.dumps(_mock_status_done()))
        with Timer() as timed:
            self.cmd.wait_for_completion(poll_interval=.005)
        self.assertLess(timed.elapsed, .010)
github gabrielfalcao / HTTPretty / tests / functional / test_urllib2.py View on Github external
def test_httpretty_should_allow_registering_regexes():
    "HTTPretty should allow registering regexes with urllib2"

    HTTPretty.register_uri(
        HTTPretty.GET,
        re.compile(r"https://api.yipit.com/v1/deal;brand=(?P\w+)"),
        body="Found brand",
    )

    request = urllib2.Request(
        "https://api.yipit.com/v1/deal;brand=GAP",
    )
    fd = urllib2.urlopen(request)
    got = fd.read()
    fd.close()

    got.should.equal(b"Found brand")
github gabrielfalcao / HTTPretty / tests / functional / test_decorator.py View on Github external
def test_decorated2(self):
        HTTPretty.register_uri(
            HTTPretty.GET, "http://localhost/",
            body="buble buble")

        fd = urllib2.urlopen('http://localhost/')
        got1 = fd.read()
        fd.close()

        expect(got1).to.equal(b'buble buble')
github tsileo / eve-mocker / eve_mocker.py View on Github external
HTTPretty.register_uri(HTTPretty.GET,
                               resource_regex,
                               body=self.generate_resource_response)
        HTTPretty.register_uri(HTTPretty.POST,
                               resource_regex,
                               body=self.generate_resource_response)

        HTTPretty.register_uri(HTTPretty.DELETE,
                               resource_regex,
                               body=self.generate_resource_response)

        # Register URIs for items
        item_regex = re.compile(urljoin(self.base_url, "([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)"))

        HTTPretty.register_uri(HTTPretty.GET,
                               item_regex,
                               body=self.generate_item_response)

        HTTPretty.register_uri(HTTPretty.PATCH,
                               item_regex,
                               body=self.generate_item_response)

        HTTPretty.register_uri(HTTPretty.DELETE,
                               item_regex,
                               body=self.generate_item_response)