def test_groups(self): group1 = core.get_node_model(self.neo4jdb, handle_id='121') contact1 = core.get_node_model(self.neo4jdb, handle_id='115') group1.add_member(contact1.handle_id) relations = contact1.get_outgoing_relations() self.assertIsInstance(relations['Member_of'][0]['node'], models.GroupModel)
def test_detach_contact(self): role1 = core.get_node_model(self.neo4jdb, handle_id='117') organization1 = core.get_node_model(self.neo4jdb, handle_id='113') organization1.remove_role_from_contacts(role1.data['name']) contact1 = core.get_node_model(self.neo4jdb, handle_id='115') relations = contact1.get_outgoing_relations() self.assertTrue('Is' not in relations)
def test_set_parent(self): organization1 = core.get_node_model(self.neo4jdb, handle_id='113') organization2 = core.get_node_model(self.neo4jdb, handle_id='114') organization2.set_parent(organization1.handle_id) relations = organization2.get_relations() self.assertIsInstance(relations['Parent_of'][0]['node'], models.OrganizationModel)
def test_set_and_get_peering_group_peering_partner_model(self): peering_partner1 = core.get_node_model(self.neo4jdb, handle_id='8') peering_group2 = core.get_node_model(self.neo4jdb, handle_id='44') peering_partner1.set_peering_group(peering_group2.handle_id, ip_address='127.0.0.2') peering_groups = peering_partner1.get_peering_group( peering_group2.handle_id, ip_address='127.0.0.2') self.assertEqual(len(peering_groups['Uses']), 1)
def test_set_and_get_group_dependency_peering_group_model(self): peering_group2 = core.get_node_model(self.neo4jdb, handle_id='44') unit2 = core.get_node_model(self.neo4jdb, handle_id='5') peering_group2.set_group_dependency(unit2.handle_id, ip_address='127.0.0.3') dependencies = peering_group2.get_group_dependency( unit2.handle_id, ip_address='127.0.0.3') self.assertEqual(len(dependencies['Depends_on']), 1)
def test_set_and_get_host_service_host_model(self): host2 = core.get_node_model(self.neo4jdb, handle_id='33') host_service1 = core.get_node_model(self.neo4jdb, handle_id='43') result = host2.set_host_service(host_service1.handle_id, ip_address='127.0.0.1', port='443', protocol='tcp') self.assertEqual(result['Depends_on'][0]['created'], True) host_services = host2.get_host_services() self.assertEqual(len(host_services['Depends_on']), 1)
def test_get_placement_path(self): # Models with placement path physical2 = core.get_node_model(self.neo4jdb, handle_id='102') placement_path = physical2.get_placement_path() self.assertEqual(placement_path['placement_path'][0]['name'], 'Physical1') # Model without placement path relation1 = core.get_node_model(self.neo4jdb, handle_id='106') location_path = relation1.get_placement_path() self.assertEqual(location_path['placement_path'], [])
def test_get_location_path(self): # Model with location physical1 = core.get_node_model(self.neo4jdb, handle_id='101') location_path = physical1.get_location_path() self.assertEqual(location_path['location_path'][0]['name'], 'Location1') self.assertEqual(location_path['location_path'][1]['name'], 'Location2') # Model without location relation1 = core.get_node_model(self.neo4jdb, handle_id='106') location_path = relation1.get_location_path() self.assertEqual(location_path['location_path'], [])
def test_uses_a_procedure(self): organization1 = core.get_node_model(self.neo4jdb, handle_id='113') organization2 = core.get_node_model(self.neo4jdb, handle_id='114') procedure1 = core.get_node_model(self.neo4jdb, handle_id='119') procedure2 = core.get_node_model(self.neo4jdb, handle_id='120') relations1 = procedure1.get_relations() self.assertIsInstance(relations1['Uses_a'][0]['node'], models.OrganizationModel) organization2.add_procedure(procedure2.handle_id) relations2 = procedure2.get_relations() self.assertIsInstance(relations2['Uses_a'][0]['node'], models.OrganizationModel)
def test_set_owner_physical_model(self): router1 = core.get_node_model(self.neo4jdb, handle_id='1') customer4 = core.get_node_model(self.neo4jdb, handle_id='37') result = router1.set_owner(customer4.handle_id) self.assertEqual(result['Owns'][0]['created'], True) relations = router1.get_relations() self.assertEqual(len(relations['Owns']), 2) # Do not accept duplicates result = router1.set_owner(customer4.handle_id) self.assertEqual(result['Owns'][0]['created'], False) relations = router1.get_relations() self.assertEqual(len(relations['Owns']), 2)
def test_set_and_get_has_physical_model(self): router1 = core.get_node_model(self.neo4jdb, handle_id='1') port8 = core.get_node_model(self.neo4jdb, handle_id='40') result = router1.set_has(port8.handle_id) self.assertEqual(result['Has'][0]['created'], True) children = router1.get_has() self.assertEqual(len(children['Has']), 3) # Do not accept duplicates result = router1.set_has(port8.handle_id) self.assertEqual(result['Has'][0]['created'], False) children = router1.get_has() self.assertEqual(len(children['Has']), 3)
def test_set_and_get_part_of_physical_model(self): port8 = core.get_node_model(self.neo4jdb, handle_id='40') unit1 = core.get_node_model(self.neo4jdb, handle_id='3') result = port8.set_part_of(unit1.handle_id) self.assertEqual(result['Part_of'][0]['created'], True) children = port8.get_part_of() self.assertEqual(len(children['Part_of']), 1) # Do not accept duplicates result = port8.set_part_of(unit1.handle_id) self.assertEqual(result['Part_of'][0]['created'], False) children = port8.get_part_of() self.assertEqual(len(children['Part_of']), 1)
def test_set_location_physical_model(self): router1 = core.get_node_model(self.neo4jdb, handle_id='1') rack_2 = core.get_node_model(self.neo4jdb, handle_id='15') result = router1.set_location(rack_2.handle_id) self.assertEqual(result['Located_in'][0]['created'], True) location = router1.get_location() self.assertEqual(len(location['Located_in']), 2) # Do not accept duplicates result = router1.set_location(rack_2.handle_id) self.assertEqual(result['Located_in'][0]['created'], False) location = router1.get_location() self.assertEqual(len(location['Located_in']), 2)
def test_set_connected_to_cable_model(self): cable6 = core.get_node_model(self.neo4jdb, handle_id='45') port7 = core.get_node_model(self.neo4jdb, handle_id='27') result = cable6.set_connected_to(port7.handle_id) self.assertEqual(result['Connected_to'][0]['created'], True) relationships = cable6.relationships self.assertEqual(len(relationships['Connected_to']), 1) # Do not accept duplicates result = cable6.set_connected_to(port7.handle_id) self.assertEqual(result['Connected_to'][0]['created'], False) relationships = cable6.relationships self.assertEqual(len(relationships['Connected_to']), 1)
def test_set_and_get_has_location_model(self): site1 = core.get_node_model(self.neo4jdb, handle_id='11') rack_4 = core.get_node_model(self.neo4jdb, handle_id='41') result = site1.set_has(rack_4.handle_id) self.assertEqual(result['Has'][0]['created'], True) children = site1.get_has() self.assertEqual(len(children['Has']), 3) # Do not accept duplicates result = site1.set_has(rack_4.handle_id) self.assertEqual(result['Has'][0]['created'], False) children = site1.get_has() self.assertEqual(len(children['Has']), 3)
def test_get_location(self): # Model with location physical1 = core.get_node_model(self.neo4jdb, handle_id='101') location = physical1.get_location() self.assertIsInstance(location['Located_in'][0]['node'], models.LocationModel) self.assertEqual(location['Located_in'][0]['node'].data['name'], 'Location2') self.assertIsInstance(location['Located_in'][0]['relationship_id'], int) # Model without location relation1 = core.get_node_model(self.neo4jdb, handle_id='106') location = relation1.get_location() self.assertIsNone(location.get('Located_in'))
def test_set_user_logical_model(self): customer4 = core.get_node_model(self.neo4jdb, handle_id='37') service4 = core.get_node_model(self.neo4jdb, handle_id='38') result = service4.set_user(customer4.handle_id) self.assertEqual(result['Uses'][0]['created'], True) relations = service4.get_relations() self.assertEqual(len(relations['Uses']), 1) self.assertEqual(relations['Uses'][0]['node'].handle_id, customer4.handle_id) # Do not accept duplicates result = service4.set_user(customer4.handle_id) self.assertEqual(result['Uses'][0]['created'], False) relations = service4.get_relations() self.assertEqual(len(relations['Uses']), 1)
def test_get_location_path_unit_model(self): unit1 = core.get_node_model(self.neo4jdb, handle_id='3') location_path = unit1.get_location_path() self.assertEqual(location_path['location_path'][0]['name'], 'Site1') self.assertEqual(location_path['location_path'][1]['name'], 'Rack1') self.assertEqual(location_path['location_path'][2]['name'], 'Router1') self.assertEqual(location_path['location_path'][3]['name'], 'Port1')
def test_delete(self): node_model_1 = core.get_node_model(self.neo4jdb, handle_id='101') node_model_1.delete() self.assertRaises(exceptions.NodeNotFound, core.get_node_model, self.neo4jdb, handle_id='101')
def test_get_services_cable_model(self): cable1 = core.get_node_model(self.neo4jdb, handle_id='28') services = cable1.get_services() self.assertEqual(len(services), 1) self.assertEqual(services[0]['service']['name'], 'Service2') self.assertIsInstance(services[0]['users'], list) self.assertEqual(services[0]['users'][0]['name'], 'Customer2')
def test_switch_type(self): node_model_1 = core.get_node_model(self.neo4jdb, handle_id='101') self.assertIn('Generic', node_model_1.labels) node_model_1 = node_model_1.switch_type(old_type='Generic', new_type='New_Type') self.assertNotIn('Generic', node_model_1.labels) self.assertIn('New_Type', node_model_1.labels)
def test_get_connections_equipment_model(self): odf2 = core.get_node_model(self.neo4jdb, handle_id='25') connections = odf2.get_connections() self.assertEqual(len(connections), 4) for connection in connections: self.assertIsNotNone(connection['porta']) self.assertIsNotNone(connection['cable'])
def test_get_connections_subequipment_model(self): port4 = core.get_node_model(self.neo4jdb, handle_id='24') connections = port4.get_connections() self.assertEqual(len(connections), 2) for connection in connections: self.assertIsNotNone(connection['porta']) self.assertIsNotNone(connection['cable'])
def test_set_responsible_for_location_model(self): rack_4 = core.get_node_model(self.neo4jdb, handle_id='41') provider_2 = core.get_node_model(self.neo4jdb, handle_id='39') result = rack_4.set_responsible_for(provider_2.handle_id) self.assertEqual(result['Responsible_for'][0]['created'], True) relations = rack_4.get_relations() self.assertEqual(len(relations['Responsible_for']), 1) self.assertEqual(relations['Responsible_for'][0]['node'].handle_id, provider_2.handle_id) # Do not accept duplicates result = rack_4.set_responsible_for(provider_2.handle_id) self.assertEqual(result['Responsible_for'][0]['created'], False) relations = rack_4.get_relations() self.assertEqual(len(relations['Responsible_for']), 1)
def test_get_ports_equipment_model(self): odf1 = core.get_node_model(self.neo4jdb, handle_id='23') ports = odf1.get_ports() self.assertIsInstance(ports, dict) self.assertEqual(len(ports['Has']), 1) for rel_type, items in ports.items(): self.assertEqual(len(items), 1)
def test_get_dependents(self): logical1 = core.get_node_model(self.neo4jdb, handle_id='103') dependents = logical1.get_dependents() self.assertEqual(len(dependents['Depends_on']), 1) self.assertEqual(dependents['Depends_on'][0]['node'].handle_id, '107') self.assertIsInstance(dependents['Depends_on'][0]['node'], models.LogicalModel)
def test_set_provider_logical_model(self): provider_1 = core.get_node_model(self.neo4jdb, handle_id='6') service4 = core.get_node_model(self.neo4jdb, handle_id='38') result = service4.set_provider(provider_1.handle_id) self.assertEqual(result['Provides'][0]['created'], True) relations = service4.get_relations() self.assertEqual(len(relations['Provides']), 1) self.assertEqual(relations['Provides'][0]['node'].handle_id, provider_1.handle_id) # Do not accept duplicates result = service4.set_provider(provider_1.handle_id) self.assertEqual(result['Provides'][0]['created'], False) relations = service4.get_relations() self.assertEqual(len(relations['Provides']), 1)
def test_set_dependency_logical_model(self): optical_path1 = core.get_node_model(self.neo4jdb, handle_id='20') service4 = core.get_node_model(self.neo4jdb, handle_id='38') result = service4.set_dependency(optical_path1.handle_id) self.assertEqual(result['Depends_on'][0]['created'], True) relations = service4.get_dependencies() self.assertEqual(len(relations['Depends_on']), 1) self.assertEqual(relations['Depends_on'][0]['node'].handle_id, optical_path1.handle_id) # Do not accept duplicates result = service4.set_dependency(optical_path1.handle_id) self.assertEqual(result['Depends_on'][0]['created'], False) relations = service4.get_dependencies() self.assertEqual(len(relations['Depends_on']), 1)
def test_get_outgoing_relations(self): contact1 = core.get_node_model(self.neo4jdb, handle_id='115') relations = contact1.get_outgoing_relations() self.assertIsInstance(relations['Works_for'][0]['node'], models.OrganizationModel) self.assertIsInstance(relations['Is'][0]['node'], models.RoleModel)
def test_set_provider_physical_model(self): router1 = core.get_node_model(self.neo4jdb, handle_id='1') provider_2 = core.get_node_model(self.neo4jdb, handle_id='39') result = router1.set_provider(provider_2.handle_id) self.assertEqual(result['Provides'][0]['created'], True) relations = router1.get_relations() self.assertEqual(len(relations['Provides']), 1) self.assertEqual(relations['Provides'][0]['node'].handle_id, provider_2.handle_id) # Do not accept duplicates result = router1.set_provider(provider_2.handle_id) self.assertEqual(result['Provides'][0]['created'], False) relations = router1.get_relations() self.assertEqual(len(relations['Provides']), 1)
def test_get_node_model(self): node_model = core.get_node_model(self.neo4jdb, handle_id='1') self.assertIsInstance(node_model, models.LogicalModel)