Exemplo n.º 1
0
 def test_object_score_low_duplication(self):
     obj1 = {
         'field1': 'value',
         'field2': 'value1',
         'field3': 'value2',
         'field4': 'value3',
         'field5': 'value4'
     }
     obj2 = {
         'field1': str(uuid.uuid4()),
         'field2': str(uuid.uuid4()),
         'field3': str(uuid.uuid4()),
         'field4': str(uuid.uuid4()),
         'field5': str(uuid.uuid4())
     }
     ioc = GreaseContainer()
     parent1 = ioc.getCollection('test_scoring').insert_one({
         'expiry':
         Deduplication.generate_expiry_time(1),
         'max_expiry':
         Deduplication.generate_max_expiry_time(1),
         'type':
         1,
         'score':
         1,
         'source':
         'test_source',
         'hash':
         Deduplication.generate_hash_from_obj(obj1)
     }).inserted_id
     score1 = Deduplication.object_field_score('test_scoring', ioc,
                                               'test_source',
                                               'test_configuration', obj1,
                                               parent1, 1, 1)
     parent2 = ioc.getCollection('test_scoring').insert_one({
         'expiry':
         Deduplication.generate_expiry_time(1),
         'max_expiry':
         Deduplication.generate_max_expiry_time(1),
         'type':
         1,
         'score':
         1,
         'source':
         'test_source',
         'hash':
         Deduplication.generate_hash_from_obj(obj2)
     }).inserted_id
     score2 = Deduplication.object_field_score('test_scoring', ioc,
                                               'test_source',
                                               'test_configuration', obj2,
                                               parent2, 1, 1)
     print("++++++++++++++++++++++++++++++++++")
     print("score1: {0}".format(score1))
     print("score2: {0}".format(score2))
     print("++++++++++++++++++++++++++++++++++")
     self.assertTrue(score1 == 0.0)
     self.assertTrue(score2 <= 20.0)
     ioc.getCollection('test_scoring').drop()
     time.sleep(1.5)
Exemplo n.º 2
0
 def test_generate_hash_other_type(self):
     obj = 7
     self.assertEqual(Deduplication.generate_hash_from_obj(obj),
                      hashlib.sha256(str(obj).encode('utf-8')).hexdigest())
     obj = 'test'
     self.assertEqual(Deduplication.generate_hash_from_obj(obj),
                      hashlib.sha256(str(obj).encode('utf-8')).hexdigest())
     obj = u'test'
     self.assertEqual(Deduplication.generate_hash_from_obj(obj),
                      hashlib.sha256(str(obj).encode('utf-8')).hexdigest())
     obj = 7.8
     self.assertEqual(Deduplication.generate_hash_from_obj(obj),
                      hashlib.sha256(str(obj).encode('utf-8')).hexdigest())
     obj = ['test', 'var', 8, 8.43]
     self.assertEqual(Deduplication.generate_hash_from_obj(obj),
                      hashlib.sha256(str(obj).encode('utf-8')).hexdigest())
Exemplo n.º 3
0
 def test_generate_hash_multi_str_type(self):
     obj = {'test': u'var', 'test1': 5, 'test2': 7.89, 'test3': 'ver'}
     self.assertEqual(Deduplication.generate_hash_from_obj(obj),
                      hashlib.sha256(str(obj).encode('utf-8')).hexdigest())