def test_handler_run(self): func_cwd = self.get_temp_dir() output_temp = self.get_temp_dir() pdata = { 'name': 'dataset-created', 'resource': 'gcp.bq-dataset', 'mode': { 'type': 'gcp-audit', 'methods': ['datasetservice.insert'] } } with open(os.path.join(func_cwd, 'config.json'), 'w') as fh: fh.write(json.dumps({'policies': [pdata]})) event = event_data('bq-dataset-create.json') p = self.load_policy(pdata) from c7n.policy import PolicyCollection self.patch(PolicyCollection, 'from_data', staticmethod(lambda *args, **kw: [p])) self.patch(p, 'push', lambda evt, ctx: None) self.patch(handler, 'get_tmp_output_dir', lambda: output_temp) self.change_cwd(func_cwd) self.assertEqual(handler.run(event), True)
def test_handler_run(self, from_data): func_cwd = self.get_temp_dir() output_temp = self.get_temp_dir() pdata = { 'name': 'dataset-created', 'resource': 'gcp.bq-dataset', 'mode': { 'type': 'gcp-audit', 'methods': ['datasetservice.insert']}} with open(os.path.join(func_cwd, 'config.json'), 'w') as fh: fh.write(json.dumps({'policies': [pdata]})) event = event_data('bq-dataset-create.json') p = self.load_policy(pdata) self.patch(p, 'push', lambda evt, ctx: None) self.patch(handler, 'get_tmp_output_dir', lambda: output_temp) from_data.return_value = [p] self.change_cwd(func_cwd) self.assertEqual(handler.run(event), True)