Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'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,
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)
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)
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)
'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,
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)
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)
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")
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')
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)