Exemple #1
0
def test_merge_file(historian: mincepy.Historian):
    """Test that merging files works correctly"""
    file = historian.create_file('test.dat')
    file.write_text('bla bla')
    file.save()
    with testing.temporary_historian(
            testing.create_archive_uri(db_name='test_historian')) as remote:
        local = historian
        # Merge the file into the remote
        result = remote.merge(local.find(obj_id=file.obj_id))
        assert len(result.all) == len(result.merged) == local.find().count()
        assert local.find().count() == remote.find().count()

        remote_file = remote.get(file.obj_id)
        assert file.read_text() == remote_file.read_text()

        # Now check that files contained within objects are correctly merged
        file_list = mincepy.List((file, ))
        file_list.save()  # pylint: disable=no-member
        result = remote.merge(local.find(obj_id=file_list.obj_id))  # pylint: disable=no-member
        assert len(result.merged) == 1
        assert historian.get_snapshot_id(file_list) in result.merged

        remote_file_list = remote.get(file_list.obj_id)  # pylint: disable=no-member
        assert file.read_text() == remote_file_list[0].read_text()
Exemple #2
0
def test_large_merge(
        historian: mincepy.Historian,
        large_dataset,  # pylint: disable=unused-argument
):
    with testing.temporary_historian(
            testing.create_archive_uri(db_name='test_historian')) as remote:
        local = historian

        all_objects = local.find()
        assert all_objects.count() > 0

        # Merge the large dataset into the remote historian
        result = remote.merge(all_objects)
        assert len(result.all) == len(result.merged) == local.find().count()
        assert local.find().count() == remote.find().count()
Exemple #3
0
def test_merge(historian: mincepy.Historian):
    with testing.temporary_historian(
            testing.create_archive_uri(db_name='test_historian')) as remote:
        local = historian
        # remote = clean_test_historian

        remote_skoda = testing.Car(make='skoda', colour='green')
        skoda_id = remote.save(remote_skoda)
        assert remote_skoda._historian is remote

        result = local.merge(remote.objects.find(obj_id=skoda_id))
        assert remote.get_snapshot_id(remote_skoda) in result.merged
        assert local.find(obj_id=skoda_id).count() == 1

        # Now, let's update and see if we can merge
        remote_skoda.colour = 'yellow'
        remote.save(remote_skoda)

        result = local.merge(remote.objects.find(obj_id=skoda_id))
        assert remote.get_snapshot_id(remote_skoda) in result.merged
        assert local.snapshots.find(obj_id=skoda_id).count() == 2
        assert local.find(obj_id=skoda_id).one().colour == 'yellow'

        # Now, change both to the same thing
        local_skoda = local.load(skoda_id)
        assert local_skoda._historian is local
        assert local_skoda is not remote_skoda

        local_skoda.colour = 'blue'
        local_skoda.save()

        remote_skoda.colour = 'blue'
        remote_skoda.save()
        result = local.merge(remote.objects.find(obj_id=skoda_id))
        assert not result.merged  # None should have been transferred

        # Now check that conflicts are correctly handled
        remote_skoda.colour = 'brown'
        remote_skoda.save()
        local_skoda.colour = 'grey'
        local_skoda.save()
        with pytest.raises(mincepy.MergeError):
            local.merge(remote.objects.find(obj_id=skoda_id))