def test_delete_ci_type(session, client): ci_type_ins = init_ci_types(1)[0] url = "/api/v0.1/ci_types/" + str(ci_type_ins.id) resp = client.delete(url) assert resp.status_code == 200 # attr should be soft delete ci_type_ins = CIType.get_by_id(ci_type_ins.id) assert ci_type_ins.deleted is True assert ci_type_ins.deleted_at
def get(cls, key): if key is None: return ct = cache.get("CIType::ID::{0}".format(key)) or \ cache.get("CIType::Name::{0}".format(key)) or \ cache.get("CIType::Alias::{0}".format(key)) if ct is None: ct = CIType.get_by(name=key, first=True, to_dict=False) or \ CIType.get_by_id(key) or \ CIType.get_by(alias=key, first=True, to_dict=False) if ct is not None: cls.set(ct) return ct
def get(cls, key): if key is None: return ct = cache.get(cls.PREFIX_NAME.format(key)) ct = ct or cache.get(cls.PREFIX_ID.format(key)) ct = ct or cache.get(cls.PREFIX_ALIAS.format(key)) if ct is None: ct = CIType.get_by(name=key, first=True, to_dict=False) ct = ct or CIType.get_by_id(key) ct = ct or CIType.get_by(alias=key, first=True, to_dict=False) if ct is not None: cls.set(ct) return ct
def test_update_ci_type(session, client): ci_type_ins = init_ci_types(1)[0] url = "/api/v0.1/ci_types/" + str(ci_type_ins.id) payload = { "name": "update", } resp = client.put(url, json=payload) # check resp status code and content assert resp.status_code == 200 assert resp.json["type_id"] == ci_type_ins.id # check ci_type updated in database ci_type_ins = CIType.get_by_id(ci_type_ins.id) assert ci_type_ins.name == "update"
def test_create_ci_type(session, client): attr = init_attributes(1)[0] url = "/api/v0.1/ci_types" payload = { "name": "test", "alias": "测试", "unique_key": attr.id } resp = client.post(url, json=payload) # check resp status code and content assert resp.status_code == 200 assert resp.json["type_id"] # check there is a attribute in database type_id = resp.json["type_id"] ci_type_ins = CIType.get_by_id(type_id) assert ci_type_ins.id == type_id assert ci_type_ins.name == "test" assert ci_type_ins.alias == "测试" assert ci_type_ins.unique_id == attr.id
def check_is_existed(key): ci_type = CITypeCache.get(key) or abort( 404, "CIType <{0}> is not existed".format(key)) return CIType.get_by_id(ci_type.id)