Python httpretty.DELETE Examples

The following are 22 code examples of httpretty.DELETE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module httpretty , or try the search function .
Example #1
Source File: test_job.py    From polyaxon-client with MIT License 6 votes vote down vote up
def test_delete_job(self):
        httpretty.register_uri(
            httpretty.DELETE,
            BaseApiHandler.build_url(
                self.api_config.base_url,
                '/',
                'username',
                'project_name',
                'jobs',
                1),
            content_type='application/json',
            status=204)
        result = self.api_handler.delete_job('username', 'project_name', 1)
        assert result.status_code == 204

        # Async
        self.assert_async_call(
            api_handler_call=lambda: self.api_handler.delete_job(
                'username', 'project_name', 1, background=True),
            method='delete') 
Example #2
Source File: test_experiment_group.py    From polyaxon-client with MIT License 6 votes vote down vote up
def test_unbookmark_experiment_group(self):
        httpretty.register_uri(
            httpretty.DELETE,
            BaseApiHandler.build_url(
                self.api_config.base_url,
                '/',
                'username',
                'project_name',
                'groups',
                1,
                'unbookmark'),
            content_type='application/json',
            status=200)
        result = self.api_handler.unbookmark('username', 'project_name', 1)
        assert result.status_code == 200

        # Async
        self.assert_async_call(
            api_handler_call=lambda: self.api_handler.unbookmark(
                'username', 'project_name', 1, background=True),
            method='delete') 
Example #3
Source File: test_experiment_group.py    From polyaxon-client with MIT License 6 votes vote down vote up
def test_delete_experiment_group(self):
        httpretty.register_uri(
            httpretty.DELETE,
            BaseApiHandler.build_url(
                self.api_config.base_url,
                '/',
                'username',
                'project_name',
                'groups',
                1),
            content_type='application/json',
            status=204)
        result = self.api_handler.delete_experiment_group('username', 'project_name', 1)
        assert result.status_code == 204

        # Async
        self.assert_async_call(
            api_handler_call=lambda: self.api_handler.delete_experiment_group(
                'username', 'project_name', 1, background=True),
            method='delete') 
Example #4
Source File: test_project.py    From polyaxon-client with MIT License 6 votes vote down vote up
def test_unbookmark_project(self):
        httpretty.register_uri(
            httpretty.DELETE,
            BaseApiHandler.build_url(
                self.api_config.base_url,
                '/',
                'username',
                'project_name',
                'unbookmark'),
            content_type='application/json',
            status=200)
        result = self.api_handler.unbookmark('username', 'project_name')
        assert result.status_code == 200

        # Async
        self.assert_async_call(
            api_handler_call=lambda: self.api_handler.unbookmark(
                'user', 'project_name', background=True),
            method='delete') 
Example #5
Source File: test_project.py    From polyaxon-client with MIT License 6 votes vote down vote up
def test_delete_project(self):
        httpretty.register_uri(
            httpretty.DELETE,
            BaseApiHandler.build_url(
                self.api_config.base_url,
                '/',
                'user',
                'project'),
            content_type='application/json',
            status=204)
        result = self.api_handler.delete_project('user', 'project')
        assert result.status_code == 204

        # Async
        self.assert_async_call(
            api_handler_call=lambda: self.api_handler.delete_project(
                'user', 'project', background=True),
            method='delete') 
Example #6
Source File: test_resource.py    From pysnow with MIT License 6 votes vote down vote up
def test_delete(self):
        """:meth:`delete` should return a dictionary containing status"""

        httpretty.register_uri(
            httpretty.GET,
            self.mock_url_builder_base,
            body=get_serialized_result(self.record_response_get_one),
            status=200,
            content_type="application/json",
        )

        httpretty.register_uri(
            httpretty.DELETE,
            self.mock_url_builder_sys_id,
            body=get_serialized_result(self.record_response_delete),
            status=204,
            content_type="application/json",
        )

        result = self.resource.delete(self.dict_query)

        self.assertEquals(type(result), dict)
        self.assertEquals(result["status"], "record deleted") 
