How to use the responses.PUT 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 getsentry / sentry / tests / sentry / integrations / jira / test_integration.py View on Github external
def test_sync_assignee_outbound_case_insensitive(self):
        self.user = self.create_user(email="bob@example.com")
        issue_id = "APP-123"
        installation = self.integration.get_installation(self.organization.id)
        assign_issue_url = "https://example.atlassian.net/rest/api/2/issue/%s/assignee" % issue_id
        external_issue = ExternalIssue.objects.create(
            organization_id=self.organization.id, integration_id=installation.model.id, key=issue_id
        )
        responses.add(
            responses.GET,
            "https://example.atlassian.net/rest/api/2/user/assignable/search",
            json=[{"accountId": "deadbeef123", "emailAddress": "Bob@example.com"}],
            match_querystring=False,
        )
        responses.add(responses.PUT, assign_issue_url, json={}, match_querystring=False)
        installation.sync_assignee_outbound(external_issue, self.user)

        assert len(responses.calls) == 2

        # assert user above was successfully assigned
        assign_issue_response = responses.calls[1][1]
        assert assign_issue_url in assign_issue_response.url
        assert assign_issue_response.status_code == 200
        assert assign_issue_response.request.body == '{"accountId": "deadbeef123"}'
github tsifrer / python-twitch-client / tests / api / test_collections.py View on Github external
def test_move_item():
    collection_id = 'abcd'
    collection_item_id = '1234'
    responses.add(responses.PUT,
                  '{}collections/{}/items/{}'.format(BASE_URL, collection_id, collection_item_id),
                  status=204,
                  content_type='application/json')

    client = TwitchClient('client id', 'oauth client')

    client.collections.move_item(collection_id, collection_item_id, 3)

    assert len(responses.calls) == 1
github olipratt / swagger-conformance / tests / test_custom_types.py View on Github external
def _run_test_colour_type(self, value_factory):
        """Test just to show how tests using multiple requests work."""

        def _get_request_callback(_):
            # Respond with the previously received body value.
            raw_val = json.loads(responses.calls[-1].request.body)["hexcolour"]
            int_val = int(raw_val.lstrip('#'), 16)
            return 200, {}, json.dumps({'intcolour': int_val})

        responses.add(responses.POST, SCHEMA_URL_BASE + '/example',
                      json={'id': 1}, content_type=CONTENT_TYPE_JSON)
        responses.add(responses.PUT, SCHEMA_URL_BASE + '/example/1/hexcolour',
                      content_type=CONTENT_TYPE_JSON, status=204)

        responses.add_callback(responses.GET,
                               SCHEMA_URL_BASE + '/example/1/intcolour',
                               callback=_get_request_callback,
                               content_type=CONTENT_TYPE_JSON)

        client = swaggerconformance.client.Client(COLOUR_TYPE_SCHEMA_PATH)
        post_operation = client.api.endpoints["/example"]["post"]
        put_operation = \
            client.api.endpoints["/example/{int_id}/hexcolour"]["put"]
        put_strategy = put_operation.parameters_strategy(value_factory)
        get_operation = \
            client.api.endpoints["/example/{int_id}/intcolour"]["get"]
        get_strategy = get_operation.parameters_strategy(value_factory)
