def test_array(self):
     left = {"a": [1, 2, 3]}
     right = {"a": [1, 2, 3, 4, 5]}
     patch = jsondiff.make(left, right)
     new_right = jsonpatch.apply_patch(left, patch)
     eq_(right, new_right)
     # do it again, it's a "replace" op so it can be re-patched safely
     new_new_right = jsonpatch.apply_patch(new_right, patch)
     eq_(right, new_new_right)
     # smaller list on right
     left = {"a": [1, 2, 3, 4, 5]}
     right = {"a": [6, 7]}
     patch = jsondiff.make(left, right)
     new_right = jsonpatch.apply_patch(left, patch)
     eq_(right, new_right)
Exemple #2
0
 def test_array(self):
     left = {"a":[1,2,3]}
     right = {"a":[1,2,3,4,5]}
     patch = jsondiff.make(left,right)
     new_right = jsonpatch.apply_patch(left,patch)
     eq_(right,new_right)
     # do it again, it's a "replace" op so it can be re-patched safely
     new_new_right = jsonpatch.apply_patch(new_right,patch)
     eq_(right,new_new_right)
     # smaller list on right
     left = {"a":[1,2,3,4,5]}
     right = {"a":[6,7]}
     patch = jsondiff.make(left,right)
     new_right = jsonpatch.apply_patch(left,patch)
     eq_(right,new_right)
 def test_bigdoc(self):
     os.chdir(os.path.dirname(sys.argv[1]))
     v2 = json.load(open("v2.json"))
     v3 = json.load(open("v3.json"))
     patch = jsondiff.make(v2, v3)
     new_v3 = jsonpatch.apply_patch(v2, patch)
     eq_(v3, new_v3)
Exemple #4
0
 def test_bigdoc(self):
     os.chdir(os.path.dirname(sys.argv[1]))
     v2 = json.load(open("v2.json"))
     v3 = json.load(open("v3.json"))
     patch = jsondiff.make(v2,v3)
     new_v3 = jsonpatch.apply_patch(v2,patch)
     eq_(v3,new_v3)
Exemple #5
0
 def test_smalldoc(self):
     left = {'a':[9,8,3],'b':'B','c':{'1':1,'2':2,'3':3}}
     right = {'c':{'5':5,'4':4,'1':1},'B':'capitalB','a':[1,2,3,4,5],'b':'bbb'}
     patch = jsondiff.make(left,right)
     new_right = jsonpatch.apply_patch(left,patch)
     new_new_right = jsonpatch.apply_patch(new_right,patch,ignore_conflicts=True,verify=True)
     eq_(right,new_new_right)
Exemple #6
0
 def test_object(self):
     left = {"c":{"1":1,"2":2,"3":3}}
     right = {"c":{"1":1,"4":4,"5":5}}
     patch = jsondiff.make(left,right)
     new_right = jsonpatch.apply_patch(left,patch)
     eq_(right,new_right)
     # patch contains "add" and "remove" ops, so it cannot be re-patched that easy...
     # use ignore and verify
     new_new_right = jsonpatch.apply_patch(new_right,patch,ignore_conflicts=True,verify=True)
     eq_(right,new_new_right)
Exemple #7
0
 def test_scalar(self):
     left = {"one": 1, "ONE": "111"}
     right = {"two": 2, "TWO": "222"}
     patch = jsondiff.make(left,right)
     new_right = jsonpatch.apply_patch(left,patch)
     eq_(right,new_right)
     # do it again, it's a "remove"/"add" op, so we need to ignore
     # conflicts but make sure the result is the one we expect
     new_new_right = jsonpatch.apply_patch(new_right,patch,ignore_conflicts=True,verify=True)
     eq_(right,new_new_right)
 def test_object(self):
     left = {"c": {"1": 1, "2": 2, "3": 3}}
     right = {"c": {"1": 1, "4": 4, "5": 5}}
     patch = jsondiff.make(left, right)
     new_right = jsonpatch.apply_patch(left, patch)
     eq_(right, new_right)
     # patch contains "add" and "remove" ops, so it cannot be re-patched that easy...
     # use ignore and verify
     new_new_right = jsonpatch.apply_patch(new_right,
                                           patch,
                                           ignore_conflicts=True,
                                           verify=True)
     eq_(right, new_new_right)
 def test_scalar(self):
     left = {"one": 1, "ONE": "111"}
     right = {"two": 2, "TWO": "222"}
     patch = jsondiff.make(left, right)
     new_right = jsonpatch.apply_patch(left, patch)
     eq_(right, new_right)
     # do it again, it's a "remove"/"add" op, so we need to ignore
     # conflicts but make sure the result is the one we expect
     new_new_right = jsonpatch.apply_patch(new_right,
                                           patch,
                                           ignore_conflicts=True,
                                           verify=True)
     eq_(right, new_new_right)
Exemple #10
0
def _diff_parallel_worker(old_collection_name, new_collection_name,
                          common_ids):
    b1 = get_backend(old_collection_name, 'mongodb')
    b2 = get_backend(new_collection_name, 'mongodb')
    _updates = []
    for doc1, doc2 in two_docs_iterator(b1, b2, common_ids):
        assert doc1['_id'] == doc2['_id'], repr((common_ids, len(common_ids)))
        _patch = jsondiff.make(doc1, doc2)
        if _patch:
            _diff = {}
            _diff['patch'] = _patch
            _diff['_id'] = doc1['_id']
            _updates.append(_diff)
    return _updates
Exemple #11
0
def _diff_doc_inner_worker2(b1, b2, ids, fastdiff=False):
    '''if fastdiff is True, only compare the whole doc,
       do not traverse into each attributes.
    '''
    _updates = []
    for doc1, doc2 in two_docs_iterator(b1, b2, ids):
        assert doc1['_id'] == doc2['_id'], repr((ids, len(ids)))
        if fastdiff:
            if doc1 != doc2:
                _updates.append({'_id': doc1['_id']})
        else:
            _patch = jsondiff.make(doc1, doc2)
            if _patch:
                _diff = {}
                _diff['patch'] = _patch
                _diff['_id'] = doc1['_id']
                _updates.append(_diff)
    return _updates
Exemple #12
0
def _diff_doc_inner_worker2(b1, b2, ids, fastdiff=False):
    '''if fastdiff is True, only compare the whole doc,
       do not traverse into each attributes.
    '''
    _updates = []
    for doc1, doc2 in two_docs_iterator(b1, b2, ids):
        assert doc1['_id'] == doc2['_id'], repr((ids, len(ids)))
        if fastdiff:
            if doc1 != doc2:
                _updates.append(doc1['_id'])
        else:
            _patch = jsondiff.make(doc1, doc2)
            if _patch:
                _diff = {}
                _diff['patch'] = _patch
                _diff['_id'] = doc1['_id']
                _updates.append(_diff)
    return _updates
 def test_smalldoc(self):
     left = {'a': [9, 8, 3], 'b': 'B', 'c': {'1': 1, '2': 2, '3': 3}}
     right = {
         'c': {
             '5': 5,
             '4': 4,
             '1': 1
         },
         'B': 'capitalB',
         'a': [1, 2, 3, 4, 5],
         'b': 'bbb'
     }
     patch = jsondiff.make(left, right)
     new_right = jsonpatch.apply_patch(left, patch)
     new_new_right = jsonpatch.apply_patch(new_right,
                                           patch,
                                           ignore_conflicts=True,
                                           verify=True)
     eq_(right, new_new_right)