Esempio n. 1
0
    def test_fail__update_product_versions(self):
        with patch('socorro.cron.newtcbs.logger'):
            cursor = self.connection.cursor()
            cursor.execute("""
            CREATE OR REPLACE FUNCTION update_product_versions()
            RETURNS boolean AS $$
            BEGIN
                    RETURN false;
            END;
            $$ LANGUAGE plpgsql;
            """)
            self.connection.commit()

            newtcbs.update(self.config, datetime.datetime.today())
            cursor = self.connection.cursor()
            for each in ('newtcbs:update_os_versions',
                         'newtcbs:update_adu',
                         'newtcbs:update_signatures',
                         ):
                cursor.execute(
                  'select last_success from cronjobs where cronjob=%s',
                  [each]
                )
                last_success = cursor.fetchone()[0]
                self.assertTrue(last_success)

            for each in ('newtcbs:update_product_versions',
                         'newtcbs:update_tcbs',
                         ):
                cursor.execute(
                  'select last_success from cronjobs where cronjob=%s',
                  [each]
                )
                last_success = cursor.fetchone()[0]
                self.assertTrue(not last_success)
Esempio n. 2
0
 def test_all_works(self):
     cursor = mock_cursor({})
     newtcbs.psycopg2 = mock_psycopg2(cursor)
     with patch('socorro.cron.newtcbs.logger') as mock_logger:
         newtcbs.update(self.config, 'some date')
         self.assertEqual(mock_logger.info.call_count, 6)
         self.assertEqual(mock_logger.warn.call_count, 0)
         self.assertEqual(mock_logger.error.call_count, 0)
Esempio n. 3
0
 def test_mock_internal_error(self):
     cursor = mock_cursor({
       'update_signatures': psycopg2.InternalError,
     })
     newtcbs.psycopg2 = mock_psycopg2(cursor)
     with patch('socorro.cron.newtcbs.logger') as mock_logger:
         newtcbs.update(self.config, 'some date')
         self.assertEqual(mock_logger.info.call_count, 5)
         self.assertEqual(mock_logger.warn.call_count, 1)
         self.assertEqual(mock_logger.error.call_count, 1)
Esempio n. 4
0
 def test_failing__update_product_versions(self):
     cursor = mock_cursor({
       'update_product_versions': (False,),
     })
     newtcbs.psycopg2 = mock_psycopg2(cursor)
     with patch('socorro.cron.newtcbs.logger') as mock_logger:
         newtcbs.update(self.config, 'some date')
         self.assertEqual(cursor.called, [
           'update_product_versions', 'update_signatures',
           'update_os_versions', 'update_adu', 'update_daily_crashes'
         ])
         self.assertEqual(mock_logger.info.call_count, 5)
         self.assertEqual(mock_logger.warn.call_count, 2)
         self.assertEqual(mock_logger.error.call_count, 0)
Esempio n. 5
0
 def test_all_works_without_errors(self):
     with patch('socorro.cron.newtcbs.logger'):
         newtcbs.update(self.config, datetime.datetime.today())
         cursor = self.connection.cursor()
         for each in ('newtcbs:update_product_versions',
                      'newtcbs:update_os_versions',
                      'newtcbs:update_adu',
                      'newtcbs:update_tcbs',
                      'newtcbs:update_signatures',
                      ):
             cursor.execute(
               'select last_success from cronjobs where cronjob=%s',
               [each]
             )
             last_success = cursor.fetchone()[0]
             self.assertTrue(last_success)
Esempio n. 6
0
except ImportError:
    import newtcbsconfig as configModule

import socorro.lib.ConfigurationManager as configurationManager
import socorro.cron.newtcbs as newtcbs
import socorro.lib.util as sutil

try:
    config = configurationManager.newConfiguration(
        configurationModule=configModule, applicationName="newTCBS 0.1")
except configurationManager.NotAnOptionError, x:
    print >>sys.stderr, x
    print >>sys.stderr, "for usage, try --help"
    sys.exit()

logger = logging.getLogger("newtcbs")
logger.setLevel(logging.DEBUG)

sutil.setupLoggingHandlers(logger, config)
sutil.echoConfig(logger, config)

exitCode = 255

try:
    targetDate = date.today() - timedelta(1)
    exitCode = newtcbs.update(config, targetDate)
finally:
    logger.info("done.")

sys.exit(exitCode)