Example #7
Source File: test_resource.py    From pysnow with MIT License 6 votes vote down vote up
def test_delete_chained(self):
        """:meth:`Response.delete` should return a dictionary containing status"""

        httpretty.register_uri(
            httpretty.GET,
            self.mock_url_builder_base,
            body=get_serialized_result(self.record_response_get_one),
            status=200,
            content_type="application/json",
        )

        httpretty.register_uri(
            httpretty.DELETE,
            self.mock_url_builder_sys_id,
            body=get_serialized_result(self.record_response_delete),
            status=204,
            content_type="application/json",
        )

        result = self.resource.get(query={}).delete()

        self.assertEquals(type(result), dict)
        self.assertEquals(result["status"], "record deleted") 
Example #8
Source File: test_attachment.py    From pysnow with MIT License 6 votes vote down vote up
def test_upload_delete(self):
        """Deleting an attachment should trigger pysnow to perform a lookup followed by a delete"""

        httpretty.register_uri(
            httpretty.GET,
            self.attachment_base_url,
            body=get_serialized_result(attachment),
            status=200,
            content_type="application/json",
        )

        httpretty.register_uri(
            httpretty.DELETE,
            self.attachment_url_sys_id,
            body=get_serialized_result(delete_status),
            status=204,
            content_type="application/json",
        )

        resource = self.client.resource(api_path=mock_api_path)
        result = resource.attachments.delete(mock_sys_id)

        self.assertEqual(result, delete_status) 
Example #9
Source File: test_build_job.py    From polyaxon-client with MIT License 6 votes vote down vote up
def test_unbookmark_build(self):
        httpretty.register_uri(
            httpretty.DELETE,
            BaseApiHandler.build_url(
                self.api_config.base_url,
                '/',
                'username',
                'project_name',
                'builds',
                1,
                'unbookmark'),
            content_type='application/json',
            status=200)
        result = self.api_handler.unbookmark('username', 'project_name', 1)
        assert result.status_code == 200

        # Async
        self.assert_async_call(
            api_handler_call=lambda: self.api_handler.unbookmark(
                'username', 'project_name', 1, background=True),
            method='delete') 
Example #10
Source File: test_build_job.py    From polyaxon-client with MIT License 6 votes vote down vote up
def test_delete_build(self):
        httpretty.register_uri(
            httpretty.DELETE,
            BaseApiHandler.build_url(
                self.api_config.base_url,
                '/',
                'username',
                'project_name',
                'builds',
                1),
            content_type='application/json',
            status=204)
        result = self.api_handler.delete_build('username', 'project_name', 1)
        assert result.status_code == 204

        # Async
        self.assert_async_call(
            api_handler_call=lambda: self.api_handler.delete_build(
                'username', 'project_name', 1, background=True),
            method='delete') 
Example #11
Source File: test_experiment.py    From polyaxon-client with MIT License 6 votes vote down vote up
def test_delete_experiment(self):
        httpretty.register_uri(
            httpretty.DELETE,
            BaseApiHandler.build_url(
                self.api_config.base_url,
                '/',
                'username',
                'project_name',
                'experiments',
                1),
            content_type='application/json',
            status=204)
        result = self.api_handler.delete_experiment('username', 'project_name', 1)
        assert result.status_code == 204

        # Async
        self.assert_async_call(
            api_handler_call=lambda: self.api_handler.delete_experiment(
                'username', 'project_name', 1, background=True),
            method='delete') 
Example #12
Source File: test_experiment.py    From polyaxon-client with MIT License 6 votes vote down vote up
def test_unbookmark_experiment(self):
        httpretty.register_uri(
            httpretty.DELETE,
            BaseApiHandler.build_url(
                self.api_config.base_url,
                '/',
                'username',
                'project_name',
                'experiments',
                1,
                'unbookmark'),
            content_type='application/json',
            status=200)
        result = self.api_handler.unbookmark('username', 'project_name', 1)
        assert result.status_code == 200

        # Async
        self.assert_async_call(
            api_handler_call=lambda: self.api_handler.unbookmark(
                'username', 'project_name', 1, background=True),
            method='delete') 
