def testConnectionUniverseGetFindings(self): context = findings_lib.FileContext('{0}/file.yaml'.format(_GOOD_PATH)) folder = connection_lib.ConnectionFolder(_GOOD_PATH) folder.AddFinding( findings_lib.InconsistentFileLocationError('', context)) namespace = folder.local_namespace namespace.AddFinding( findings_lib.DuplicateConnectionDefinitionError( connection_lib.Connection('FEEDS'), base_lib.GLOBAL_NAMESPACE)) connection = connection_lib.Connection('FEEDS', 'description') connection.AddFinding( findings_lib.MissingConnectionDescriptionWarning(connection)) namespace.InsertConnection(connection) connection_universe = connection_lib.ConnectionUniverse([folder]) findings = connection_universe.GetFindings() self.assertLen(findings, 3) self.assertTrue( connection_universe.HasFindingTypes([ findings_lib.InconsistentFileLocationError, findings_lib.DuplicateConnectionDefinitionError, findings_lib.MissingConnectionDescriptionWarning ])) self.assertFalse(connection_universe.IsValid())
def testConnectionFolderAddDuplicateConnectionFails(self): folder = connection_lib.ConnectionFolder(_GOOD_PATH) folder.AddConnection(connection_lib.Connection('FEEDS', 'description')) self.assertIn('FEEDS', folder.local_namespace.connections) self.assertEmpty(folder.local_namespace.GetFindings()) folder.AddConnection(connection_lib.Connection('FEEDS', 'duplicate')) self.assertIsInstance(folder.local_namespace.GetFindings()[0], findings_lib.DuplicateConnectionDefinitionError)
def testConnectionEquals(self): connection_one = connection_lib.Connection('FEEDS', 'description') connection_one_dup = connection_lib.Connection('FEEDS', 'description') connection_one_no_desc = connection_lib.Connection('FEEDS', '') connection_two = connection_lib.Connection('CONTAINS', 'description') self.assertEqual(connection_one, connection_one_dup) self.assertNotEqual(connection_one, connection_one_no_desc) self.assertNotEqual(connection_one, connection_two)
def testConnectionUniverseGetConnectionsMap(self): folder = connection_lib.ConnectionFolder(_GOOD_PATH) namespace = folder.local_namespace namespace.InsertConnection(connection_lib.Connection('FEEDS', 'one')) namespace.InsertConnection(connection_lib.Connection( 'CONTAINS', 'two')) connection_universe = connection_lib.ConnectionUniverse([folder]) connections = connection_universe.GetConnectionsMap( base_lib.GLOBAL_NAMESPACE) self.assertIn('FEEDS', connections) self.assertIn('CONTAINS', connections)
def testConnectionFolderAddInvalidConnectionFails(self): folder = connection_lib.ConnectionFolder(_GOOD_PATH) folder.AddConnection( connection_lib.Connection('bad-connection', 'invalid')) self.assertNotIn('bad-connection', folder.local_namespace.connections) self.assertIsInstance(folder.GetFindings()[0], findings_lib.IllegalCharacterError)
def testConnectionUniverseConnectionIsDefined(self): folder = connection_lib.ConnectionFolder(_GOOD_PATH) namespace = folder.local_namespace namespace.InsertConnection(connection_lib.Connection('FEEDS', 'one')) connection_universe = connection_lib.ConnectionUniverse([folder]) self.assertTrue(connection_universe.IsDefined('FEEDS')) self.assertFalse(connection_universe.IsDefined('CONTAINS'))
def testConnectionFolderAddValidConnection(self): folder = connection_lib.ConnectionFolder(_GOOD_PATH) folder.AddConnection(connection_lib.Connection('FEEDS', 'description')) self.assertIn('FEEDS', folder.local_namespace.connections) self.assertEmpty(folder.GetFindings())
def testConnectionWithNoDescriptionHasFindings(self): connection = connection_lib.Connection('FEEDS', '') self.assertIsInstance(connection.GetFindings()[0], findings_lib.MissingConnectionDescriptionWarning)
def testConnectionWithIllegalNameHasFindings(self): connection = connection_lib.Connection('bad-connection', 'invalid') self.assertIsInstance(connection.GetFindings()[0], findings_lib.IllegalCharacterError)
def testConnectionWithIllegalKeyTypeHasFindings(self): connection = connection_lib.Connection(False, 'invalid') self.assertIsInstance(connection.GetFindings()[0], findings_lib.IllegalKeyTypeError)