def test_add_hash(self): "Test add_hash function" rec = {'foo':1} add_hash(rec) expect = ['foo', 'hash'] result = rec.keys() self.assertEqual(result, expect)
def test_add_hash(self): "Test add_hash function" rec = {'foo': 1} add_hash(rec) expect = sorted(['foo', 'hash']) result = sorted(list(rec.keys())) self.assertEqual(result, expect)
def check_hash(rec): """ Check record hash """ nrec = dict(rec) if 'hash' in nrec: md5 = nrec.pop('hash') add_hash(nrec) rmd5 = nrec.pop('hash') if md5 != rmd5: print('Invalid hash') print("record:", rec) print("nrec:", nrec) print("md5 :", md5) print("rmd5 :", rmd5) return False return True
def validator(record): """ DAS map validator """ add_record_type(record) add_hash(record) must_have_keys = ['type'] if 'notations' in record: must_have_keys += ['system', 'notations', 'ts', 'hash'] elif 'presentation' in record: must_have_keys += ['presentation', 'ts', 'hash'] elif 'input_values' in record: must_have_keys += ['input_values'] else: must_have_keys += ['system', 'format', 'urn', 'url', 'expire', 'params', 'das_map', 'ts', 'hash'] if set(record.keys()) & set(must_have_keys) != set(must_have_keys): return False return True
def validator(record): """ DAS map validator """ add_record_type(record) add_hash(record) must_have_keys = ['type'] if 'notations' in record: must_have_keys += ['system', 'notations', 'ts', 'hash'] elif 'presentation' in record: must_have_keys += ['presentation', 'ts', 'hash'] elif 'input_values' in record: must_have_keys += ['input_values'] else: must_have_keys += ['system', 'format', 'urn', 'url', 'expire', \ 'params', 'das_map', 'ts', 'hash'] if set(record.keys()) & set(must_have_keys) != set(must_have_keys): return False return True