test: add some test cases

This commit is contained in:
penzai
2020-02-16 18:03:33 +08:00
parent 7b3f95b41d
commit b798d5e2cc
5 changed files with 237 additions and 3 deletions

View File

@@ -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]}