예제 #1
0
    def test_get_fullpatches_of_last_run(self, mocker):

        # Given some fullpatches
        records_o = {1: fd({'recid': 1}), 2: fd({'recid': 2}), 3: fd({'recid': 3})}
        records_m = {1: fd({'recid': 10}), 2: fd({'recid': 20}), 3: fd({'recid': 3})}

        # And some mocks
        invenio_records = {'modified': deepcopy(records_m), 'original': deepcopy(records_o)}
        worker = mocker.Mock(task_id='abc')

        def jsonpatch(r1, r2):
            """Return objects that act like jsonpatches when bool is called."""
            p = mocker.MagicMock()
            if r1 == records_o[1] and r2 == records_m[1]:
                p.tostring.return_value = '[{"path": "/recid", "value": 10, "op": "replace"}]'
            elif r1 == records_o[2] and r2 == records_m[2]:
                p.tostring.return_value = '[{"path": "/recid", "value": 20, "op": "replace"}]'
            elif r1 == records_o[3] and r2 == records_m[3]:
                try:
                    p.__bool__.return_value = False
                except AttributeError:
                    p.__nonzero__.return_value = False
                p.tostring.return_value = '[]'
            else:
                raise Exception('Unwated patch attempted')
            return p

        # Mock jsonpatch  --  Returns jsonpatch.JsonPatch
        m_jsonpatch = mocker.Mock()
        m_jsonpatch.make_patch = jsonpatch
        mocker.patch('invenio_checker.conftest.conftest_checker.jsonpatch', m_jsonpatch)

        # Mock make_fullpatch
        from invenio_checker.clients.worker import make_fullpatch
        m_make_fullpatch = create_autospec(make_fullpatch)
        mocker.patch('invenio_checker.conftest.conftest_checker.make_fullpatch', m_make_fullpatch)

        # Run
        ret = tuple(_get_fullpatches_of_last_run('modified', invenio_records, worker))

        # Ensure that two patches were sent to redis
        assert len(ret) == 2
        assert set(ret) == {
            m_make_fullpatch(1, 'hash1', '[{"path": "/recid", "value": 10, "op": "replace"}]', 'abc'),
            m_make_fullpatch(2, 'hash1', '[{"path": "/recid", "value": 20, "op": "replace"}]', 'abc'),
        }
예제 #2
0
파일: utils.py 프로젝트: renatkh/provenance
def edge(tail_name, head_name, **attrs):
    attrs['type'] = 'edge'
    attrs['tail_name'] = tail_name
    attrs['head_name'] = head_name
    return fd(attrs)
예제 #3
0
파일: utils.py 프로젝트: renatkh/provenance
def node(name, label=None, **attrs):
    attrs['type'] = 'node'
    attrs['name'] = name
    attrs['label'] = label
    return fd(attrs)