Beispiel #1
0
 def test_init(self):
     """Testing method init."""
     # Test with non existent AgentNameIDX
     record = db_agentname.GetIDXAgentName(-1)
     self.assertEqual(record.exists(), False)
     self.assertEqual(record.name(), None)
     self.assertEqual(record.idx_agentname(), None)
     self.assertEqual(record.enabled(), None)
Beispiel #2
0
class TestGetIDX(unittest.TestCase):
    """Checks all functions and methods."""

    #########################################################################
    # General object setup
    #########################################################################

    # Setup database based on the config
    database = unittest_setup_db.TestData()

    # Define expected values
    expected = {}
    expected['idx_agentname'] = database.idx_agentname()
    expected['name'] = database.agent()
    expected['enabled'] = True
    expected['exists'] = True

    # Retrieve data
    good_agent = db_agentname.GetIDXAgentName(expected['idx_agentname'])

    def test_init(self):
        """Testing method init."""
        # Test with non existent AgentNameIDX
        record = db_agentname.GetIDXAgentName(-1)
        self.assertEqual(record.exists(), False)
        self.assertEqual(record.name(), None)
        self.assertEqual(record.idx_agentname(), None)
        self.assertEqual(record.enabled(), None)

    def test_name(self):
        """Testing method name."""
        # Testing with known good value
        result = self.good_agent.name()
        self.assertEqual(result, self.expected['name'])

        # Testing with known bad value
        expected = ('bogus')
        result = self.good_agent.name()
        self.assertNotEqual(result, expected)

    def test_idx_agentname(self):
        """Testing method idx."""
        # Testing with known good value
        result = self.good_agent.idx_agentname()
        self.assertEqual(result, self.expected['idx_agentname'])

        # Testing with known bad value
        expected = ('bogus')
        result = self.good_agent.idx_agentname()
        self.assertNotEqual(result, expected)

    def test_exists(self):
        """Testing method exists."""
        # Testing with known good value
        result = self.good_agent.exists()
        self.assertEqual(result, self.expected['exists'])

    def test_enabled(self):
        """Testing method enabled."""
        # Testing with known good value
        result = self.good_agent.enabled()
        self.assertEqual(result, self.expected['enabled'])

        # Testing with known bad value
        expected = ('bogus')
        result = self.good_agent.enabled()
        self.assertNotEqual(result, expected)

    def test_everything(self):
        """Testing method everything."""
        # Testing with known good value
        result = self.good_agent.everything()
        for key, _ in self.expected.items():
            self.assertEqual(result[key], self.expected[key])

        # Test the number and names of keys
        keys = ['idx_agentname', 'name', 'enabled', 'exists']
        self.assertEqual(len(result), len(keys))
        for key in keys:
            self.assertEqual(key in result, True)