def test_merge_validator(self): def_validators = [{ 'eq': ['v1', 200] }, { "check": "s2", "expect": 16, "comparator": "len_eq" }] current_validators = [{ "check": "v1", "expect": 201 }, { 'len_eq': ['s3', 12] }] merged_validators = loader._merge_validator(def_validators, current_validators) self.assertIn({ "check": "v1", "expect": 201, "comparator": "eq" }, merged_validators) self.assertIn({ "check": "s2", "expect": 16, "comparator": "len_eq" }, merged_validators) self.assertIn({ "check": "s3", "expect": 12, "comparator": "len_eq" }, merged_validators)
def test_merge_validator(self): def_validators = [{ 'eq': ['v1', 200] }, { 'check': 's2', 'expect': 16, 'comparator': 'len_eq' }] current_validators = [{ 'check': 'v1', 'expect': 201 }, { 'len_eq': ['s3', 12] }] merged_validators = loader._merge_validator(def_validators, current_validators) assert { 'check': 'v1', 'expect': 201, 'comparator': 'eq' } in merged_validators assert { 'check': 's2', 'expect': 16, 'comparator': 'len_eq' } in merged_validators assert { 'check': 's3', 'expect': 12, 'comparator': 'len_eq' } in merged_validators
def test_merge_validator_with_dict(self): def_validators = [ {'eq': ["a", {"v": 1}]}, {'eq': [{"b": 1}, 200]} ] current_validators = [ {'len_eq': ['s3', 12]}, {'eq': [{"b": 1}, 201]} ] merged_validators = loader._merge_validator(def_validators, current_validators) self.assertEqual(len(merged_validators), 3) self.assertIn({'check': {'b': 1}, 'expect': 201, 'comparator': 'eq'}, merged_validators) self.assertNotIn({'check': {'b': 1}, 'expect': 200, 'comparator': 'eq'}, merged_validators)
def test_merge_validator_with_dict(self): def_validators = [{'eq': ['a', {'v1': 1}]}, {'eq': [{'b': 1}, 201]}] current_validators = [{'len_eq': ['s3', 12]}, {'eq': [{'b': 1}, 201]}] merged_validators = loader._merge_validator(def_validators, current_validators) assert len(merged_validators) == 3 assert { 'check': { 'b': 1 }, 'expect': 201, 'comparator': 'eq' } in merged_validators assert { 'check': { 'b': 1 }, 'expect': 200, 'comparator': 'eq' } not in merged_validators