Esempio n. 1
0
 def get(cls, key):
     if key is None:
         return
     ct = cache.get("RelationType::ID::{0}".format(key)) or \
         cache.get("RelationType::Name::{0}".format(key))
     if ct is None:
         ct = RelationType.get_by(
             name=key, first=True,
             to_dict=False) or RelationType.get_by_id(key)
         if ct is not None:
             cls.set(ct)
     return ct
Esempio n. 2
0
 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))
     if ct is None:
         ct = RelationType.get_by(
             name=key, first=True,
             to_dict=False) or RelationType.get_by_id(key)
         if ct is not None:
             cls.set(ct)
     return ct
Esempio n. 3
0
def init_relation_type(num=1):
    result = []
    for i in range(num):
        result.append(RelationType.create(
            name=uuid.uuid4().hex[:8],
        ))
    return result
def test_create_relation_type_name_strip(session, client):
    url = "/api/v0.1/relation_types"
    payload = {
        "name": "test\t   ",
    }

    resp = client.post(url, json=payload)

    assert resp.status_code == 200
    assert resp.json["id"]

    relation_types_id = resp.json["id"]
    relation_type = RelationType.get_by_id(relation_types_id)
    assert relation_type.name == "test"
def test_update_relation_type(session, client):
    relation_type_ins = init_relation_type(1)[0]

    url = "/api/v0.1/relation_types/" + str(relation_type_ins.id)
    payload = {
        "name": "update",
    }

    resp = client.put(url, json=payload)

    assert resp.status_code == 200
    assert resp.json["id"] == relation_type_ins.id

    relation_type_ins = RelationType.get_by_id(relation_type_ins.id)
    assert relation_type_ins.name == "update"
Esempio n. 6
0
 def get_all():
     return RelationType.get_by(to_dict=False)
Esempio n. 7
0
    def delete(rel_id):
        existed = RelationType.get_by_id(rel_id) or abort(
            404, "RelationType <{0}> does not exist".format(rel_id))

        existed.soft_delete()
Esempio n. 8
0
    def update(rel_id, name):
        existed = RelationType.get_by_id(rel_id) or abort(
            404, "RelationType <{0}> does not exist".format(rel_id))

        return existed.update(name=name)
Esempio n. 9
0
 def add(name):
     RelationType.get_by(name=name, first=True, to_dict=False) and abort(
         400, "It's already existed")
     return RelationType.create(name=name)