How to use the httpretty.activate 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 ImperialCollegeLondon / django-drf-filepond / tests / test_fetch_view.py View on Github external
    @httpretty.activate
    def test_fetch_head_connection_error(self):
        test_url = 'http://localhost/test.txt'

        def connection_error_callback(request, uri, response_headers):
            raise requests.exceptions.ConnectionError('Connection error.')

        register_uri(method=httpretty.HEAD,
                     uri=test_url,
                     status=200,
                     body=connection_error_callback)

        response = self.client.get((reverse('fetch') +
                                    ('?target=%s' % test_url)))
        self.assertContains(
            response,
            'Unable to access the requested remote file headers',
github lokenx / plexrequests-python / config / tests.py View on Github external
    @httpretty.activate
    def test_invalid_plex_friend(self):
        """
        Should reject a valid new plex user that isn't friends with the server admin
        """
        httpretty.register_uri(httpretty.POST, "https://plex.tv/users/sign_in.json",
                               body='{"user":{"email": "test@email.com"}}',
                               status=201)

        httpretty.register_uri(httpretty.GET, "https://plex.tv/pms/friends/all?X-Plex-Token=abcd1234",
                               body="""
                                    """,
                               status=200)

        Config.objects.create()
        client = APIClient()
        data = {'username': 'user', 'password': 'pass'}
github openstack / keystonemiddleware / v3 / test_auth.py View on Github external
    @httpretty.activate
    def test_authenticate_success_token_domain_scoped(self):
        ident = self.TEST_REQUEST_BODY['auth']['identity']
        del ident['password']
        ident['methods'] = ['token']
        ident['token'] = {}
        ident['token']['id'] = self.TEST_TOKEN

        scope = self.TEST_REQUEST_BODY['auth']['scope']
        del scope['project']
        scope['domain'] = {}
        scope['domain']['id'] = self.TEST_DOMAIN_ID

        token = self.TEST_RESPONSE_DICT['token']
        del token['project']
        token['domain'] = {}
        token['domain']['id'] = self.TEST_DOMAIN_ID
github canonical / cloud-init / tests / unittests / test_datasource / test_exoscale.py View on Github external
import os
import requests


TEST_PASSWORD_URL = "{}:{}/{}/".format(METADATA_URL,
                                       PASSWORD_SERVER_PORT,
                                       API_VERSION)

TEST_METADATA_URL = "{}/{}/meta-data/".format(METADATA_URL,
                                              API_VERSION)

TEST_USERDATA_URL = "{}/{}/user-data".format(METADATA_URL,
                                             API_VERSION)


@httpretty.activate
class TestDatasourceExoscale(HttprettyTestCase):

    def setUp(self):
        super(TestDatasourceExoscale, self).setUp()
        self.tmp = self.tmp_dir()
        self.password_url = TEST_PASSWORD_URL
        self.metadata_url = TEST_METADATA_URL
        self.userdata_url = TEST_USERDATA_URL

    def test_password_saved(self):
        """The password is not set when it is not found
        in the metadata service."""
        httpretty.register_uri(httpretty.GET,
                               self.password_url,
                               body="saved_password")
        self.assertFalse(get_password())
github openstack / python-keystoneclient / tests / v3 / test_auth.py View on Github external
    @httpretty.activate
    def test_authenticate_success_userid_password_project_scoped(self):
        ident = self.TEST_REQUEST_BODY['auth']['identity']
        del ident['password']['user']['domain']
        del ident['password']['user']['name']
        ident['password']['user']['id'] = self.TEST_USER

        self.stub_auth(json=self.TEST_RESPONSE_DICT)

        cs = client.Client(user_id=self.TEST_USER,
                           password=self.TEST_TOKEN,
                           project_id=self.TEST_TENANT_ID,
                           auth_url=self.TEST_URL)
        self.assertEqual(cs.auth_tenant_id,
                         self.TEST_TENANT_ID)
        self.assertEqual(cs.management_url,
                         self.TEST_RESPONSE_DICT["token"]["catalog"][3]
github chaoss / grimoirelab-perceval / tests / test_client.py View on Github external
    @httpretty.activate
    def test_fetch_http_error(self):
        """Test fetch method"""

        httpretty.register_uri(httpretty.GET,
                               CLIENT_SUPERMAN_URL,
                               body="",
                               status=403)

        client = MockedClient(CLIENT_API_URL, sleep_time=0.1, max_retries=1)

        with self.assertRaises(requests.exceptions.HTTPError):
            _ = client.fetch(CLIENT_SUPERMAN_URL)
github inspirehep / inspire-next / tests / test_robotupload.py View on Github external
    @httpretty.activate
    def test_robotupload_success_append(self):
        """Test proper handling when good MARCXML is sent."""
        from inspirehep.utils.robotupload import make_robotupload_marcxml
        httpretty.register_uri(
            httpretty.POST,
            "http://localhost:4000/batchuploader/robotupload/append",
            body="[INFO] bibupload batchupload --append /dummy/file/path\n",
            status=200
        )
        valid_marcxml = ""
        response = make_robotupload_marcxml(
            "http://localhost:4000",
            valid_marcxml,
            mode="append",
        )
        self.assertEqual(response.status_code, 200)
github WeblateOrg / weblate / weblate / machinery / tests.py View on Github external
    @httpretty.activate
    def test_apertium_apy(self):
        machine = self.get_machine(ApertiumAPYTranslation)
        self.register_apertium_urls()
        self.assert_translate(machine, 'es')
        self.assert_translate(machine, 'es', word='Zkouška')
github polyaxon / polyaxon-client / tests / test_api / test_experiment_group.py View on Github external
    @httpretty.activate
    def test_stop_experiment_group_all(self):
        httpretty.register_uri(
            httpretty.POST,
            BaseApiHandler.build_url(
                self.api_config.base_url,
                '/',
                'username',
                'project_name',
                'groups',
                1,
                'stop'),
            content_type='application/json',
            status=200)
        result = self.api_handler.stop('username', 'project_name', 1)
        assert result.status_code == 200
github bennylope / pygeocodio / tests / test_client.py View on Github external
    @httpretty.activate
    def test_return_none_with_no_address_or_components(self):
        """Ensure None is returned when geocoding with no passed in address or components data"""
        httpretty.register_uri(
            httpretty.GET, self.geocode_url, body=self.single_components, status=200
        )
        self.assertEqual(self.client.geocode(), None)