def post(self): try: body = json.loads(self.request.body.decode("utf-8")) envId = None envName = None if "id" in body: envId = body["id"] if "name" in body: envName = body["name"] # TODO replace by true authorization authorization = get_autorisation(envId, None, None) env = get_env_list(authorization).create_env(envId, envName) self.write_and_set_status( { "id": env.id, "name": env.name, "securityType": "basic" }, HTTPStatus.OK) except EnvAlreadyExistWithSameIdException: self.write_and_set_status( {MESSAGE: "env with the same id already exists"}, HTTPStatus.CONFLICT) except Exception: trace = traceback.format_exc().splitlines() self.write_and_set_status( { MESSAGE: "Internal server error", TRACE: trace }, HTTPStatus.INTERNAL_SERVER_ERROR)
def tearDownClass(cls): try: authorization = BaseAuthorization("unittest_", None, None, None) envList1 = get_env_list(authorization) # envList1.delete_env("unittest_") except: pass
def test_create_env(self): es = get_es_conn() es_wait_ready() sett = get_settings() authorization1 = BaseAuthorization("unitenvtest", None, None, None) envList1 = get_env_list(authorization1) authorization2 = BaseAuthorization("unitenvtest2", None, None, None) envList2 = get_env_list(authorization2) envList1.create_env("unitenvtest") envList1.create_env("unitenvtest2", "My Super env") envList2.delete_env("unitenvtest") envList2.delete_env("unitenvtest2") time.sleep(1) envList1.create_env("unitenvtest") envList2.delete_env("unitenvtest")
def post(self): try: envId = get_env_id() authorization = get_autorisation(envId, None, None) envList = get_env_list(authorization) env = envList.get_env(envId) envList.delete_env(env.id) es_wait_ready() sleep(5) env = get_env_list(authorization).create_env(env.id, env.name) es_wait_ready() self.write_and_set_status(None, HTTPStatus.OK) except Exception: trace = traceback.format_exc().splitlines() self.write({ MESSAGE: "Internal server error", TRACE: trace }, HTTPStatus.INTERNAL_SERVER_ERROR)
def set_up_environment(): try: es_wait_ready() envId = get_env_id() authorization = get_autorisation(envId, None, None) envList = get_env_list(authorization) envList.get_env(envId) except EnvNotFoundException: es_wait_ready() envList.create_env(envId)
def setup_unittest_environment(self): try: setting = get_settings() self.envId = "unittest_" self.authorization = BaseAuthorization("unittest_", None, None, None) self.envList1 = get_env_list(self.authorization) try: self.envList1.create_env(self.envId) except EnvAlreadyExistWithSameIdException: time.sleep(1) self.envList1.delete_env(self.envId) self.envList1.create_env(self.envId) finally: pass
def delete(self, envId): try: authorization = get_autorisation(envId, None, None) env = get_env_list(authorization).delete_env(envId) self.write_and_set_status(None, HTTPStatus.NO_CONTENT) except EnvNotFoundException: self.write_and_set_status( {MESSAGE: "env with id : {0} doest exists".format(envId)}, HTTPStatus.NOT_FOUND) except Exception: trace = traceback.format_exc().splitlines() self.write_and_set_status( { MESSAGE: "Internal server error", TRACE: trace }, HTTPStatus.INTERNAL_SERVER_ERROR)
def setUpClass(cls): try: global envIdReadOnly global authorizationReadOnly setting = get_settings() authorizationReadOnly = BaseAuthorization("unitsearch_", None, None, None) envList1 = get_env_list(authorizationReadOnly) try: envList1.create_env(envIdReadOnly) MyTestCase.populateData() except EnvAlreadyExistWithSameIdException: # pass # Read only so we dont need to change it if it exists. # If search environment exists we do dothing envList1.delete_env(envIdReadOnly) envList1.create_env(envIdReadOnly) MyTestCase.populateData() finally: pass
def get(self, envId): try: authorization = get_autorisation(envId, None, None) env = get_env_list(authorization).get_env(envId) self.write_and_set_status( json.dumps({ "id": env.id, "name": env.name, "securityType": "basic" }), HTTPStatus.OK) except EnvNotFoundException: self.write_and_set_status( {MESSAGE: "env with id : {0} doest exists".format(envId)}, HTTPStatus.NOT_FOUND) except Exception: trace = traceback.format_exc().splitlines() self.write_and_set_status( { MESSAGE: "Internal server error", TRACE: trace }, HTTPStatus.INTERNAL_SERVER_ERROR)