Ejemplo n.º 1
0
    def test_normalize(self, normalize_mock, hash_sha_256_mock):
        initial_state = {
            'f5first': 'FirstName',
            'f5last': 'LastName',
            'fi': 'FI',
            'dobd': '01',
            'dobm': '02',
            'doby': '2000',
        }
        user_data = UserData(
            f5first=initial_state['f5first'],
            f5last=initial_state['f5last'],
            fi=initial_state['fi'],
            dobd=initial_state['dobd'],
            dobm=initial_state['dobm'],
            doby=initial_state['doby'],
        )
        hash_sha_256_mock.side_effect = (lambda field: field + '-sha256'
                                         if field else None)
        normalize_mock.side_effect = (lambda _, field: field + '-normal'
                                      if field else None)
        actual = user_data.normalize()
        expected = {}
        for key, value in initial_state.items():
            expected[key] = '%s-normal-sha256' % value

        self.assertEqual(actual, expected)
    def test_normalize_it_normalizes_and_hashes(self):
        initial_state = {
            'f5first': 'First',
            'f5last': 'Last',
            'fi': 'A',
            'dobd': '01',
            'dobm': '02',
            'doby': '2000',
            'lead_id': 'lead-id-3',
        }
        user_data = UserData(
            f5first=initial_state['f5first'],
            f5last=initial_state['f5last'],
            fi=initial_state['fi'],
            dobd=initial_state['dobd'],
            dobm=initial_state['dobm'],
            doby=initial_state['doby'],
            lead_id=initial_state['lead_id'],
        )

        actual = user_data.normalize()
        expected = {
            'f5first':
            Normalize.hash_sha_256(initial_state['f5first'].lower()),
            'f5last': Normalize.hash_sha_256(initial_state['f5last'].lower()),
            'fi': Normalize.hash_sha_256(initial_state['fi'].lower()),
            'dobd': Normalize.hash_sha_256(initial_state['dobd']),
            'dobm': Normalize.hash_sha_256(initial_state['dobm']),
            'doby': Normalize.hash_sha_256(initial_state['doby']),
            'lead_id': initial_state['lead_id'],
        }

        self.assertEqual(actual, expected)
    def test_multi_value_normalization_with_empty(self):
        user_data = UserData()
        user_data.emails = []
        user_data.phones = []
        user_data.genders = []
        user_data.dates_of_birth = []
        user_data.last_names = []
        user_data.first_names = []
        user_data.cities = []
        user_data.states = []
        user_data.country_codes = []
        user_data.zip_codes = []
        user_data.external_ids = []

        normalized_data = user_data.normalize()

        self.assertFalse(normalized_data)
Ejemplo n.º 4
0
    def test_constructor(self):
        event_name = 'event_name-0'
        event_time = 123
        event_source_url = 'event_source_url-2'
        opt_out = False
        event_id = 'event_id-3'
        user_data = UserData(email='*****@*****.**')
        custom_data = CustomData(order_id=123)
        data_processing_options = ['4' '5']
        data_processing_options_country = 6
        data_processing_options_state = 7
        action_source = ActionSource.APP
        event = Event(
            event_name=event_name,
            event_time=event_time,
            event_source_url=event_source_url,
            opt_out=opt_out,
            event_id=event_id,
            user_data=user_data,
            custom_data=custom_data,
            data_processing_options=data_processing_options,
            data_processing_options_country=data_processing_options_country,
            data_processing_options_state=data_processing_options_state,
            action_source=action_source,
        )
        expected_params = {
            'event_name': event_name,
            'event_time': event_time,
            'event_source_url': event_source_url,
            'opt_out': opt_out,
            'event_id': event_id,
            'user_data': user_data.normalize(),
            'custom_data': custom_data.normalize(),
            'data_processing_options': data_processing_options,
            'data_processing_options_country': data_processing_options_country,
            'data_processing_options_state': data_processing_options_state,
            'action_source': action_source.value,
        }

        self.assertEqual(event.normalize(), expected_params)
    def test_normalize_it_normalizes_and_hashes(self):
        initial_state = {
            'emails': ['*****@*****.**', '*****@*****.**', '*****@*****.**'],
            'phones': ['12345678912', '12062072008', '12062072008'],
            'genders': [Gender.MALE, Gender.FEMALE, Gender.FEMALE],
            'dates_of_birth': ['19900101', '19660202', '19660202'],
            'last_names': ['smith', 'brown', 'brown'],
            'first_names': ['joe', 'mary', 'mary'],
            'cities': ['seattle', 'sanfrancisco', 'sanfrancisco'],
            'states': ['ca', 'wa', 'wa'],
            'country_codes': ['us', 'ca', 'ca'],
            'zip_codes': ['98001', '12345', '12345'],
            'external_ids': ['123', '456', '456'],
            'f5first': 'First',
            'f5last': 'Last',
            'fi': 'A',
            'dobd': '01',
            'dobm': '02',
            'doby': '2000',
            'lead_id': 'lead-id-3',
        }
        user_data = UserData(
            f5first=initial_state['f5first'],
            f5last=initial_state['f5last'],
            fi=initial_state['fi'],
            dobd=initial_state['dobd'],
            dobm=initial_state['dobm'],
            doby=initial_state['doby'],
            lead_id=initial_state['lead_id'],
        )
        user_data.emails = initial_state['emails']
        user_data.phones = initial_state['phones']
        user_data.genders = initial_state['genders']
        user_data.dates_of_birth = initial_state['dates_of_birth']
        user_data.last_names = initial_state['last_names']
        user_data.first_names = initial_state['first_names']
        user_data.cities = initial_state['cities']
        user_data.states = initial_state['states']
        user_data.country_codes = initial_state['country_codes']
        user_data.zip_codes = initial_state['zip_codes']
        user_data.external_ids = initial_state['external_ids']

        actual = user_data.normalize()
        expected = {
            'em':
            self.__hash_list(initial_state['emails'][0:2]),
            'ph':
            self.__hash_list(initial_state['phones'][0:2]),
            'ge':
            self.__hash_list(
                list(map(lambda g: g.value, initial_state['genders'][0:2]))),
            'db':
            self.__hash_list(initial_state['dates_of_birth'][0:2]),
            'ln':
            self.__hash_list(initial_state['last_names'][0:2]),
            'fn':
            self.__hash_list(initial_state['first_names'][0:2]),
            'ct':
            self.__hash_list(initial_state['cities'][0:2]),
            'st':
            self.__hash_list(initial_state['states'][0:2]),
            'zp':
            self.__hash_list(initial_state['zip_codes'][0:2]),
            'country':
            self.__hash_list(initial_state['country_codes'][0:2]),
            'external_id':
            initial_state['external_ids'][0:2],
            'f5first':
            Normalize.hash_sha_256(initial_state['f5first'].lower()),
            'f5last':
            Normalize.hash_sha_256(initial_state['f5last'].lower()),
            'fi':
            Normalize.hash_sha_256(initial_state['fi'].lower()),
            'dobd':
            Normalize.hash_sha_256(initial_state['dobd']),
            'dobm':
            Normalize.hash_sha_256(initial_state['dobm']),
            'doby':
            Normalize.hash_sha_256(initial_state['doby']),
            'lead_id':
            initial_state['lead_id'],
        }

        not_equal_items = {
            k: actual[k]
            for k in actual
            if k not in expected or sorted(actual[k]) != sorted(expected[k])
        }
        self.assertEqual(len(not_equal_items), 0)
        self.assertEqual(len(actual), len(expected))