Ejemplo n.º 1
0
    def test_02(self):
        job_cfg = ProcessConfiguration()
        job_cfg.load_dict({
            ProcessConfiguration.Props.SITE_CODE: 'unit-test',
            ProcessConfiguration.Props.REPORT_TO: '*****@*****.**',
            ProcessConfiguration.Props.SERVER: {
                ProcessConfiguration.Props.HOST: 'unittest',
                ProcessConfiguration.Props.AUTH: {
                    ProcessConfiguration.Props.LOGIN: '******',
                    ProcessConfiguration.Props.PASSWORD: '******'
                }
            }
        })
        job_parms = {
            PARM_EXTRACT_DATE: datetime.datetime(2015, 11, 03, 0, 0)
        }
        job = DWHEventsExportJob(jobname='unittest', jobid=42, config=job_cfg, parms=job_parms)
        # avoid cluttering unit tests report with logging
        job.log_setLevel(logging.ERROR)

        count, files = self.filter.export_events(events=self.events)
        arch_name = job.create_archive(files, datetime.datetime(2015, 11, 04, 0, 0))
        self.assertTrue(arch_name)
        self.assertTrue(os.path.isfile(arch_name))

        try:
            job._archive = arch_name
            job.send_data()

            self.assertIsNotNone(self.tmp)
            arch = zipfile.ZipFile(self.tmp.name)
            self.assertTrue(arch.filelist)
            self.assertEqual(len(arch.filelist), 5)

        finally:
            job.cleanup()
Ejemplo n.º 2
0
    def setUp(self):
        self.process = DWHVariableDefinitionsExportProcess()
        self.process_cfg = ProcessConfiguration()
        self.process_cfg.load_dict({
            ProcessConfiguration.Props.SITE_CODE: 'unit-test',
            ProcessConfiguration.Props.REPORT_TO: '*****@*****.**',
            ProcessConfiguration.Props.SERVER: {
                ProcessConfiguration.Props.HOST: 'unittest',
                ProcessConfiguration.Props.AUTH: {
                    ProcessConfiguration.Props.LOGIN: '******',
                    ProcessConfiguration.Props.PASSWORD: '******'
                }
            }
        })
        # avoid cluttering unit tests report with logging
        self.process.logger.setLevel(logging.ERROR)

        # monkey patch requests module
        requests.post = self.mock_post
Ejemplo n.º 3
0
if __name__ == '__main__':
    gs = pycstbox.config.GlobalSettings()

    pycstbox.log.setup_logging()
    _logger = pycstbox.log.getLogger(name=SCRIPT_NAME)

    # process CLI args
    parser = pycstbox.cli.get_argument_parser(
        description=__doc__
    )
    args = parser.parse_args()

    pycstbox.log.set_loglevel_from_args(_logger, args)

    _logger.info('loading process configuration')
    process_cfg = ProcessConfiguration()

    # Loads the configuration parameters
    try:
        process_cfg.load(pycstbox.config.make_config_file_path(CONFIG_FILE_NAME))

    except ConfigParser.Error as e:
        _logger.fatal('configuration error (%s)', e)
        sys.exit(1)

    else:
        _logger.debug('--> %s:', process_cfg.as_dict())

        worker = Worker(process_cfg, args.debug)
        worker.run()
Ejemplo n.º 4
0
class TestProcess01(unittest.TestCase):
    devcfg_name = 'device_config_01.json'
    enabled_outputs_cnt = 7

    class MockResponse(object):
        ok = None
        message = None

    def mock_post(self, url, data=None, **kwargs):
        data.seek(0)

        tmp = tempfile.NamedTemporaryFile(suffix='.json', delete=False)
        tmp.write(data.read())
        tmp.close()
        self.tmp = tmp

        resp = self.MockResponse()
        resp.ok = True
        resp.text = json.dumps({'message': 'OK'})

        return resp

    @classmethod
    def setUpClass(cls):
        devcfg.METADATA_HOME = fixture_path('devcfg.d')
        cls.dev_cfg = DeviceNetworkConfiguration(fixture_path(cls.devcfg_name), autoload=True)
        cls.vars_meta = json.load(file(fixture_path('vars_metadata.json')))

    def setUp(self):
        self.process = DWHVariableDefinitionsExportProcess()
        self.process_cfg = ProcessConfiguration()
        self.process_cfg.load_dict({
            ProcessConfiguration.Props.SITE_CODE: 'unit-test',
            ProcessConfiguration.Props.REPORT_TO: '*****@*****.**',
            ProcessConfiguration.Props.SERVER: {
                ProcessConfiguration.Props.HOST: 'unittest',
                ProcessConfiguration.Props.AUTH: {
                    ProcessConfiguration.Props.LOGIN: '******',
                    ProcessConfiguration.Props.PASSWORD: '******'
                }
            }
        })
        # avoid cluttering unit tests report with logging
        self.process.logger.setLevel(logging.ERROR)

        # monkey patch requests module
        requests.post = self.mock_post

    def test_01(self):
        rc = self.process.run(self.process_cfg, self.dev_cfg, self.vars_meta)
        self.assertEqual(rc, 0)

        try:
            with file(self.tmp.name) as fp:
                defs = json.load(fp)

            self.assertEqual(len(defs), self.enabled_outputs_cnt)
            d = dict([
                (entry['varname'], entry) for entry in defs
            ])
            for v in self.vars_meta:
                self.assertIn(v, d)

        finally:
            os.remove(self.tmp.name)
Ejemplo n.º 5
0
if __name__ == '__main__':
    gs = pycstbox.config.GlobalSettings()

    pycstbox.log.setup_logging()
    log = pycstbox.log.getLogger(name=SCRIPT_NAME)

    # process CLI args
    parser = pycstbox.cli.get_argument_parser(
        description=__doc__
    )
    args = parser.parse_args()

    pycstbox.log.set_loglevel_from_args(log, args)

    log.info('loading process configuration')
    process_cfg = ProcessConfiguration()

    # Loads the configuration parameters
    try:
        process_cfg.load(pycstbox.config.make_config_file_path(CONFIG_FILE_NAME))

    except ConfigParser.Error as e:
        log.fatal('configuration error (%s)', e)
        sys.exit(1)

    else:
        log.info('initializing export process')
        process = DWHVariableDefinitionsExportProcess()
        process.log_setLevel_from_args(args)

        try: