def test_should_parse_accepted_story(self): expected_date = datetime.date(2010, 11, 28) event = EventParser().parse(self.accepted_story_xml) self.assertTrue(event.is_accept_story_event()) self.assertFalse(event.is_create_story_event()) self.assertEqual(event.story_id, '6799253') self.assertEqual(event.accepted_date, expected_date)
def test_should_parse_new_story(self): event = EventParser().parse(self.new_story_xml) self.assertTrue(event.is_create_story_event()) self.assertFalse(event.is_accept_story_event()) self.assertEqual(event.story_id, '6798545') self.assertEqual(event.story_title, 'This is the title') self.assertEqual(event.story_type, 'feature')
def post(self): logging.info('Received event from Pivotal Tracker') event_xml = self.request.body logging.info('Event xml: ' + event_xml) event = EventParser().parse(event_xml) logging.info(str(event)) if event.is_create_story_event(): self._create_new_story(event) elif event.is_accept_story_event(): self._accept_story(event) elif event.is_name_update_event(): self._update_story_name(event) else: logging.info("Ignoring pivotal tracker update")
class EventProcessor(object): def __init__(self, options): self.event_parser = EventParser(options) output_type = options.get("output_type") self.output = None if output_type == "stdout": self.output = StdOutOutput() elif output_type == "file": self.output = FileOutput(options.get("outfile")) elif output_type == "tcp": (host, port) = options.get("tcpout").split(":") self.output = TcpOutput(host, int(port)) elif output_type == "udp": (host, port) = options.get("udpout").split(":") self.output = UdpOutput(host, int(port)) elif output_type == "s3": self.output = S3Output(options.get("s3out"), options.get("aws_key", None), options.get("aws_secret", None)) else: raise ValueError("Invalid output type: %s" % output_type) def process_event(self, content_type, routing_key, body): """ Parse an event from the Carbon Black event bus and write the resulting events to the configured output """ events = self.event_parser.parse_events(content_type, routing_key, body) for event in events: try: json_str = json.dumps(event) self.output.write(json_str) except TypeError as e: LOGGER.exception("Got an exception (%s) processing event (repr: %s)" % (e, repr(event)))
def __init__(self, options): self.event_parser = EventParser(options) output_type = options.get("output_type") self.output = None if output_type == "stdout": self.output = StdOutOutput() elif output_type == "file": self.output = FileOutput(options.get("outfile")) elif output_type == "tcp": (host, port) = options.get("tcpout").split(":") self.output = TcpOutput(host, int(port)) elif output_type == "udp": (host, port) = options.get("udpout").split(":") self.output = UdpOutput(host, int(port)) elif output_type == "s3": self.output = S3Output(options.get("s3out"), options.get("aws_key", None), options.get("aws_secret", None)) else: raise ValueError("Invalid output type: %s" % output_type)
class EventProcessor(object): def __init__(self, options): self.event_parser = EventParser(options) output_type = options.get("output_type") self.output = None if output_type == "stdout": self.output = StdOutOutput() elif output_type == "file": self.output = FileOutput(options.get("outfile")) elif output_type == "tcp": (host, port) = options.get("tcpout").split(":") self.output = TcpOutput(host, int(port)) elif output_type == "udp": (host, port) = options.get("udpout").split(":") self.output = UdpOutput(host, int(port)) elif output_type == "s3": self.output = S3Output(options.get("s3out"), options.get("aws_key", None), options.get("aws_secret", None)) else: raise ValueError("Invalid output type: %s" % output_type) def process_event(self, content_type, routing_key, body): """ Parse an event from the Carbon Black event bus and write the resulting events to the configured output """ events = self.event_parser.parse_events(content_type, routing_key, body) for event in events: try: json_str = json.dumps(event) self.output.write(json_str) except TypeError as e: LOGGER.exception( "Got an exception (%s) processing event (repr: %s)" % (e, repr(event)))
def test_should_parse_name_change(self): event = EventParser().parse(self.story_name_change) self.assertFalse(event.is_accept_story_event()) self.assertTrue(event.is_name_update_event()) self.assertEqual(event.story_id, '6806885') self.assertEqual(event.story_title, 'Big test story again')
def __init__(self, input): self.entry = EventParser.parse_webhook_event(input) self.parsed_input = EventParser.parse_message_event(self.entry, True)