def test_normal_collect(self):
     self._logger.info('execute() enter')
     self._logger.getChild('db_source_collector').AndReturn(self._db_source_collector_logger)
     self._db_source_collector_logger.info('collect() enter')
     self._db_source_collector_logger.getChild('data_collector').AndReturn(self._data_collector_logger)
     self._data_collector_logger.info('collect_data(collect_task_list) enter')
     self._source_connection.cursor().AndReturn(self._source_cursor)
     self._data_collector_logger.getChild('collect_task').AndReturn(self._collect_task_logger)
     set_collect_data_expectations(self._collect_task_logger,
         self._source_cursor,
         ['q1', 'q2'],
         [[('cat1', 'data1'), ('cat2', 'data2')], [('cat1', 'data3')]])
     set_collect_data_expectations(self._collect_task_logger,
         self._source_cursor,
         ['q3'],
         [[('cat1', 'data1', 'subdata1'), ('cat2', 'data2', 'subdata2'), ('cat1', 'data3', 'subdata3')]])
     self._source_connection.close()
     self._data_collector_logger.info(u'collect_data(collect_task_list) exit')
     self._db_source_collector_logger.getChild('collect_task').AndReturn(self._collect_task_logger)
     save_items_list = [[DataItem(category='cat1', data='data1'), DataItem(category='cat2', data='data2'), DataItem(category='cat1', data='data3')],
         [DataItem(category='category.cat1', data='data1:subdata1'), DataItem(category='category.cat2', data='data2:subdata2'), DataItem(category='category.cat1', data='data3:subdata3')]]
     set_process_data_expectations(self._collect_task_logger, self._dest_storage, self._source_id, save_items_list)
     self._db_source_collector_logger.info('collect() exit')
     self._logger.info('execute() exit')
     self._mox.ReplayAll()
     self.assertTrue(self._collect_task.execute())
     self._mox.VerifyAll()
 def test_exception_when_process(self):
     self._logger.info('execute() enter')
     self._logger.getChild('db_source_collector').AndReturn(self._db_source_collector_logger)
     self._db_source_collector_logger.info('collect() enter')
     self._db_source_collector_logger.getChild('data_collector').AndReturn(self._data_collector_logger)
     self._data_collector_logger.info('collect_data(collect_task_list) enter')
     self._source_connection.cursor().AndReturn(self._source_cursor)
     self._data_collector_logger.getChild('collect_task').AndReturn(self._collect_task_logger)
     set_collect_data_expectations(self._collect_task_logger,
         self._source_cursor,
         ['q1', 'q2'],
         [[('cat1',), ('cat2',)], [('cat1',)]])
     set_collect_data_expectations(self._collect_task_logger,
         self._source_cursor,
         ['q3'],
         [[('cat1', 'data1', 'subdata1'), ('cat2', 'data2', 'subdata2'), ('cat1', 'data3', 'subdata3')]])
     self._source_connection.close()
     self._data_collector_logger.info(u'collect_data(collect_task_list) exit')
     self._db_source_collector_logger.getChild('collect_task').AndReturn(self._collect_task_logger)
     self._collect_task_logger.info('process_data() enter')
     self._collect_task_logger.exception('exception in process_data()')
     self._db_source_collector_logger.exception(u'exception in collect()')
     self._logger.exception('exception in execute()')
     self._mox.ReplayAll()
     self.assertFalse(self._collect_task.execute())
     self._mox.VerifyAll()
 def test_exception_when_save(self):
     self._logger.info('execute() enter')
     self._logger.getChild('db_source_collector').AndReturn(self._db_source_collector_logger)
     self._db_source_collector_logger.info('collect() enter')
     self._db_source_collector_logger.getChild('data_collector').AndReturn(self._data_collector_logger)
     self._data_collector_logger.info('collect_data(collect_task_list) enter')
     self._source_connection.cursor().AndReturn(self._source_cursor)
     self._data_collector_logger.getChild('collect_task').AndReturn(self._collect_task_logger)
     set_collect_data_expectations(self._collect_task_logger,
         self._source_cursor,
         ['q1', 'q2'],
         [[('cat1', 'data1'), ('cat2', 'data2')], [('cat1', 'data3')]])
     set_collect_data_expectations(self._collect_task_logger,
         self._source_cursor,
         ['q3'],
         [[('cat1', 'data1', 'subdata1'), ('cat2', 'data2', 'subdata2'), ('cat1', 'data3', 'subdata3')]])
     self._source_connection.close()
     self._data_collector_logger.info(u'collect_data(collect_task_list) exit')
     self._db_source_collector_logger.getChild('collect_task').AndReturn(self._collect_task_logger)
     self._collect_task_logger.info('process_data() enter')
     self._collect_task_logger.info('process_data() exit')
     save_data = [DataItem(category='cat1', data='data1'), DataItem(category='cat2', data='data2'), DataItem(category='cat1', data='data3')]
     self._dest_storage.save_data(self._source_id, save_data).AndRaise(CustomTestException())
     self._db_source_collector_logger.exception(u'exception in collect()')
     self._logger.exception('exception in execute()')
     self._mox.ReplayAll()
     self.assertFalse(self._collect_task.execute())
     self._mox.VerifyAll()