def create_tables(): """Create the tables for the objects if they exist.""" try_db_connect() try_es_connect() create_elastic_index() for obj in ORM_OBJECTS: if not obj.table_exists(): obj.create_table() obj.create_elastic_mapping() DB.close()
def test_existing_elastic_index(self): """Test the create elastic index.""" response_body = { 'status': 'created!' } httpretty.register_uri(httpretty.PUT, 'http://127.0.0.1:9200/pacifica', body=dumps(response_body), content_type='application/json') create_elastic_index() self.assertEqual(httpretty.last_request().method, 'PUT')
def test_existing_elastic_index(self): """ Test the create elastic index """ response_body = { "status": "created!" } httpretty.register_uri(httpretty.GET, "http://127.0.0.1:9200/pacifica", body=dumps(response_body), content_type="application/json") create_elastic_index() self.assertEqual(httpretty.last_request().method, "GET")
def create_tables(): """ Create the tables for the objects if they exist. """ try_db_connect() try_es_connect() create_elastic_index() for obj in ORM_OBJECTS: if not obj.table_exists(): obj.create_table() obj.create_elastic_mapping() DB.close()
def test_error_elastic_index(self): """ Test the create elastic index """ response_body = {} created_body = { "status": "ERROR" } httpretty.register_uri(httpretty.GET, "http://127.0.0.1:9200/pacifica", body=dumps(response_body), content_type="application/json", status=404) httpretty.register_uri(httpretty.PUT, "http://127.0.0.1:9200/pacifica", body=dumps(created_body), content_type="application/json", status=500) #pylint: disable=broad-except try: create_elastic_index() except Exception, ex: self.assertEqual(httpretty.last_request().method, "PUT") self.assertEqual(str(ex), "create_elastic_index: 500\n")
def test_error_elastic_index(self): """Test the create elastic index.""" hit_exception = False response_body = {} created_body = { 'status': 'ERROR' } httpretty.register_uri(httpretty.GET, 'http://127.0.0.1:9200/pacifica', body=dumps(response_body), content_type='application/json', status=404) httpretty.register_uri(httpretty.PUT, 'http://127.0.0.1:9200/pacifica', body=dumps(created_body), content_type='application/json', status=500) # pylint: disable=broad-except try: create_elastic_index() except Exception as ex: hit_exception = True self.assertEqual(httpretty.last_request().method, 'PUT') self.assertEqual(str(ex), 'TransportError(500, u\'{"status": "ERROR"}\')') # pylint: enable=broad-except self.assertTrue(hit_exception)