How to use the httpretty.HTTPretty.enable 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 karan / HackerNewsAPI / tests / test_story_get_comments.py View on Github external
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,
github duoduo369 / social_auth_demo / tests / actions / actions_tests.py View on Github external
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
github st4lk / django-rest-social-auth / tests / test_social.py View on Github external
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()
github gabrielfalcao / HTTPretty / tests / unit / test_httpretty.py View on Github external
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()
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 gabrielfalcao / HTTPretty / tests / unit / test_httpretty.py View on Github external
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
github duoduo369 / social_auth_demo / tests / oauth2.py View on Github external
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)
github gabrielfalcao / HTTPretty / tests / unit / test_httpretty.py View on Github external
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()
github quandl / quandl-python / test / helpers / my_httpretty.py View on Github external
def enable(cls):
        OriginalHTTPretty.enable()
        if pyopenssl_override:
            # Take out the pyopenssl version - use the default implementation
            extract_from_urllib3()
github urschrei / pyzotero / test / test_zotero.py View on Github external
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,
        )