Ejemplo n.º 1
0
    def test_call_no_event(self):
        context = {}
        options = default_options()
        options.pop('event')

        with self.assertRaises(InvalidParametersError):
            CommandsTrack(context).call(options)
Ejemplo n.º 2
0
    def test_call_properties_allowed(self):
        context = {}
        options = default_options_plus(properties={'face': 'handsome'})
        options.update({'context': context})

        expected = default_command_with_data(**options)

        self.assertEqual(CommandsTrack(context).call(options), expected)
Ejemplo n.º 3
0
 def test_build_active_false(self):
     payload = default_payload()
     payload.update(context={'active': False})
     command = CommandsTrack({}).build(payload)
     self.assertIsInstance(command, Command)
     self.assertEqual(command.method, 'post')
     self.assertEqual(command.endpoint, 'track')
     self.assertEqual(command.data, payload)
Ejemplo n.º 4
0
    def test_call_user_traits_allowed(self):
        context = {}
        options = default_options_plus(
            user_traits={'email': '*****@*****.**'})
        options.update({'context': context})

        expected = default_command_with_data(**options)

        self.assertEqual(CommandsTrack(context).call(options), expected)
Ejemplo n.º 5
0
    def test_call(self):
        context = {'lang': 'es'}
        options = default_options_plus(context={'local time': '8:53pm'})

        # expect the original context to have been merged with the context specified in the options
        expected_data = UtilsClone.call(options)
        expected_data.update(context={'lang': 'es', 'local time': '8:53pm'})
        expected = default_command_with_data(**expected_data)

        self.assertEqual(CommandsTrack(context).call(options), expected)
Ejemplo n.º 6
0
 def test_build_traits(self):
     payload = default_payload()
     payload.update(traits={'test': '1'})
     command_data = default_payload()
     command_data.update(traits={'test': '1'}, context={})
     command = CommandsTrack({}).build(payload)
     self.assertIsInstance(command, Command)
     self.assertEqual(command.method, 'post')
     self.assertEqual(command.endpoint, 'track')
     self.assertEqual(command.data, command_data)
Ejemplo n.º 7
0
 def test_build_user_id(self):
     payload = default_payload()
     payload.update(user_id='1234')
     command_data = default_payload()
     command_data.update(user_id='1234', context={})
     command = CommandsTrack({}).build(payload)
     self.assertIsInstance(command, Command)
     self.assertEqual(command.method, 'post')
     self.assertEqual(command.endpoint, 'track')
     self.assertEqual(command.data, command_data)
Ejemplo n.º 8
0
 def test_init(self):
     context = mock.sentinel.test_init_context
     obj = CommandsTrack(context)
     self.assertEqual(obj.context, context)
Ejemplo n.º 9
0
 def test_build_context(self):
     context = {'test': '1'}
     self.assertEqual(CommandsTrack({}).build_context(context), context)
Ejemplo n.º 10
0
 def test_build_no_event(self):
     with self.assertRaises(InvalidParametersError):
         CommandsTrack({}).build({'user_id': '1234'})
Ejemplo n.º 11
0
 def test_init(self):
     self.assertIsInstance(CommandsTrack({}).context_merger, ContextMerger)
Ejemplo n.º 12
0
 def track(self, options):
     if not self.tracked():
         return None
     self._add_timestamp_if_necessary(options)
     return self.api.call(CommandsTrack(self.context).build(options))
Ejemplo n.º 13
0
 def track(self, options):
     if not self.tracked():
         return
     return self.api.call(CommandsTrack(self.context).build(options))