mirror of
https://github.com/veops/cmdb.git
synced 2025-08-08 16:37:03 +08:00
test: add some test cases
This commit is contained in:
@@ -3,7 +3,14 @@
|
||||
import uuid
|
||||
import random
|
||||
|
||||
from api.models.cmdb import Attribute, CIType, CITypeAttributeGroup, CITypeAttribute
|
||||
from api.models.cmdb import (
|
||||
Attribute,
|
||||
CIType,
|
||||
CITypeAttributeGroup,
|
||||
CITypeAttribute,
|
||||
CITypeRelation,
|
||||
RelationType
|
||||
)
|
||||
|
||||
|
||||
def init_attributes(num=1):
|
||||
@@ -12,7 +19,7 @@ def init_attributes(num=1):
|
||||
attrs.append(Attribute.create(
|
||||
name=uuid.uuid4().hex[:8],
|
||||
alias=uuid.uuid4().hex[:8],
|
||||
value_type=str(random.randint(0, 100) % 7)
|
||||
value_type=str(random.randint(0, 100) % 3)
|
||||
))
|
||||
return attrs
|
||||
|
||||
@@ -47,3 +54,37 @@ def init_attribute_groups(num=1):
|
||||
order=i
|
||||
))
|
||||
return ags
|
||||
|
||||
|
||||
def init_relation_type(num=1):
|
||||
result = []
|
||||
for i in range(num):
|
||||
result.append(RelationType.create(
|
||||
name=uuid.uuid4().hex[:8],
|
||||
))
|
||||
return result
|
||||
|
||||
|
||||
def init_ci_type_relation(num=1):
|
||||
result = []
|
||||
ci_types = init_ci_types(num+1)
|
||||
relation_types = init_relation_type(num)
|
||||
for i in range(num):
|
||||
result.append(CITypeRelation.create(
|
||||
parent_id=ci_types[i].id,
|
||||
child_id=ci_types[i+1].id,
|
||||
relation_type_id=relation_types[i].id
|
||||
))
|
||||
return result
|
||||
|
||||
|
||||
def fake_attr_value(attr_dict):
|
||||
attr_type = attr_dict["value_type"]
|
||||
attr_name = attr_dict["name"]
|
||||
|
||||
if attr_type == "0":
|
||||
return {attr_name: random.randint(0, 1000)}
|
||||
elif attr_type == "1":
|
||||
return {attr_name: random.randint(0, 1000) / 3.0}
|
||||
elif attr_type == "2":
|
||||
return {attr_name: uuid.uuid4().hex[:8]}
|
||||
|
Reference in New Issue
Block a user