How to use the responses.PATCH function in responses

To help you get started, we’ve selected a few responses 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 razorpay / razorpay-python / tests / test_client_transfer.py View on Github external
def test_transfer_edit(self):
        param = {'on_hold': False}
        result = mock_file('fake_transfer')
        url = "{}/dummy_id".format(self.base_url)
        responses.add(responses.PATCH, url, status=200, body=json.dumps(result),
                      match_querystring=True)
        self.assertEqual(self.client.transfer.edit('dummy_id', param), result)
github vintasoftware / tapioca-wrapper / tests / test_tapioca.py View on Github external
def test_patch_request(self):
        responses.add(responses.PATCH, self.wrapper.test().data,
                      body='{"data": {"key": "value"}}',
                      status=201,
                      content_type='application/json')

        response = self.wrapper.test().patch()

        self.assertEqual(response().data, {'data': {'key': 'value'}})
github rubrikinc / rubrik-sdk-for-python / tests / test_api.py View on Github external
"geolocation": {
            "address": "string"
        },
        "acceptedEulaVersion": "string",
        "latestEulaVersion": "string"
    }

    error_message = {
        'errorType': 'user_error',
        'message': 'Incorrect username/password',
        'code': 'invalid_authentication_credentials',
        'cause': None
    }

    # Test 1 - Successful Request
    responses.add(responses.PATCH, url, json=response_body, status=200)
    # Test 2 - Invalid Request
    responses.add(responses.PATCH, url, status=500)
    # Test 3 - Invalid Request (Rubrik provided error message)
    responses.add(responses.PATCH, url, json=error_message, status=422)

    # Test 1 - Successful Request
    resp = rubrik.patch(api_version, api_endpoint, config)
    assert resp == response_body

    # Test 2 - Invalid Request
    with pytest.raises(SystemExit, match="500 Server Error: Internal Server Error for url"):
        resp = rubrik.patch(api_version, api_endpoint, config)

    # Test 3 - Invalid Request (Rubrik provided error message)
    with pytest.raises(SystemExit, match="Error: Incorrect username/password"):
        resp = rubrik.patch(api_version, api_endpoint, config)
github getsentry / sentry-plugins / tests / vsts / test_plugin.py View on Github external
def test_create_issue(self):
        responses.add(
            responses.PATCH,
            "https://fabrikam-fiber-inc.visualstudio.com/DefaultProject/_apis/wit/workitems/$Bug",
            body=WORK_ITEM_RESPONSE,
            content_type="application/json",
        )

        self.plugin.set_option("instance", "fabrikam-fiber-inc.visualstudio.com", self.project)
        self.plugin.set_option("default_project", "DefaultProject", self.project)
        group = self.create_group(message="Hello world", culprit="foo.bar")

        request = self.request.get("/")
        request.user = AnonymousUser()
        form_data = {"title": "Hello", "description": "Fix this."}
        with self.assertRaises(PluginError):
            self.plugin.create_issue(request, group, form_data)

        request.user = self.user
github bhodorog / pytest-vts / src / pytest_vts / vts / __init__.py View on Github external
def setup_recording(self, **kwargs):
        _logger.info("recording ...")
        self.responses.reset()
        all_requests_re = re.compile("http.*")
        methods = (responses.GET, responses.POST, responses.PUT,
                   responses.PATCH, responses.DELETE, responses.HEAD,
                   responses.OPTIONS)
        for http_method in methods:
            self.responses.add_callback(
                http_method, all_requests_re,
                match_querystring=False,
                callback=self.record())
github conan-io / hooks / tests / test_hooks / test_github_updater.py View on Github external
def test_failed_attribute_update(self):
        responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy', json=_GITHUB_REPO_DATA)
        responses.add(responses.PATCH, 'https://api.github.com/repos/foobar/conan-dummy', status=500, json={"message": "Internal Server Error"})
        tools.save('conanfile.py', content=self.conanfile_complete)
        output = self.conan(['export', '.', 'name/0.1.0@foobar/stable'])
        self.assertIn('pre_export(): WARN: The attributes description, homepage, name are outdated and they will be updated.', output)
        self.assertIn('pre_export(): ERROR: GitHub PATCH request failed with (500): {"message": "Internal Server Error"}.', output)
github Instamojo / instamojo-py / tests / test_products.py View on Github external
def test_product_edit_with_all_params(self):
        data = products_payload['product_edit_with_all_params']
        endpoint = self.api_endpoint + 'links/{slug}/'.format(slug=data['request']['slug'])
        get_file_upload_url_endpoint = self.api_endpoint + 'links/get_file_upload_url/'
        file_upload_endpoint = self.api_endpoint + 'links/upload/'
        responses.add(
            responses.PATCH,
            endpoint,
            body='{}',
            content_type='application/json'
        )
        responses.add(
            responses.GET,
            get_file_upload_url_endpoint,
            json={'upload_url': file_upload_endpoint}
        )

        responses.add(
            responses.POST,
            file_upload_endpoint,
            body='{"spam": "eggs"}'
        )
        with patch('instamojo_wrapper.api.open', mock_open(), create=True) as m:
github cloudlinux / kuberdock-platform / kubedock / testutils / fixtures.py View on Github external
Stubs K8S API call used to update node info using PATCH requests.
        For now it saves metadata part in cache per node, so it can be used
        by node_info stub if one is enabled
        on
        :param hostname: hostname of a node to enable this stub for
        """

        def request_callback(request):
            payload = json.loads(request.body)
            if 'metadata' in payload:
                # TODO: Actually patch metadata, not just replace it
                self.metadata[hostname] = payload['metadata']
            return 200, {}, json.dumps(payload)

        url = get_api_url('nodes', hostname, namespace=None)
        responses.add_callback(responses.PATCH, url,
                               callback=request_callback)
github actmd / zoomus / tests / zoomus / components / meeting / test_update.py View on Github external
def test_can_update(self):
        responses.add(responses.PATCH, "http://foo.com/meetings/42")
        response = self.component.update(id="42", foo="bar")
        self.assertEqual(response.request.body, '{"id": "42", "foo": "bar"}')
github getsentry / sentry / tests / sentry_plugins / vsts / test_plugin.py View on Github external
def test_create_issue(self):
        responses.add(
            responses.PATCH,
            "https://fabrikam-fiber-inc.visualstudio.com/DefaultProject/_apis/wit/workitems/$Bug",
            body=WORK_ITEM_RESPONSE,
            content_type="application/json",
        )

        self.plugin.set_option("instance", "fabrikam-fiber-inc.visualstudio.com", self.project)
        self.plugin.set_option("default_project", "DefaultProject", self.project)
        group = self.create_group(message="Hello world", culprit="foo.bar")

        request = self.request.get("/")
        request.user = AnonymousUser()
        form_data = {"title": "Hello", "description": "Fix this."}
        with self.assertRaises(PluginError):
            self.plugin.create_issue(request, group, form_data)

        request.user = self.user