コード例 #1
0
ファイル: cube_api.py プロジェクト: jniznan/metrique
 def _obj_hash(self, obj, key, exclude=None, include=None):
     o = copy(obj)
     if include:
         include = set(include)
         o = dict([(k, v) for k, v in o.items() if k in include])
     elif exclude:
         keys = set(obj.keys())
         [o.pop(k) for k in exclude if k in keys]
     obj[key] = jsonhash(o)
     return obj
コード例 #2
0
ファイル: test_utils.py プロジェクト: pombredanne/metrique
def test_jsonhash():
    from metriqueu.utils import jsonhash

    dct = {'a': [3, 2, 1],
           'z': ['a', 'c', 'b', 1],
           'b': {1: [], 3: {}},
           'partner': [],
           'pm_score': None,
           'priority': 'insignificant',
           'product': 'thisorthat',
           'qa_contact': None,
           'qa_whiteboard': None,
           'qe_cond_nak': None,
           'reporter': '*****@*****.**',
           'resolution': None,
           'severity': 'low',
           'short_desc': 'blabla',
           'status': 'CLOSED',
           'target_milestone': '---',
           'target_release': ['---'],
           'verified': [],
           'version': '2.1r'}

    dct_sorted_z = copy(dct)
    dct_sorted_z['z'] = sorted(dct_sorted_z['z'])

    dct_diff = copy(dct)
    del dct_diff['z']

    DCT = '9537205dc75418549068c0c14766645479ce2ec3'
    DCT_SORTED_Z = '38179f7d2a5422efcfb078ecb5dc3354514d1bdc'
    DCT_DIFF = 'dd8374c81577b1295b13aa9c86d2791e3a315399'

    assert dct != dct_sorted_z

    assert jsonhash(dct) == DCT
    assert jsonhash(dct_sorted_z) == DCT_SORTED_Z
    assert jsonhash(dct_diff) == DCT_DIFF

    ' list sort order is an identifier of a unique object '
    assert jsonhash(dct) != jsonhash(dct_sorted_z)