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)
def test_generate_expiry_time(self): self.assertTrue( Deduplication.generate_expiry_time(12).hour == ( datetime.datetime.utcnow() + datetime.timedelta(hours=12)).hour)