def make_observer_chain(ultimate_observer, indent): """ Return our feature observers wrapped our the ultimate_observer """ add_to_fanout( ObserverWrapper(JSONObserverWrapper(ultimate_observer, sort_keys=True, indent=indent or None), hostname=socket.gethostname())) return throttling_wrapper( SpecificationObserverWrapper( PEP3101FormattingWrapper( SystemFilterWrapper( ErrorFormattingWrapper(cf_id_wrapper(get_fanout()))))))
def test_add_cf_id_to_cloud_feeds_events(self): """ CF event dictionaries have an ID added to them, non-CF events do not. """ obs = [] id_observer = cf_id_wrapper(obs.append) id_observer({'cloud_feed': True, 'this': 'is a cf event'}) id_observer({'this': 'is not a cf event'}) def hex_repeat(num): return "[a-fA-F0-9]{{{num}}}".format(num=num) uuid_regex = "-".join([hex_repeat(i) for i in (8, 4, 4, 4, 12)]) self.assertEqual( obs, [{'cloud_feed': True, 'this': 'is a cf event', 'cloud_feed_id': matches(MatchesRegex(uuid_regex))}, {'this': 'is not a cf event'}])
def make_observer_chain(ultimate_observer, indent): """ Return our feature observers wrapped our the ultimate_observer """ add_to_fanout( ObserverWrapper( JSONObserverWrapper( ultimate_observer, sort_keys=True, indent=indent or None), hostname=socket.gethostname())) return throttling_wrapper( SpecificationObserverWrapper( PEP3101FormattingWrapper( SystemFilterWrapper( ErrorFormattingWrapper( cf_id_wrapper( get_fanout()))))))
def test_add_cf_id_to_cloud_feeds_events(self): """ CF event dictionaries have an ID added to them, non-CF events do not. """ obs = [] id_observer = cf_id_wrapper(obs.append) id_observer({'cloud_feed': True, 'this': 'is a cf event'}) id_observer({'this': 'is not a cf event'}) def hex_repeat(num): return "[a-fA-F0-9]{{{num}}}".format(num=num) uuid_regex = "-".join([hex_repeat(i) for i in (8, 4, 4, 4, 12)]) self.assertEqual(obs, [{ 'cloud_feed': True, 'this': 'is a cf event', 'cloud_feed_id': matches(MatchesRegex(uuid_regex)) }, { 'this': 'is not a cf event' }])