Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
httpretty.HTTPretty.enable()
httpretty.register_uri(httpretty.GET,
'https://news.ycombinator.com/',
body=get_content('index.html'))
httpretty.register_uri(httpretty.GET, '%s/%s' % (constants.BASE_URL,
'item?id=7324236'),
body=get_content('7324236.html'))
httpretty.register_uri(httpretty.GET,
'%s/%s' % (constants.BASE_URL,
'x?fnid=0MonpGsCkcGbA7rcbd2BAP'),
body=get_content('7324236-2.html'))
httpretty.register_uri(httpretty.GET,
'%s/%s' % (constants.BASE_URL,
'x?fnid=jyhCSQtM6ymFazFplS4Gpf'),
body=get_content('7324236-3.html'))
httpretty.register_uri(httpretty.GET,
'%s/%s' % (constants.BASE_URL,
def setUp(self):
HTTPretty.enable()
User.reset_cache()
TestUserSocialAuth.reset_cache()
TestNonce.reset_cache()
TestAssociation.reset_cache()
self.backend = module_member('social.backends.github.GithubOAuth2')
self.strategy = TestStrategy(self.backend, TestStorage)
self.user = None
def setUp(self):
HTTPretty.enable()
Backend = module_member(self.backend_path)
self.strategy = views.load_strategy()
self.backend = Backend(self.strategy, redirect_uri=self.complete_url)
self.name = self.backend.name.upper().replace('-', '_')
self.complete_url = self.strategy.build_absolute_uri(
self.raw_complete_url.format(self.backend.name)
)
backends = (self.backend_path, )
load_backends(backends, force_load=True)
user_data_body = json.loads(self.user_data_body)
self.email = 'example@mail.com'
user_data_body['email'] = self.email
self.user_data_body = json.dumps(user_data_body)
self.do_rest_login()
def test_fake_socket_passes_through_getpeername():
import socket
HTTPretty.enable()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.truesock = MagicMock()
expect(s.getpeername).called_with().should_not.throw(AttributeError)
s.truesock.getpeername.assert_called_with()
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 test_global_boolean_enabled():
HTTPretty.disable()
expect(HTTPretty.is_enabled()).to.be.falsy
HTTPretty.enable()
expect(HTTPretty.is_enabled()).to.be.truthy
HTTPretty.disable()
expect(HTTPretty.is_enabled()).to.be.falsy
def setUp(self):
HTTPretty.enable()
self.backend = module_member(self.backend_path)
self.complete_url = '/complete/{0}/?code=foobar'.format(
self.backend.name
)
self.strategy = TestStrategy(self.backend, TestStorage)
def test_socktype_bad_python_version_regression():
""" Some versions of python accidentally internally shadowed the SockType
variable, so it was no longer the socket object but and int Enum representing
the socket type e.g. AF_INET. Make sure we don't patch SockType in these cases
https://bugs.python.org/issue20386
"""
import socket
someObject = object()
with patch('socket.SocketType', someObject):
HTTPretty.enable()
expect(socket.SocketType).to.equal(someObject)
HTTPretty.disable()
def enable(cls):
OriginalHTTPretty.enable()
if pyopenssl_override:
# Take out the pyopenssl version - use the default implementation
extract_from_urllib3()
self.collection_doc = self.get_doc("collection_doc.json")
self.collection_tags = self.get_doc("collection_tags.json")
self.citation_doc = self.get_doc("citation_doc.xml")
# self.biblio_doc = self.get_doc('bib_doc.xml')
self.attachments_doc = self.get_doc("attachments_doc.json")
self.tags_doc = self.get_doc("tags_doc.json")
self.groups_doc = self.get_doc("groups_doc.json")
self.item_templt = self.get_doc("item_template.json")
self.item_types = self.get_doc("item_types.json")
self.item_fields = self.get_doc("item_fields.json")
self.keys_response = self.get_doc("keys_doc.txt")
self.creation_doc = self.get_doc("creation_doc.json")
self.item_file = self.get_doc("item_file.pdf")
# Add the item file to the mock response by default
HTTPretty.enable()
HTTPretty.register_uri(
HTTPretty.GET,
"https://api.zotero.org/users/myuserID/items",
content_type="application/json",
body=self.items_doc,
)