Python源码示例:responses.DELETE

示例1
def test_delete_policy(nomad_setup):
    responses.add(
        responses.DELETE,
        "http://{ip}:{port}/v1/sentinel/policy/my-policy".format(ip=common.IP, port=common.NOMAD_PORT),
        status=200,
        json={
            "Name": "foo",
            "Description": "test policy",
            "Scope": "submit-job",
            "EnforcementLevel": "advisory",
            "Policy": "main = rule { true }\n",
            "Hash": "CIs8aNX5OfFvo4D7ihWcQSexEJpHp+Za+dHSncVx5+8=",
            "CreateIndex": 8,
            "ModifyIndex": 8
        }
    )

    nomad_setup.sentinel.delete_policy(id="my-policy") 
示例2
def test_cli_dataset_delete_dataset():
    id = "cii9dtexw0039uelz7nzk1lq3"

    responses.add(
        responses.DELETE,
        'https://api.mapbox.com/datasets/v1/{0}/{1}?access_token={2}'.format(username, id, access_token),
        match_querystring=True,
        status=204
    )

    runner = CliRunner()
    result = runner.invoke(
        main_group,
        ['--access-token', access_token,
         'datasets',
         'delete-dataset', id])

    assert result.exit_code == 0 
示例3
def test_cli_dataset_delete_feature():
    dataset = "dataset-2"
    id = "abc"

    responses.add(
        responses.DELETE,
        'https://api.mapbox.com/datasets/v1/{0}/{1}/features/{2}?access_token={3}'.format(username, dataset, id, access_token),
        match_querystring=True,
        status=204
    )

    runner = CliRunner()
    result = runner.invoke(
        main_group,
        ['--access-token', access_token,
         'datasets',
         'delete-feature', dataset, id])

    assert result.exit_code == 0 
示例4
def test_disable_monitoring_monitors_not_found(self, mock_consul):
        """
        Test that the `disable_monitoring` method removes any New Relic
        Synthetics monitors for this instance, even if the actual monitors no longer exist.
        """
        monitor_ids = [str(uuid4()) for i in range(3)]
        instance = OpenEdXInstanceFactory()

        for monitor_id in monitor_ids:
            instance.new_relic_availability_monitors.create(pk=monitor_id)
            responses.add(
                responses.DELETE,
                '{0}/monitors/{1}'.format(newrelic.SYNTHETICS_API_URL, monitor_id),
                status=requests.codes.not_found
            )

        # Precondition
        self.assertEqual(instance.new_relic_availability_monitors.count(), 3)

        # Disable monitoring
        instance.disable_monitoring()

        # Instance should no longer have any monitors associated with it
        self.assertEqual(instance.new_relic_availability_monitors.count(), 0) 