github canonical-web-and-design / snapcraft.io / tests / publisher / snaps / tests_post_settings.py View on Github external
def test_return_error_invalid_field(self):
        metadata_payload = {
            "error_list": [
                {
                    "code": "invalid-field",
                    "message": "error message",
                    "extra": {"name": "description"},
                }
            ]
        }

        responses.add(
            responses.PUT, self.api_url, json=metadata_payload, status=500
        )

        info_url = "https://dashboard.snapcraft.io/dev/api/snaps/info/{}"
        info_url = info_url.format(self.snap_name)

        payload = {
            "snap_id": self.snap_id,
            "title": "test snap",
            "snap_name": self.snap_name,
            "summary": "This is a summary",
            "description": "This is a description",
            "license": "license",
            "media": [],
            "publisher": {"display-name": "The publisher"},
            "private": True,
            "unlisted": False,
github getsentry / sentry-plugins / tests / test_client.py View on Github external
def test_put(self):
        responses.add(responses.PUT, "http://example.com", json={})

        resp = ApiClient().put("http://example.com")
        assert resp.status_code == 200
github conan-io / hooks / tests / test_hooks / test_github_updater.py View on Github external
def test_updated_project(self):
        responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy', json=_GITHUB_REPO_DATA_UPDATED)
        responses.add(responses.GET, 'https://api.github.com/repos/foobar/conan-dummy/topics', json=_GITHUB_TOPICS_DATA_UPDATED)
        responses.add(responses.PATCH, 'https://api.github.com/repos/foobar/conan-dummy')
        responses.add(responses.PUT, 'https://api.github.com/repos/foobar/conan-dummy/topics')
        tools.save('conanfile.py', content=self.conanfile_complete)
        output = self.conan(['export', '.', 'name/0.1.0@foobar/stable'])
        self.assertIn('pre_export(): The attributes are up-to-date.', output)
        self.assertIn('pre_export(): The topics are up-to-date.', output)
github Datatamer / tamr-client / tests / unit / test_attribute.py View on Github external
def test_update_attribute(self):
        def create_callback(request, snoop):
            snoop["payload"] = request.body
            return 200, {}, json.dumps(self._updated_attribute_json)

        relative_id = "dataset/1/attributes/RowNum"
        attribute_url = f"http://localhost:9100/api/versioned/v1/{relative_id}"
        snoop_dict = {}
        responses.add_callback(
            responses.PUT, attribute_url, partial(create_callback, snoop=snoop_dict)
        )
        attribute = Attribute(self.tamr, self._attributes_json[0], relative_id)

        temp_spec = attribute.spec()
        new_attribute = temp_spec.with_description(
            self._updated_attribute_json["description"]
        ).put()
        self.assertEqual(new_attribute.name, self._updated_attribute_json["name"])
        self.assertEqual(
            new_attribute.description, self._updated_attribute_json["description"]
        )

        self.assertEqual(
            json.loads(snoop_dict["payload"]), self._updated_attribute_json
        )
github containerbuildsystem / atomic-reactor / tests / plugins / test_push_floating_tags.py View on Github external
def __init__(self, registry):
        self.hostname = registry_hostname(registry)
        self.repos = {}
        self._add_pattern(responses.PUT, r'/v2/(.*)/manifests/([^/]+)',
                          self._put_manifest)
github awslabs / aws-ec2rescue-linux / test / test_main.py View on Github external
def test_main_upload_with_invalid_presigned_url(self, make_tarfile_mock, open_mock, remove_mock):
        """Test how invalid presigned URLs are handled in the upload subcommand."""
        responses.add(responses.PUT, "http://fakeurl.com", status=403)
        self.ec2rl.options.global_args["uploaddirectory"] = "."
        self.ec2rl.options.global_args["presignedurl"] = "http://fakeurl.com/"
        with self.assertRaises(ec2rlcore.s3upload.S3UploadResponseError):
            with contextlib.redirect_stdout(self.output):
                self.ec2rl.upload()
        self.assertEqual(self.output.getvalue(), "ERROR: Upload failed.  Received response 403\n")
        self.assertTrue(make_tarfile_mock.called)
        self.assertTrue(open_mock.called)
        self.assertTrue(remove_mock.called)
        del self.ec2rl.options.global_args["uploaddirectory"]
        del self.ec2rl.options.global_args["presignedurl"]
github histrio / py-couchdb / test / functional_tests.py View on Github external
def test_create_db_conflict(self):
        with responses.RequestsMock() as rsps:
            rsps.add(responses.PUT, "http://example.com/testing1")
            rsps.add(responses.HEAD, "http://example.com/testing1")
            self.server.create("testing1")

        with responses.RequestsMock() as rsps:
            rsps.add(responses.PUT, "http://example.com/testing1",
                     content_type="application/json",
                     body='{"error":"file_exists"}', status=409)
            self.server.create("testing1")