Example #13
Source File: test_couch.py    From openag_python with GNU General Public License v3.0 5 votes vote down vote up
def test_cancel_replication():
    server = Server("http://test.test:5984")
    httpretty.register_uri(
        httpretty.HEAD, "http://test.test:5984/_replicator",
        status=200
    )
    global doc_exists
    doc_exists = True
    def head_test_src(request, uri, headers):
        if doc_exists:
            return 200, headers, ""
        else:
            return 404, headers, ""
    httpretty.register_uri(
        httpretty.HEAD, "http://test.test:5984/_replicator/test_src",
        etag="a", body=head_test_src
    )
    def delete_test_src(request, uri, headers):
        global doc_exists
        doc_exists = False
        return 200, headers, ""
    httpretty.register_uri(
        httpretty.DELETE, "http://test.test:5984/_replicator/test_src",
        etag="a", body=delete_test_src
    )
    assert "test_src" in server["_replicator"]
    server.cancel_replication("test_src")
    assert "test_src" not in server["_replicator"] 
Example #14
Source File: test_user.py    From polyaxon-client with MIT License 5 votes vote down vote up
def test_delete_user(self):
        httpretty.register_uri(
            httpretty.DELETE,
            BaseApiHandler.build_url(
                self.api_config.base_url,
                '/users',
                'delete',
                'test-username'
            ),
            content_type='application/json',
            status=204)

        response = self.api_handler.delete_user('test-username')
        assert response.status_code == 204 
Example #15
Source File: test_model_integration.py    From stream-django with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def register_delete_api(self):
        httpretty.register_uri(httpretty.DELETE, api_url,
              body='{}', status=200,
              content_type='application/json') 
Example #16
Source File: test_request.py    From pysnow with MIT License 5 votes vote down vote up
def test_clone_incident_non_existent(self):
        """
        Attempt to clone a non-existing record
        """
        httpretty.register_uri(
            httpretty.GET,
            "http://%s/%s" % (self.mock_connection["host"], self.mock_incident["path"]),
            body=json.dumps({"result": {}}),
            status=200,
            content_type="application/json",
        )

        httpretty.register_uri(
            httpretty.DELETE,
            "http://%s/%s/%s"
            % (
                self.mock_connection["host"],
                self.mock_incident["path"],
                self.mock_incident["sys_id"],
            ),
            body=json.dumps({"success": True}),
            status=204,
            content_type="application/json",
        )

        r = self.client.query(
            table="incident", query={"number": self.mock_incident["number"]}
        )
        self.assertRaises(NoResults, r.clone) 
Example #17
Source File: test_request.py    From pysnow with MIT License 5 votes vote down vote up
def test_delete_incident_non_existent(self):
        """
        Attempt to delete a non-existing record
        """
        client = copy(self.client)
        httpretty.register_uri(
            httpretty.GET,
            "http://%s/%s" % (self.mock_connection["host"], self.mock_incident["path"]),
            body=json.dumps({"result": {}}),
            status=200,
            content_type="application/json",
        )

        httpretty.register_uri(
            httpretty.DELETE,
            "http://%s/%s/%s"
            % (
                self.mock_connection["host"],
                self.mock_incident["path"],
                self.mock_incident["sys_id"],
            ),
            body=json.dumps({"success": True}),
            status=204,
            content_type="application/json",
        )

        client.raise_on_empty = False

        r = client.query(
            table="incident", query={"number": self.mock_incident["number"]}
        )
        self.assertRaises(NoResults, r.delete) 
Example #18
Source File: test_request.py    From pysnow with MIT License 5 votes vote down vote up
def test_delete_incident_invalid_response(self):
        """
        Make sure non-204 responses are properly handled
        """
        httpretty.register_uri(
            httpretty.GET,
            "http://%s/%s" % (self.mock_connection["host"], self.mock_incident["path"]),
            body=json.dumps({"result": [{"sys_id": self.mock_incident["sys_id"]}]}),
            status=200,
            content_type="application/json",
        )

        httpretty.register_uri(
            httpretty.DELETE,
            "http://%s/%s/%s"
            % (
                self.mock_connection["host"],
                self.mock_incident["path"],
                self.mock_incident["sys_id"],
            ),
            body=json.dumps({"success": True}),
            status=200,
            content_type="application/json",
        )

        r = self.client.query(
            table="incident", query={"number": self.mock_incident["number"]}
        )
        self.assertRaises(UnexpectedResponse, r.delete) 
