def test_delete(self): """ Test the delete class method """ url = "http://127.0.0.1:9200/pacifica/ElasticAPI/127" obj = ElasticAPI() obj.id = 127 response_body = { "status": "deleted!" } httpretty.register_uri(httpretty.DELETE, url, body=dumps(response_body), content_type="application/json") ElasticAPI.elastic_delete(obj) self.assertEqual(httpretty.last_request().method, "DELETE")
def test_failed_delete(self): """ Test the delete class method failed upload """ url = "http://127.0.0.1:9200/pacifica/ElasticAPI/127" obj = ElasticAPI() obj.id = 127 response_body = { "status": "error!" } httpretty.register_uri(httpretty.DELETE, url, body=dumps(response_body), content_type="application/json", status=500) #pylint: disable=broad-except try: ElasticAPI.elastic_delete(obj) except Exception, ex: self.assertEqual(httpretty.last_request().method, "DELETE") self.assertEqual(str(ex), "elastic_delete_obj: 500\n")