import unittest
import logging; logger = logging.getLogger()

from checks.db.mysql import MySql

class TestMySql(unittest.TestCase):
    def setUp(self):
        # This should run on pre-2.7 python so no skiptest
        try:
            import MySQLdb
            self.mysql = MySql(logger)
        except ImportError:
            self.skip = True

    def testChecks(self):
        if not self.skip:
            results = self.mysql.check({"mysql_server": "localhost", "mysql_user": "dog", "mysql_pass": "dog"})
            assert results

if __name__ == '__main__':
    unittest.main()

import unittest
import logging; logger = logging.getLogger()

from checks.db.mysql import MySql
from tests.common import load_check
import time

class TestMySql(unittest.TestCase):

    def testChecks(self):
        agentConfig = { 'mysql_server': 'localhost',
            'mysql_user': "datadog",
            'mysql_pass': "phQOrbaXem0kP8JHri1qSMRS",
            'version': '0.1',
            'api_key': 'toto' }

        # Initialize the check from checks.d
        c = load_check('mysql', {'init_config': {}, 'instances':{}},agentConfig)
        conf = c.parse_agent_config(agentConfig)
        self.check = load_check('mysql', conf, agentConfig)

        self.check.run()
        metrics = self.check.get_metrics()
        self.assertTrue(len(metrics) >= 8, metrics)
        time.sleep(1)
        self.check.run()
        metrics = self.check.get_metrics()
        self.assertTrue(len(metrics) >= 16, metrics)
        
if __name__ == '__main__':
    unittest.main()

Fix mysql check to use checks.d version
Fix mysql check to use checks.d version
  import unittest
  import logging; logger = logging.getLogger()
  
  from checks.db.mysql import MySql
+ from tests.common import load_check
+ import time
  
  class TestMySql(unittest.TestCase):
-     def setUp(self):
-         # This should run on pre-2.7 python so no skiptest
-         try:
-             import MySQLdb
-             self.mysql = MySql(logger)
-         except ImportError:
-             self.skip = True
  
      def testChecks(self):
-         if not self.skip:
-             results = self.mysql.check({"mysql_server": "localhost", "mysql_user": "dog", "mysql_pass": "dog"})
-             assert results
+         agentConfig = { 'mysql_server': 'localhost',
+             'mysql_user': "datadog",
+             'mysql_pass': "phQOrbaXem0kP8JHri1qSMRS",
+             'version': '0.1',
+             'api_key': 'toto' }
  
+         # Initialize the check from checks.d
+         c = load_check('mysql', {'init_config': {}, 'instances':{}},agentConfig)
+         conf = c.parse_agent_config(agentConfig)
+         self.check = load_check('mysql', conf, agentConfig)
+ 
+         self.check.run()
+         metrics = self.check.get_metrics()
+         self.assertTrue(len(metrics) >= 8, metrics)
+         time.sleep(1)
+         self.check.run()
+         metrics = self.check.get_metrics()
+         self.assertTrue(len(metrics) >= 16, metrics)
+         
  if __name__ == '__main__':
      unittest.main()
  
Fix mysql check to use checks.d version
## Code Before:
import unittest
import logging; logger = logging.getLogger()

from checks.db.mysql import MySql

class TestMySql(unittest.TestCase):
    def setUp(self):
        # This should run on pre-2.7 python so no skiptest
        try:
            import MySQLdb
            self.mysql = MySql(logger)
        except ImportError:
            self.skip = True

    def testChecks(self):
        if not self.skip:
            results = self.mysql.check({"mysql_server": "localhost", "mysql_user": "dog", "mysql_pass": "dog"})
            assert results

if __name__ == '__main__':
    unittest.main()

## Instruction:
Fix mysql check to use checks.d version
## Code After:
import unittest
import logging; logger = logging.getLogger()

from checks.db.mysql import MySql
from tests.common import load_check
import time

class TestMySql(unittest.TestCase):

    def testChecks(self):
        agentConfig = { 'mysql_server': 'localhost',
            'mysql_user': "datadog",
            'mysql_pass': "phQOrbaXem0kP8JHri1qSMRS",
            'version': '0.1',
            'api_key': 'toto' }

        # Initialize the check from checks.d
        c = load_check('mysql', {'init_config': {}, 'instances':{}},agentConfig)
        conf = c.parse_agent_config(agentConfig)
        self.check = load_check('mysql', conf, agentConfig)

        self.check.run()
        metrics = self.check.get_metrics()
        self.assertTrue(len(metrics) >= 8, metrics)
        time.sleep(1)
        self.check.run()
        metrics = self.check.get_metrics()
        self.assertTrue(len(metrics) >= 16, metrics)
        
if __name__ == '__main__':
    unittest.main()
