def testLocations(self): iLocsName = self.ilocations[0]['theName'] iLocsDia = self.ilocations[0]['theDiagram'] iLocations = [] iLoc1 = self.ilocations[0]['theLocations'][0] iLoc1Name = iLoc1['theName'] iLoc1AssetInstances = [] iLoc1PersonaInstances = [] iLoc1Links = iLoc1['theLinks'] iLocations.append(Location(-1,iLoc1Name,iLoc1AssetInstances,iLoc1PersonaInstances,iLoc1Links)) iLoc2 = self.ilocations[0]['theLocations'][1] iLoc2Name = iLoc2['theName'] iLoc2AssetInstances = [(iLoc2['theAssetInstances'][0]['theName'],iLoc2['theAssetInstances'][0]['theAsset'])] iLoc2PersonaInstances = [(iLoc2['thePersonaInstances'][0]['theName'],iLoc2['thePersonaInstances'][0]['thePersona'])] iLoc2Links = iLoc2['theLinks'] iLocations.append(Location(-1,iLoc2Name,iLoc2AssetInstances,iLoc2PersonaInstances,iLoc2Links)) ilp = LocationsParameters(iLocsName,iLocsDia,iLocations) b = Borg() b.dbProxy.addLocations(ilp) oLocsDict = b.dbProxy.getLocations() oLocs = oLocsDict[ilp.name()] oLocsId = oLocs.id() oLocsDia = oLocs.diagram() oLocsLocations = oLocs.locations() self.assertEqual(iLocsDia,oLocsDia) oLocs1 = oLocsLocations[0] self.assertEqual(iLoc1Name,oLocs1.name()) self.assertEqual(iLoc1AssetInstances,oLocs1.assetInstances()) self.assertEqual(iLoc1PersonaInstances,oLocs1.personaInstances()) oLocs2 = oLocsLocations[1] self.assertEqual(iLoc2Name,oLocs2.name()) self.assertEqual(iLoc2AssetInstances,oLocs2.assetInstances()) self.assertEqual(iLoc2PersonaInstances,oLocs2.personaInstances()) ilp.setId(oLocsId) b.dbProxy.updateLocations(ilp) uLocsDict = b.dbProxy.getLocations() uLocs = uLocsDict[ilp.name()] uLocsId = uLocs.id() uLocsDia = uLocs.diagram() uLocsLocations = uLocs.locations() self.assertEqual(uLocsDia,oLocsDia) uLocs1 = uLocsLocations[0] self.assertEqual(uLocs1.name(),oLocs1.name()) self.assertEqual(uLocs1.assetInstances(),oLocs1.assetInstances()) self.assertEqual(uLocs1.personaInstances(),oLocs1.personaInstances()) b.dbProxy.deleteLocations(uLocsId)
def convert_loc_list(self,real_loc_list = None, fake_loc_list = None): new_loc_list = [] if real_loc_list is not None: if len(real_loc_list) > 0: for real_loc in real_loc_list: assert isinstance(real_loc,Location) loc_dict = {} loc_dict['theName'] = real_loc.name() loc_dict['theAssetInstances'] = [] for ai in real_loc.assetInstances(): loc_dict['theAssetInstances'].append({'theName':ai[0],'theAsset':ai[1]}) loc_dict['thePersonaInstances'] = [] for pi in real_loc.personaInstances(): loc_dict['thePersonaInstances'].append({'theName':pi[0],'thePersona':pi[1]}) loc_dict['theLinks'] = real_loc.links() new_loc_list.append(loc_dict) elif fake_loc_list is not None: if len(fake_loc_list) > 0: for fake_loc in fake_loc_list: check_required_keys(fake_loc,LocationModel.required) assetInstances = [] for ai in fake_loc['theAssetInstances']: assetInstances.append((ai['theName'],ai['theAsset'])) personaInstances = [] for pi in fake_loc['thePersonaInstances']: personaInstances.append((pi['theName'],pi['thePersona'])) new_loc_list.append(Location(-1,fake_loc['theName'],assetInstances,personaInstances,fake_loc['theLinks'])) else: self.close() raise MissingParameterHTTPError(param_names=['real_loc_list', 'fake_loc_list']) return new_loc_list
def endElement(self, name): if name == 'location': self.theLocations.append( Location(-1, self.theName, self.theAssetInstances, self.thePersonaInstances, self.theLinks)) self.theAssetInstances = [] self.thePersonaInstances = [] self.theLinks = []
def setUp(self): self.logger = logging.getLogger(__name__) f = open(os.environ['CAIRIS_SRC'] + '/test/locations.json') d = json.load(f) f.close() iLocations = d['locations'] newLocsName = iLocations[1]['theName'] newLocsDia = iLocations[1]['theDiagram'] newLocations = [] iLoc1 = iLocations[1]['theLocations'][0] iLoc1Name = iLoc1['theName'] iLoc1AssetInstances = [] iLoc1PersonaInstances = [] iLoc1Links = iLoc1['theLinks'] newLocations.append( Location(-1, iLoc1Name, iLoc1AssetInstances, iLoc1PersonaInstances, iLoc1Links)) iLoc2 = iLocations[1]['theLocations'][1] iLoc2Name = iLoc2['theName'] iLoc2AssetInstances = [{ 'theName': iLoc2['theAssetInstances'][0]['theName'], 'theAsset': iLoc2['theAssetInstances'][0]['theAsset'] }] iLoc2PersonaInstances = [{ 'theName': iLoc2['thePersonaInstances'][0]['theName'], 'thePersona': iLoc2['thePersonaInstances'][0]['thePersona'] }] iLoc2Links = iLoc2['theLinks'] newLocations.append( Location(-1, iLoc2Name, iLoc2AssetInstances, iLoc2PersonaInstances, iLoc2Links)) self.new_locs = Locations(locsId='-1', locsName=newLocsName, locsDiagram=newLocsDia, locs=newLocations) self.new_locs_dict = {'session_id': 'test', 'object': self.new_locs} self.existing_locs_name = 'PooleWWTW'
def endElement(self, name): if name == 'location': self.theLocations.append( Location(-1, self.theName, self.theAssetInstances, self.thePersonaInstances, self.theLinks)) self.resetLocationAttributes() elif name == 'locations': self.allLocations.append( LocationsParameters(self.theLocationsName, self.theDiagram, self.theLocations)) self.resetLocationsAttributes()