本文整理汇总了Python中ralph.cmdb.models_ci.CI.save方法的典型用法代码示例。如果您正苦于以下问题:Python CI.save方法的具体用法?Python CI.save怎么用?Python CI.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ralph.cmdb.models_ci.CI
的用法示例。
在下文中一共展示了CI.save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reports_views
# 需要导入模块: from ralph.cmdb.models_ci import CI [as 别名]
# 或者: from ralph.cmdb.models_ci.CI import save [as 别名]
def test_reports_views(self):
url = '/ui/reports/services/'
report = self.client.get(url, follow=True)
self.assertEqual(report.status_code, 200)
invalid_relation = report.context['invalid_relation']
services_without_venture = report.context['services_without_venture']
self.assertEqual(invalid_relation[0].name, 'allegro.pl')
self.assertEqual(len(invalid_relation), 1)
self.assertEqual(len(services_without_venture), 0)
# local service for tests
service = CI(name='ceneo.pl', type=CIType.objects.get(
id=CI_TYPES.SERVICE)
)
service.save()
# local venture for tests
venture = CI(name='allegro_prod', type=CIType.objects.get(
id=CI_TYPES.VENTURE)
)
venture.save()
reload_report = self.client.get(url, follow=True)
re_invalid_relation = reload_report.context['invalid_relation']
re_services_without_venture = reload_report.context[
'services_without_venture']
self.assertEqual(len(re_invalid_relation), 1)
self.assertEqual(len(re_services_without_venture), 0)
示例2: ReportsServicesTest
# 需要导入模块: from ralph.cmdb.models_ci import CI [as 别名]
# 或者: from ralph.cmdb.models_ci.CI import save [as 别名]
class ReportsServicesTest(TestCase):
fixtures = [
'0_types.yaml',
'1_attributes.yaml',
'2_layers.yaml',
'3_prefixes.yaml'
]
def setUp(self):
self.client = login_as_su()
self.service = CI(
name='allegro.pl',
type=CIType.objects.get(id=CI_TYPES.SERVICE)
)
self.service.save()
self.db_service = CI.objects.get(id=self.service.id)
self.venture = CI(
name='allegro_prod',
type=CIType.objects.get(id=CI_TYPES.VENTURE)
)
self.venture.save()
self.ci_venture = CI.objects.get(id=self.venture.id)
self.relation = CIRelation(
parent=self.ci_venture,
child=self.db_service,
type=CI_RELATION_TYPES.CONTAINS,
)
self.relation.save()
def test_user_login(self):
self.assertTrue(self.client)
def test_reports_devices(self):
self.assertEqual(self.service.name, 'allegro.pl')
self.assertEqual(self.db_service.name, self.service.name)
def test_reports_venture(self):
self.assertEqual(self.venture.name, 'allegro_prod')
self.assertEqual(self.ci_venture.name, self.venture.name)
def test_reports_relation(self):
self.assertEqual(self.relation.child.type_id, CI_TYPES.SERVICE)
self.assertEqual(self.relation.parent.type_id, CI_TYPES.VENTURE)
self.assertNotEqual(self.relation.child.type_id, CI_TYPES.VENTURE)
def test_reports_views(self):
url = '/ui/reports/services/'
report = self.client.get(url, follow=True)
self.assertEqual(report.status_code, 200)
invalid_relation = report.context['invalid_relation']
services_without_venture = report.context['services_without_venture']
self.assertEqual(invalid_relation[0].name, 'allegro.pl')
self.assertEqual(len(invalid_relation), 1)
self.assertEqual(len(services_without_venture), 0)
# local service for tests
service = CI(name='ceneo.pl', type=CIType.objects.get(
id=CI_TYPES.SERVICE)
)
service.save()
# local venture for tests
venture = CI(name='allegro_prod', type=CIType.objects.get(
id=CI_TYPES.VENTURE)
)
venture.save()
reload_report = self.client.get(url, follow=True)
re_invalid_relation = reload_report.context['invalid_relation']
re_services_without_venture = reload_report.context['services_without_venture']
self.assertEqual(len(re_invalid_relation), 1)
self.assertEqual(len(re_services_without_venture), 0)
示例3: CMDBApiTest
# 需要导入模块: from ralph.cmdb.models_ci import CI [as 别名]
# 或者: from ralph.cmdb.models_ci.CI import save [as 别名]
class CMDBApiTest(TestCase):
def setUp(self):
self.create_user()
self.create_cilayers()
self.create_citypes()
self.create_owners()
self.create_cis()
self.create_ownerships()
self.create_relations()
def create_user(self):
self.user = User.objects.create_user(
'api_user',
'[email protected]',
'password'
)
self.user.save()
self.api_key = ApiKey.objects.get(user=self.user)
self.data = {
'format': 'json',
'username': self.user.username,
'api_key': self.api_key.key
}
cache.delete("api_user_accesses")
def create_cilayers(self):
self.cilayer1 = CILayer(name='layer1')
self.cilayer1.save()
self.cilayer2 = CILayer(name='layer2')
self.cilayer2.save()
def create_citypes(self):
self.citype1 = CIType(name='type1')
self.citype1.save()
self.citype2 = CIType(name='type2')
self.citype2.save()
def create_owners(self):
self.owner1 = CIOwner(
first_name='first_name_owner1',
last_name='last_name_owner1',
email='[email protected]'
)
self.owner1.save()
self.owner2 = CIOwner(
first_name='first_name_owner2',
last_name='last_name_owner2',
email='[email protected]'
)
self.owner2.save()
def create_cis(self):
self.ci1 = CI(
uid='uid-ci1',
type=self.citype1,
barcode='barcodeci1',
name='ciname1',
)
self.ci1.save()
self.ci1.layers = [self.cilayer1, self.cilayer2]
self.ci1.save()
self.ci2 = CI(
uid='uid-ci2',
type=self.citype2,
barcode='barcodeci2',
name='ciname2',
)
self.ci2.save()
self.ci2.layers = [self.cilayer1]
self.ci2.save()
self.ci3 = CI(
uid='other-ci3',
type=self.citype2,
barcode='otherbarcodeci3',
name='otherci',
)
self.ci3.save()
self.ci3.layers = [self.cilayer2]
self.ci3.save()
def create_ownerships(self):
self.ciownership1 = CIOwnership(
ci=self.ci1,
owner=self.owner1,
type=CIOwnershipType.technical
)
self.ciownership1.save()
self.ciownership2 = CIOwnership(
ci=self.ci1,
owner=self.owner2,
type=CIOwnershipType.business
)
self.ciownership2.save()
self.ciownership3 = CIOwnership(
ci=self.ci2,
owner=self.owner2,
type=CIOwnershipType.business
)
self.ciownership3.save()
#.........这里部分代码省略.........
示例4: CMDBApiTest
# 需要导入模块: from ralph.cmdb.models_ci import CI [as 别名]
# 或者: from ralph.cmdb.models_ci.CI import save [as 别名]
class CMDBApiTest(TestCase):
def setUp(self):
self.user = create_user("api_user", "[email protected]", "password")
self.layers = CILayer.objects.all()
self.types = CIType.objects.all()
self.create_owners()
self.create_cis()
self.create_ownerships()
self.create_attributes()
self.create_relations()
self.headers = {
"HTTP_ACCEPT": "application/json",
"HTTP_AUTHORIZATION": "ApiKey {}:{}".format(self.user.username, self.user.api_key.key),
}
cache.delete("api_user_accesses")
def create_owners(self):
self.owner1 = CIOwner(
first_name="first_name_owner1",
last_name="last_name_owner1",
email="[email protected]",
)
self.owner1.save()
self.owner2 = CIOwner(
first_name="first_name_owner2",
last_name="last_name_owner2",
email="[email protected]",
)
self.owner2.save()
def create_cis(self):
self.ci1 = CI(uid="uid-ci1", type=self.types[0], barcode="barcodeci1", name="ciname1")
self.ci1.save()
self.ci1.layers = [self.layers[0].id, self.layers[1].id]
self.ci1.save()
self.ci2 = CI(uid="uid-ci2", type=self.types[1], barcode="barcodeci2", name="ciname2")
self.ci2.save()
self.ci2.layers = [self.layers[0].id]
self.ci2.save()
self.ci3 = CI(uid="other-ci3", type=self.types[1], barcode="otherbarcodeci3", name="otherci")
self.ci3.save()
self.ci3.layers = [self.layers[1].id]
self.ci3.save()
def create_ownerships(self):
self.ciownership1 = CIOwnership(ci=self.ci1, owner=self.owner1, type=CIOwnershipType.technical)
self.ciownership1.save()
self.ciownership2 = CIOwnership(ci=self.ci1, owner=self.owner2, type=CIOwnershipType.business)
self.ciownership2.save()
self.ciownership3 = CIOwnership(ci=self.ci2, owner=self.owner2, type=CIOwnershipType.business)
self.ciownership3.save()
def create_relations(self):
self.relation1 = CIRelation(parent=self.ci1, child=self.ci2, type=CI_RELATION_TYPES.CONTAINS)
self.relation1.save()
self.relation2 = CIRelation(parent=self.ci2, child=self.ci3, type=CI_RELATION_TYPES.HASROLE)
self.relation2.save()
def create_attributes(self):
self.attribute1 = CIAttribute(name="Attribute 1", attribute_type=CI_ATTRIBUTE_TYPES.INTEGER, choices="")
self.attribute1.save()
self.attribute1.ci_types.add(self.types[0]),
self.attribute_value1 = CIAttributeValue(ci=self.ci1, attribute=self.attribute1)
self.attribute_value1.value = 10
self.attribute_value1.save()
def test_layers(self):
path = "/api/v0.9/cilayers/"
response = self.client.get(path=path, **self.headers)
json_string = response.content
json_data = json.loads(json_string)
resource_uris = [ci_layer["resource_uri"] for ci_layer in json_data["objects"]]
response = self.client.get(path=resource_uris[0], **self.headers)
json_string = response.content
json_data = json.loads(json_string)
self.assertEqual(json_data["name"], self.layers[0].name)
response = self.client.get(resource_uris[1], **self.headers)
json_string = response.content
json_data = json.loads(json_string)
self.assertEqual(json_data["name"], self.layers[1].name)
def test_types(self):
path = "/api/v0.9/citypes/"
response = self.client.get(path=path, **self.headers)
json_string = response.content
json_data = json.loads(json_string)
resource_uris = [ci_type["resource_uri"] for ci_type in json_data["objects"]]
response = self.client.get(path=resource_uris[0], **self.headers)
json_string = response.content
json_data = json.loads(json_string)
self.assertEqual(json_data["name"], self.types[0].name)
response = self.client.get(resource_uris[1], **self.headers)
json_string = response.content
json_data = json.loads(json_string)
self.assertEqual(json_data["name"], self.types[1].name)
#.........这里部分代码省略.........
示例5: CMDBApiTest
# 需要导入模块: from ralph.cmdb.models_ci import CI [as 别名]
# 或者: from ralph.cmdb.models_ci.CI import save [as 别名]
class CMDBApiTest(UserTestCase):
def setUp(self):
self.layers = CILayer.objects.all()
self.types = CIType.objects.all()
self.create_owners()
self.create_cis()
self.create_ownerships()
self.create_attributes()
self.create_relations()
super(CMDBApiTest, self).setUp()
def create_owners(self):
self.owner1 = CIOwnerFactory()
self.owner2 = CIOwnerFactory()
def create_cis(self):
self.ci1 = CI(
uid='uid-ci1',
type=self.types[0],
barcode='barcodeci1',
name='ciname1',
)
self.ci1.save()
self.ci1.layers = [self.layers[0].id, self.layers[1].id]
self.ci1.save()
self.ci2 = CI(
uid='uid-ci2',
type=self.types[1],
barcode='barcodeci2',
name='ciname2',
)
self.ci2.save()
self.ci2.layers = [self.layers[0].id]
self.ci2.save()
self.ci3 = CI(
uid='other-ci3',
type=self.types[1],
barcode='otherbarcodeci3',
name='otherci',
)
self.ci3.save()
self.ci3.layers = [self.layers[1].id]
self.ci3.save()
def create_ownerships(self):
self.ciownership1 = CIOwnership(
ci=self.ci1,
owner=self.owner1,
type=CIOwnershipType.technical,
)
self.ciownership1.save()
self.ciownership2 = CIOwnership(
ci=self.ci1,
owner=self.owner2,
type=CIOwnershipType.business,
)
self.ciownership2.save()
self.ciownership3 = CIOwnership(
ci=self.ci2,
owner=self.owner2,
type=CIOwnershipType.business,
)
self.ciownership3.save()
def create_relations(self):
self.relation1 = CIRelation(
parent=self.ci1,
child=self.ci2,
type=CI_RELATION_TYPES.CONTAINS,
)
self.relation1.save()
self.relation2 = CIRelation(
parent=self.ci2,
child=self.ci3,
type=CI_RELATION_TYPES.HASROLE,
)
self.relation2.save()
def create_attributes(self):
self.attribute1 = CIAttribute(
name='Attribute 1', attribute_type=CI_ATTRIBUTE_TYPES.INTEGER,
choices='',
)
self.attribute1.save()
self.attribute1.ci_types.add(self.types[0]),
self.attribute_value1 = CIAttributeValue(
ci=self.ci1, attribute=self.attribute1,
)
self.attribute_value1.value = 10
self.attribute_value1.save()
def test_layers(self):
path = "/api/v0.9/cilayers/"
response = self.get(path)
json_string = response.content
json_data = json.loads(json_string)
resource_uris = [
ci_layer['resource_uri'] for ci_layer in json_data['objects']
]
#.........这里部分代码省略.........