def test_call_no_event(self): context = {} options = default_options() options.pop('event') with self.assertRaises(InvalidParametersError): CommandsTrack(context).call(options)
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)
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)
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)
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)
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)
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)
def test_init(self): context = mock.sentinel.test_init_context obj = CommandsTrack(context) self.assertEqual(obj.context, context)
def test_build_context(self): context = {'test': '1'} self.assertEqual(CommandsTrack({}).build_context(context), context)
def test_build_no_event(self): with self.assertRaises(InvalidParametersError): CommandsTrack({}).build({'user_id': '1234'})
def test_init(self): self.assertIsInstance(CommandsTrack({}).context_merger, ContextMerger)
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))
def track(self, options): if not self.tracked(): return return self.api.call(CommandsTrack(self.context).build(options))