Exemplo n.º 1
0
Arquivo: utils_t.py Projeto: ktf/DAS
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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