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'}}
     )
Exemple #2
0
    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)
Exemple #3
0
    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)
Exemple #4
0
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)
Exemple #6
0
 def __init__(self, context):
     self.context_merger = ContextMerger(context)
Exemple #7
0
 def to_context(request, options={}):
     default_context = ContextDefault(
         request, options.get('cookies')).call()
     return ContextMerger.call(default_context, options.get('context', {}))
Exemple #8
0
 def setup_context(self, request):
     default_context = ContextDefault(request, self.cookies).call()
     return ContextMerger(default_context).call(
         self.options.get('context', dict()))