示例5
def test_reset_stream_key():
    channel_id = example_channel["_id"]
    responses.add(
        responses.DELETE,
        "{}channels/{}/stream_key".format(BASE_URL, channel_id),
        body=json.dumps(example_channel),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    channel = client.channels.reset_stream_key(channel_id)

    assert len(responses.calls) == 1
    assert isinstance(channel, Channel)
    assert channel.id == example_channel["_id"]
    assert channel.name == example_channel["name"] 
示例6
def test_delete_post():
    channel_id = "1234"
    post_id = example_post["id"]
    responses.add(
        responses.DELETE,
        "{}feed/{}/posts/{}".format(BASE_URL, channel_id, post_id),
        body=json.dumps(example_post),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    post = client.channel_feed.delete_post(channel_id, post_id)

    assert len(responses.calls) == 1
    assert isinstance(post, Post)
    assert post.id == example_post["id"] 
示例7
def test_delete_reaction_to_post():
    channel_id = "1234"
    post_id = example_post["id"]
    body = {"deleted": True}
    responses.add(
        responses.DELETE,
        "{}feed/{}/posts/{}/reactions".format(BASE_URL, channel_id, post_id),
        body=json.dumps(body),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    response = client.channel_feed.delete_reaction_to_post(channel_id, post_id, "1234")

    assert len(responses.calls) == 1
    assert response["deleted"] 
示例8
def test_delete_post_comment():
    channel_id = "1234"
    post_id = example_post["id"]
    comment_id = example_comment["id"]
    responses.add(
        responses.DELETE,
        "{}feed/{}/posts/{}/comments/{}".format(
            BASE_URL, channel_id, post_id, comment_id
        ),
        body=json.dumps(example_comment),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    comment = client.channel_feed.delete_post_comment(channel_id, post_id, comment_id)

    assert len(responses.calls) == 1
    assert isinstance(comment, Comment)
    assert comment.id == example_comment["id"] 
示例9
def test_unblock_user():
    user_id = 1234
    blocked_user_id = 12345
    responses.add(
        responses.DELETE,
        "{}users/{}/blocks/{}".format(BASE_URL, user_id, blocked_user_id),
        body=json.dumps(example_block),
        status=200,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    client.users.unblock_user(user_id, blocked_user_id)

    assert len(responses.calls) == 1 
示例10
def test_oauth_response_missing_keys(self):
        """
        A ``requests.RequestException`` is raised when the call for an OAuth2 access token returns no data.
        """
        responses.add(
            responses.POST,
            self.oauth_url,
            json={},
            status=200
        )
        responses.add(
            responses.DELETE,
            self.course_url,
            json={},
            status=200
        )

        degreed_api_client = DegreedAPIClient(self.enterprise_config)
        with pytest.raises(ClientError):
            degreed_api_client.delete_content_metadata({}) 
示例11
def test_unlink_rich_menu_from_user(self):
        responses.add(
            responses.DELETE,
            LineBotApi.DEFAULT_API_ENDPOINT +
            '/v2/bot/user/user_id/richmenu',
            json={}, status=200
        )

        self.tested.unlink_rich_menu_from_user('user_id')

        request = responses.calls[0].request
        self.assertEqual(request.method, 'DELETE')
        self.assertEqual(
            request.url,
            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/user/user_id/richmenu'
        ) 
示例12
def test_cancel_default_rich_menu(self):
        responses.add(
            responses.DELETE,
            LineBotApi.DEFAULT_API_ENDPOINT +
            '/v2/bot/user/all/richmenu',
            json={}, status=200
        )

        self.tested.cancel_default_rich_menu()

        request = responses.calls[0].request
        self.assertEqual(request.method, 'DELETE')
        self.assertEqual(
            request.url,
            LineBotApi.DEFAULT_API_ENDPOINT + '/v2/bot/user/all/richmenu'
        ) 
示例13
def test_delete_namespace(nomad_setup):
    responses.add(
        responses.DELETE,
        "http://{ip}:{port}/v1/namespace/api".format(ip=common.IP, port=common.NOMAD_PORT),
        status=200,
    )

    nomad_setup.namespace.delete_namespace("api")



######### ENTERPRISE TEST ###########
# def test_apply_namespace(nomad_setup):
#     namespace_api='{"Name":"api","Description":"api server namespace"}'
#     namespace = json.loads(namespace_api)
#     nomad_setup.namespace.apply_namespace("api", namespace)
#     assert "api" in nomad_setup.namespace
#
# def test_get_namespace(nomad_setup):
#     assert "api" in nomad_setup.namespace.get_namespace("api")["Name"]
#
# def test_delete_namespace(nomad_setup):
#     nomad_setup.namespace.delete_namespace("api")
#     try:
#         assert "api" != nomad_setup.namespace.get_namespace("api")["Name"]
#     except nomad.api.exceptions.URLNotFoundNomadException:
#         pass 
示例14
def test_delete_synthetics_monitor(self):
        """
        Check that the delete_synthetics_monitor function deletes the monitor
        with the given id.
        """
        monitor_id = '3e442fa8-ec6c-4bf7-94ac-a0eccb817587'
        responses.add(responses.DELETE,
                      '{0}/monitors/{1}'.format(newrelic.SYNTHETICS_API_URL,
                                                monitor_id),
                      status=204)
        newrelic.delete_synthetics_monitor(monitor_id)
        self.assertEqual(len(responses.calls), 1)
        request_headers = responses.calls[0].request.headers
        self.assertEqual(request_headers['x-api-key'], 'admin-api-key') 
示例15
def test_delete_synthetics_monitor_exceptions(self):
        """
        Check that the delete_synthetics_monitor function behaves correctly if DELETE request unsuccessful.

        We expect the function *not* to raise an exception if the monitor to delete
        can not be found (i.e., if the DELETE request comes back with a 404).

        In all other cases the function should raise an exception.
        """
        monitor_id = '2085b3d6-3689-4847-97cc-f7c91d86cd1d'

        client_errors = [status_code for status_code in requests.status_codes._codes if 400 <= status_code < 500]
        server_errors = [status_code for status_code in requests.status_codes._codes if 500 <= status_code < 600]

        for error in client_errors + server_errors:
            with responses.RequestsMock() as mock_responses:
                mock_responses.add(responses.DELETE,
                                   '{0}/monitors/{1}'.format(newrelic.SYNTHETICS_API_URL,
                                                             monitor_id),
                                   status=error)
                try:
                    newrelic.delete_synthetics_monitor(monitor_id)
                except requests.exceptions.HTTPError:
                    if error == requests.codes.not_found:
                        self.fail('Should not raise an exception for {} response.'.format(error))
                else:
                    if not error == requests.codes.not_found:
                        self.fail('Should raise an exception for {} response.'.format(error)) 
示例16
def test_delete_alert_policy(self):
        """
        Check that the delete_alert_policy function behaves correctly if DELETE request unsuccessful.

        We expect the function *not* to raise an exception if the alert policy to delete
        can not be found (i.e., if the DELETE request comes back with a 404).

        In all other cases the function should raise an exception.
        """
        policy_id = 1

        client_errors = [status_code for status_code in requests.status_codes._codes if 400 <= status_code < 500]
        server_errors = [status_code for status_code in requests.status_codes._codes if 500 <= status_code < 600]

        for error in client_errors + server_errors:
            with responses.RequestsMock() as mock_responses:
                mock_responses.add(
                    responses.DELETE,
                    '{}/{}.json'.format(newrelic.ALERTS_POLICIES_API_URL, policy_id),
                    status=error
                )
                try:
                    newrelic.delete_alert_policy(policy_id)
                except requests.exceptions.HTTPError:
                    if error == requests.codes.not_found:
                        self.fail('Should not raise an exception for {} response.'.format(error))
                else:
                    if not error == requests.codes.not_found:
                        self.fail('Should raise an exception for {} response.'.format(error)) 
示例17
def test_delete_alert_condition(self):
        """
        Check that the delete_alert_condition function behaves correctly if DELETE request unsuccessful.

        We expect the function *not* to raise an exception if the alert_condition to delete
        can not be found (i.e., if the DELETE request comes back with a 404).

        In all other cases the function should raise an exception.
        """
        condition_id = 1

        client_errors = [status_code for status_code in requests.status_codes._codes if 400 <= status_code < 500]
        server_errors = [status_code for status_code in requests.status_codes._codes if 500 <= status_code < 600]

        for error in client_errors + server_errors:
            with responses.RequestsMock() as mock_responses:
                mock_responses.add(
                    responses.DELETE,
                    '{}/{}.json'.format(newrelic.ALERTS_CONDITIONS_API_URL, condition_id),
                    status=error
                )
                try:
                    newrelic.delete_alert_condition(condition_id)
                except requests.exceptions.HTTPError:
                    if error == requests.codes.not_found:
                        self.fail('Should not raise an exception for {} response.'.format(error))
                else:
                    if not error == requests.codes.not_found:
                        self.fail('Should raise an exception for {} response.'.format(error)) 
示例18
def test_hide_greeting(self):
        exp="""
        {
            "fields": [
                "greeting"
            ]
        }
        """
        with MessengerAPIMock(subpath="messenger_profile", expected=exp,
                              method=MessengerAPIMock.DELETE, utest=self) as m:
            self.page.hide_greeting() 
示例19
def test_hide_starting_button(self):
        exp="""
        {
            "fields": [
                "get_started"
            ]
        }
        """
        with MessengerAPIMock(subpath="messenger_profile", expected=exp,
                              method=MessengerAPIMock.DELETE, utest=self) as m:
            self.page.hide_starting_button() 
示例20
def test_hide_persistent_menu(self):
        exp="""
        {
            "fields": [
                "persistent_menu"
            ]
        }
        """
        with MessengerAPIMock(subpath="messenger_profile", expected=exp,
                              method=MessengerAPIMock.DELETE, utest=self) as m:
            self.page.hide_persistent_menu() 
示例21
def test_storage_delete(pydrill_instance, pydrill_url, name):
    """
    :type pydrill_instance: pydrill.client.PyDrill
    """
    responses.add(**{
        'method': responses.DELETE,
        'url': '{0}/{1}'.format(pydrill_url, 'storage/{0}.json'.format(name)),
        'content_type': 'application/json',
        'status': 200,
    })
    result = pydrill_instance.storage_delete(name=name)
    assert type(result) == Result
    assert result.response.status_code == 200 
示例22
def mock_node_delete(self, status):
        responses.add(
            responses.DELETE,
            '{root}/node.json/{node_id}'.format(root=self.api_root, node_id=self.node_id),
            body='',
            content_type='text/html',
            status=status
        ) 
示例23
def delete(self, url, filename, status=204):
        """Setup a mock response for a DELETE request."""
        body = self._get_body(filename)
        self.add(responses.DELETE, url, body=body, status=status, content_type='application/hal+json') 
示例24
def test_request_delete_does_not_raise_exception_if_successful():
    responses.add(
        responses.DELETE, BASE_URL, status=204, content_type="application/json"
    )

    api = TwitchAPI(client_id="client")
    api._request_delete("") 
示例25
def test_request_delete_does_not_raise_exception_if_successful_and_returns_json():
    responses.add(
        responses.DELETE,
        BASE_URL,
        body=json.dumps(dummy_data),
        status=200,
        content_type="application/json",
    )

    api = TwitchAPI(client_id="client")
    response = api._request_delete("")
    assert response == dummy_data 
示例26
def test_request_delete_sends_headers_with_the_request():
    responses.add(
        responses.DELETE, BASE_URL, status=204, content_type="application/json"
    )

    api = TwitchAPI(client_id="client")
    api._request_delete("")

    assert "Client-ID" in responses.calls[0].request.headers
    assert "Accept" in responses.calls[0].request.headers 
示例27
def test_request_delete_raises_exception_if_not_200_response(status):
    responses.add(
        responses.DELETE, BASE_URL, status=status, content_type="application/json"
    )

    api = TwitchAPI(client_id="client")

    with pytest.raises(exceptions.HTTPError):
        api._request_delete("") 
示例28
def test_delete():
    collection_id = "abcd"
    responses.add(
        responses.DELETE,
        "{}collections/{}".format(BASE_URL, collection_id),
        status=204,
        content_type="application/json",
    )

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

    client.collections.delete(collection_id)

    assert len(responses.calls) == 1 
示例29
def test_delete_from_community():
    channel_id = example_channel["_id"]
    responses.add(
        responses.DELETE,
        "{}channels/{}/community".format(BASE_URL, channel_id),
        body=json.dumps(example_community),
        status=204,
        content_type="application/json",
    )

    client = TwitchClient("client id")

    client.channels.delete_from_community(channel_id)

    assert len(responses.calls) == 1 
示例30
def test_unban_user():
    community_id = "abcd"
    user_id = 1234
    responses.add(
        responses.DELETE,
        "{}communities/{}/bans/{}".format(BASE_URL, community_id, user_id),
        status=204,
        content_type="application/json",
    )

    client = TwitchClient("client id", "oauth token")

    client.communities.unban_user(community_id, user_id)

    assert len(responses.calls) == 1