def test_build_no_user_id(self): context = {} options = default_options() options.pop('user_id') with self.assertRaises(InvalidParametersError): CommandsIdentify(context).build(options)
def test_build_active_false(self): payload = default_payload() payload.update(context={'active': False}) command = CommandsIdentify({}).build(payload) self.assertIsInstance(command, Command) self.assertEqual(command.method, 'post') self.assertEqual(command.endpoint, 'identify') self.assertEqual(command.data, payload)
def test_build_no_user_id(self): context = {} options = default_options() options.pop('user_id') expected = default_command_with_data(**options) self.assertEqual(CommandsIdentify(context).build(options), expected)
def test_build_traits_allowed(self): context = {} options = default_options_plus(traits={'email': '*****@*****.**'}) options.update({'context': context}) expected = default_command_with_data(**options) self.assertEqual(CommandsIdentify(context).build(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 = CommandsIdentify({}).build(payload) self.assertIsInstance(command, Command) self.assertEqual(command.method, 'post') self.assertEqual(command.endpoint, 'identify') self.assertEqual(command.data, command_data)
def test_build(self): context = {'test': '1'} options = default_options_plus(context={'color': 'blue'}) # expect the original context to have been merged with the context specified in the options expected_data = clone(options) expected_data.update(context={'test': '1', 'color': 'blue'}) expected = default_command_with_data(**expected_data) self.assertEqual(CommandsIdentify(context).build(options), expected)
def test_build_context(self): context = {'test': '1'} self.assertEqual(CommandsIdentify({}).build_context(context), context)
def test_build_properties(self): with self.assertRaises(InvalidParametersError): CommandsIdentify({}).build({'properties': '1234'})
def test_build_no_user_id(self): with self.assertRaises(InvalidParametersError): CommandsIdentify({}).build({})
def test_init(self): self.assertIsInstance( CommandsIdentify({}).context_merger, ContextMerger)
def test_build_properties_not_allowed(self): context = {'test': '1'} options = default_options_plus(properties={'hair': 'blonde'}) with self.assertRaises(InvalidParametersError): CommandsIdentify(context).build(options)
def test_init(self): context = mock.sentinel.test_init_context obj = CommandsIdentify(context) self.assertEqual(obj.context, context)
def identify(self, options): if not self.tracked(): return None self._add_timestamp_if_necessary(options) return self.api.call(CommandsIdentify(self.context).build(options))
def identify(self, options): if not self.tracked(): return return self.api.call(CommandsIdentify(self.context).build(options))