Example #19
Source File: test_request.py    From pysnow with MIT License 5 votes vote down vote up
def test_delete_incident_multiple(self):
        """
        Make sure delete queries yielding more than 1 record fails
        """
        json_body_get = json.dumps(
            {
                "result": [
                    {"sys_id": self.mock_incident["sys_id"]},
                    {"sys_id": self.mock_incident["sys_id"]},
                ]
            }
        )
        httpretty.register_uri(
            httpretty.GET,
            "http://%s/%s" % (self.mock_connection["host"], self.mock_incident["path"]),
            body=json_body_get,
            status=200,
            content_type="application/json",
        )

        json_body_delete = json.dumps({"success": True})
        httpretty.register_uri(
            httpretty.DELETE,
            "http://%s/%s/%s"
            % (
                self.mock_connection["host"],
                self.mock_incident["path"],
                self.mock_incident["sys_id"],
            ),
            body=json_body_delete,
            status=204,
            content_type="application/json",
        )

        r = self.client.query(
            table="incident", query={"number": self.mock_incident["number"]}
        )
        self.assertRaises(MultipleResults, r.delete) 
Example #20
Source File: test_request.py    From pysnow with MIT License 5 votes vote down vote up
def test_delete_incident(self):
        """
        Delete an incident, make sure we get a 204 back along with expected body
        """
        httpretty.register_uri(
            httpretty.GET,
            "http://%s/%s" % (self.mock_connection["host"], self.mock_incident["path"]),
            body=json.dumps({"result": [{"sys_id": self.mock_incident["sys_id"]}]}),
            status=200,
            content_type="application/json",
        )

        httpretty.register_uri(
            httpretty.DELETE,
            "http://%s/%s/%s"
            % (
                self.mock_connection["host"],
                self.mock_incident["path"],
                self.mock_incident["sys_id"],
            ),
            body=json.dumps({"success": True}),
            status=204,
            content_type="application/json",
        )

        r = self.client.query(
            table="incident", query={"number": self.mock_incident["number"]}
        )
        result = r.delete()

        self.assertEqual(result["success"], True)
        self.assertEqual(r.status_code, 204) 
Example #21
Source File: test_model_integration.py    From stream-django with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_delete(self):
        self.register_post_api()
        self.register_delete_api()
        pin = models.Pin.objects.create(author=self.bogus)
        pin.delete()
        last_req = httpretty.last_request()
        self.assertEqual(last_req.method, httpretty.DELETE) 
Example #22
Source File: test_couch.py    From openag_python with GNU General Public License v3.0 4 votes vote down vote up
def test_replicate():
    # Start a replication
    server = Server("http://test.test:5984")
    httpretty.register_uri(
        httpretty.HEAD, "http://test.test:5984/_replicator"
    )
    httpretty.register_uri(
        httpretty.HEAD, "http://test.test:5984/_replicator/test",
        status=404
    )
    def replicate_test_src(request, uri, headers):
        httpretty.reset()
        httpretty.register_uri(
            httpretty.HEAD, "http://test.test:5984/_replicator"
        )
        httpretty.register_uri(
            httpretty.HEAD, "http://test.test:5984/_replicator/test",
            status=200, etag="a"
        )
        return 201, headers, json.dumps({
            "id": "test_src", "rev": "a", "ok": True
        })
    httpretty.register_uri(
        httpretty.PUT, "http://test.test:5984/_replicator/test",
        status=201, content_type="application/json", body=replicate_test_src
    )
    server.replicate("test", "test_src", "test_dest", continuous=True)
    assert "test" in server["_replicator"]

    # Make sure replicate is idempotent
    httpretty.register_uri(
        httpretty.PUT, "http://test.test:5984/_replicator/test_src",
        status=500
    )
    server.replicate("test", "test_src", "test_dest", continuous=True)
    assert "test" in server["_replicator"]

    # Cancel the replication
    def cancel_test_replication(request, uri, headers):
        httpretty.reset()
        httpretty.register_uri(
            httpretty.HEAD, "http://test.test:5984/_replicator"
        )
        httpretty.register_uri(
            httpretty.HEAD, "http://test.test:5984/_replicator/test",
            status=404
        )
        return 200, headers, ""
    httpretty.register_uri(
        httpretty.DELETE, "http://test.test:5984/_replicator/test",
        status=200, body=cancel_test_replication
    )
    server.cancel_replication("test")
    assert "test" not in server["_replicator"]