def test_call(self): params = {'foo': {'foo': 'bar', 'nonfoo': 'nonbar'}, 'to_remove': 'ok'} self.assertEqual( ContextMerger.call( params, {'foo': {'foo': 'foo'}, 'to_remove': None}), {'foo': {'foo': 'foo', 'nonfoo': 'nonbar'}} )
def build(self, options): ValidatorsPresent.call(options, 'event') context = ContextMerger.call(self.context, options.get('context')) context = ContextSanitizer.call(context) options.update({'sent_at': timestamp(), 'context': context}) return Command(method='post', path='track', data=options)
def build(self, options): ValidatorsPresent.call(options, 'user_id') ValidatorsNotSupported.call(options, 'properties') context = ContextMerger.call(self.context, options.get('context')) context = ContextSanitizer.call(context) options.update({'sent_at': timestamp(), 'context': context}) return Command(method='post', path='identify', data=options)
class WithContext(object): def __init__(self, context): self.context_merger = ContextMerger(context) def build_context(self, options): sanitize_active_mode(options) options['context'] = self.merge_context(options.get('context', dict())) return options def merge_context(self, context): return self.context_merger.call(context)
def build(self, options): ValidatorsPresent.call(options, 'user_id') context = ContextMerger.call(self.context, options.get('context')) context = ContextSanitizer.call(context) ValidatorsPresent.call(context, 'user_agent', 'ip') options.update({'sent_at': timestamp(), 'context': context}) method = ('delete' if options.get('reset', False) else 'post') return Command(method=method, path='impersonate', data=options)
def __init__(self, context): self.context_merger = ContextMerger(context)
def to_context(request, options={}): default_context = ContextDefault( request, options.get('cookies')).call() return ContextMerger.call(default_context, options.get('context', {}))
def setup_context(self, request): default_context = ContextDefault(request, self.cookies).call() return ContextMerger(default_context).call( self.options.get('context', dict()))