import unittest
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
        self.skip = False
        try:
            import pymysql
        except ImportError:
            self.skip = True

    def testChecks(self):
        if not self.skip:
            agentConfig = { 
                'version': '0.1',
                'api_key': 'toto' }

            conf = {'init_config': {}, 'instances': [{
                'server': 'localhost',
                'user': 'dog',
                'pass': 'dog',
                'options': {'replication': True},
            }]}
            # Initialize the check from checks.d
            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()

import unittest
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
        self.skip = False
        try:
            import pymysql
        except ImportError:
            self.skip = True

    def testChecks(self):
        if not self.skip:
            agentConfig = {
                'version': '0.1',
                'api_key': 'toto' }

            conf = {'init_config': {}, 'instances': [{
                'server': 'localhost',
                'user': 'dog',
                'pass': 'dog',
                'options': {'replication': True},
            }]}
            # Initialize the check from checks.d
            self.check = load_check('mysql', conf, agentConfig)

            self.check.run()
            metrics = self.check.get_metrics()
            self.assertTrue(len(metrics) >= 8, metrics)

            # Service checks
            service_checks = self.check.get_service_checks()
            service_checks_count = len(service_checks)
            self.assertTrue(type(service_checks) == type([]))
            self.assertTrue(service_checks_count > 0)
            self.assertEquals(len([sc for sc in service_checks if sc['check'] == "mysql.can_connect"]), 1, service_checks)
            # Assert that all service checks have the proper tags: host and port
            self.assertEquals(len([sc for sc in service_checks if "host:localhost" in sc['tags']]), service_checks_count, service_checks)
            self.assertEquals(len([sc for sc in service_checks if "port:0" in sc['tags']]), service_checks_count, service_checks)

            time.sleep(1)
            self.check.run()
            metrics = self.check.get_metrics()
            self.assertTrue(len(metrics) >= 16, metrics)


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

Add test for Mysql sc
Add test for Mysql sc

  import unittest
  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
          self.skip = False
          try:
              import pymysql
          except ImportError:
              self.skip = True
  
      def testChecks(self):
          if not self.skip:
-             agentConfig = { 
+             agentConfig = {
                  'version': '0.1',
                  'api_key': 'toto' }
  
              conf = {'init_config': {}, 'instances': [{
                  'server': 'localhost',
                  'user': 'dog',
                  'pass': 'dog',
                  'options': {'replication': True},
              }]}
              # Initialize the check from checks.d
              self.check = load_check('mysql', conf, agentConfig)
  
              self.check.run()
              metrics = self.check.get_metrics()
              self.assertTrue(len(metrics) >= 8, metrics)
+ 
+             # Service checks
+             service_checks = self.check.get_service_checks()
+             service_checks_count = len(service_checks)
+             self.assertTrue(type(service_checks) == type([]))
+             self.assertTrue(service_checks_count > 0)
+             self.assertEquals(len([sc for sc in service_checks if sc['check'] == "mysql.can_connect"]), 1, service_checks)
+             # Assert that all service checks have the proper tags: host and port
+             self.assertEquals(len([sc for sc in service_checks if "host:localhost" in sc['tags']]), service_checks_count, service_checks)
+             self.assertEquals(len([sc for sc in service_checks if "port:0" in sc['tags']]), service_checks_count, service_checks)
+ 
              time.sleep(1)
              self.check.run()
              metrics = self.check.get_metrics()
              self.assertTrue(len(metrics) >= 16, metrics)
-         
+ 
+ 
  if __name__ == '__main__':
      unittest.main()
  
Add test for Mysql sc
## Code Before:
import unittest
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
        self.skip = False
        try:
            import pymysql
        except ImportError:
            self.skip = True

    def testChecks(self):
        if not self.skip:
            agentConfig = { 
                'version': '0.1',
                'api_key': 'toto' }

            conf = {'init_config': {}, 'instances': [{
                'server': 'localhost',
                'user': 'dog',
                'pass': 'dog',
                'options': {'replication': True},
            }]}
            # Initialize the check from checks.d
            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()

## Instruction:
Add test for Mysql sc
## Code After:
import unittest
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
        self.skip = False
        try:
            import pymysql
        except ImportError:
            self.skip = True

    def testChecks(self):
        if not self.skip:
            agentConfig = {
                'version': '0.1',
                'api_key': 'toto' }

            conf = {'init_config': {}, 'instances': [{
                'server': 'localhost',
                'user': 'dog',
                'pass': 'dog',
                'options': {'replication': True},
            }]}
            # Initialize the check from checks.d
            self.check = load_check('mysql', conf, agentConfig)

            self.check.run()
            metrics = self.check.get_metrics()
            self.assertTrue(len(metrics) >= 8, metrics)

            # Service checks
            service_checks = self.check.get_service_checks()
            service_checks_count = len(service_checks)
            self.assertTrue(type(service_checks) == type([]))
            self.assertTrue(service_checks_count > 0)
            self.assertEquals(len([sc for sc in service_checks if sc['check'] == "mysql.can_connect"]), 1, service_checks)
            # Assert that all service checks have the proper tags: host and port
            self.assertEquals(len([sc for sc in service_checks if "host:localhost" in sc['tags']]), service_checks_count, service_checks)
            self.assertEquals(len([sc for sc in service_checks if "port:0" in sc['tags']]), service_checks_count, service_checks)

            time.sleep(1)
            self.check.run()
            metrics = self.check.get_metrics()
            self.assertTrue(len(metrics) >= 16, metrics)


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