コード例 #1
0
    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())
コード例 #2
0
 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)
コード例 #3
0
 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)
コード例 #4
0
    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)
コード例 #5
0
 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)
コード例 #6
0
    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'))
コード例 #7
0
 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())
コード例 #8
0
 def testConnectionWithNoDescriptionHasFindings(self):
     connection = connection_lib.Connection('FEEDS', '')
     self.assertIsInstance(connection.GetFindings()[0],
                           findings_lib.MissingConnectionDescriptionWarning)
コード例 #9
0
 def testConnectionWithIllegalNameHasFindings(self):
     connection = connection_lib.Connection('bad-connection', 'invalid')
     self.assertIsInstance(connection.GetFindings()[0],
                           findings_lib.IllegalCharacterError)
コード例 #10
0
 def testConnectionWithIllegalKeyTypeHasFindings(self):
     connection = connection_lib.Connection(False, 'invalid')
     self.assertIsInstance(connection.GetFindings()[0],
                           findings_lib.IllegalKeyTypeError)