Пример #1
0
def test_wrap_store_fs(valid_mock, settings, tmpdir):
    """Add a store_fs for a store that doesnt exist yet"""
    settings.POOTLE_FS_WORKING_PATH = os.path.join(str(tmpdir), "fs_file_test")
    valid_mock.side_effect = lambda x: x
    store_fs = MockStoreFS()
    fs_file = FSFile(store_fs)
    assert (
        fs_file.file_path
        == os.path.join(
            store_fs.project.local_fs_path,
            store_fs.path.strip("/")))
    assert fs_file.file_exists is False
    assert fs_file.latest_hash is None
    assert fs_file.pootle_changed is False
    assert fs_file.fs_changed is False

    assert fs_file.store is None
    assert fs_file.store_exists is False

    assert fs_file.deserialize() is None
    assert fs_file.serialize() is None
    assert str(fs_file) == "<FSFile: %s::%s>" % (fs_file.pootle_path, fs_file.path)
    assert hash(fs_file) == hash(
        "%s::%s::%s::%s"
        % (fs_file.path,
           fs_file.pootle_path,
           fs_file.store_fs.last_sync_hash,
           fs_file.store_fs.last_sync_revision))
    assert fs_file == FSFile(store_fs)
    testdict = {}
    testdict[fs_file] = "foo"
    testdict[FSFile(store_fs)] = "bar"
    assert len(testdict.keys()) == 1
    assert testdict.values()[0] == "bar"
Пример #2
0
def test_wrap_store_fs_with_file(settings, tmpdir, tp0_store, test_fs):
    pootle_fs_path = os.path.join(str(tmpdir), "fs_file_test")
    settings.POOTLE_FS_PATH = pootle_fs_path
    project = Project.objects.get(code="project0")
    pootle_path = "/language0/%s/example.po" % project.code
    fs_path = "/some/fs/example.po"
    store_fs = StoreFS.objects.create(path=fs_path, pootle_path=pootle_path)
    fs_file = FSFile(store_fs)
    os.makedirs(os.path.dirname(fs_file.file_path))
    with test_fs.open("data/po/complex.po") as src:
        with open(fs_file.file_path, "w") as target:
            data = src.read()
            target.write(data)
    assert fs_file.pootle_changed is False
    assert fs_file.fs_changed is True
    assert fs_file.file_exists is True
    assert fs_file.latest_hash == str(os.stat(fs_file.file_path).st_mtime)
    assert isinstance(fs_file.deserialize(), pofile)
    assert str(fs_file.deserialize()) == data
Пример #3
0
def test_wrap_store_fs_with_store(settings, tmpdir, tp0_store):
    pootle_fs_path = os.path.join(str(tmpdir), "fs_file_test")
    settings.POOTLE_FS_PATH = pootle_fs_path
    fs_path = "/some/fs/example.po"
    store_fs = StoreFS.objects.create(path=fs_path, store=tp0_store)
    project = tp0_store.translation_project.project
    fs_file = FSFile(store_fs)
    assert (fs_file.file_path == os.path.join(pootle_fs_path, project.code,
                                              store_fs.path.strip("/")))
    assert fs_file.file_exists is False
    assert fs_file.latest_hash is None
    assert fs_file.fs_changed is False
    assert fs_file.pootle_changed is True
    assert fs_file.store == tp0_store
    assert fs_file.store_exists is True
    serialized = fs_file.serialize()
    assert serialized
    assert serialized == tp0_store.serialize()
    assert fs_file.deserialize() is None
Пример #4
0
def test_wrap_store_fs_with_file(settings, tmpdir, tp0_store, test_fs):
    settings.POOTLE_FS_WORKING_PATH = os.path.join(str(tmpdir), "fs_file_test")
    project = Project.objects.get(code="project0")
    pootle_path = "/language0/%s/example.po" % project.code
    fs_path = "/some/fs/example.po"
    store_fs = StoreFS.objects.create(
        path=fs_path,
        pootle_path=pootle_path)
    fs_file = FSFile(store_fs)
    os.makedirs(os.path.dirname(fs_file.file_path))
    with test_fs.open("data/po/complex.po") as src:
        with open(fs_file.file_path, "w") as target:
            data = src.read()
            target.write(data)
    assert fs_file.pootle_changed is False
    assert fs_file.fs_changed is True
    assert fs_file.file_exists is True
    assert fs_file.latest_hash == str(os.stat(fs_file.file_path).st_mtime)
    assert isinstance(fs_file.deserialize(), pofile)
    assert str(fs_file.deserialize()) == data
Пример #5
0
def store_fs_file_store(settings, tmpdir, tp0_store, test_fs):
    from pootle_fs.files import FSFile
    from pootle_fs.models import StoreFS

    settings.POOTLE_FS_WORKING_PATH = os.path.join(str(tmpdir), "fs_file_test")
    fs_path = "/some/fs/example.po"
    store_fs = StoreFS.objects.create(path=fs_path, store=tp0_store)
    fs_file = FSFile(store_fs)
    with test_fs.open("data/po/complex.po") as src:
        tp0_store.update(tp0_store.deserialize(src.read()))
    return fs_file
Пример #6
0
def test_wrap_store_fs_with_store(valid_mock):
    valid_mock.side_effect = lambda x: x
    store_mock = PropertyMock()
    store_mock.configure_mock(**{
        "data.max_unit_revision": 23,
        "serialize.return_value": 73
    })
    store_fs = MockStoreFS()
    store_fs.store = store_mock
    fs_file = FSFile(store_fs)

    assert (fs_file.file_path == os.path.join(store_fs.project.local_fs_path,
                                              store_fs.path.strip("/")))
    assert fs_file.file_exists is False
    assert fs_file.latest_hash is None
    assert fs_file.fs_changed is False
    assert fs_file.pootle_changed is True
    assert fs_file.store is store_mock
    assert fs_file.store_exists is True
    assert fs_file.serialize() == 73
    assert fs_file.deserialize() is None
Пример #7
0
def test_wrap_store_fs_with_file(path_mock, hash_mock, valid_mock):
    valid_mock.side_effect = lambda x: x
    path_mock.return_value = True
    hash_mock.return_value = 23

    store_fs = MockStoreFS()
    store_fs.last_sync_hash = 73
    fs_file = FSFile(store_fs)

    assert fs_file.pootle_changed is False
    assert fs_file.fs_changed is True
    assert fs_file.file_exists is True
Пример #8
0
def test_wrap_store_fs(settings, tmpdir):
    """Add a store_fs for a store that doesnt exist yet
    """
    pootle_fs_path = os.path.join(str(tmpdir), "fs_file_test")
    settings.POOTLE_FS_PATH = pootle_fs_path
    project = Project.objects.get(code="project0")
    pootle_path = "/language0/%s/example.po" % project.code
    fs_path = "/some/fs/example.po"
    store_fs = StoreFS.objects.create(pootle_path=pootle_path, path=fs_path)
    fs_file = FSFile(store_fs)
    assert (fs_file.file_path == os.path.join(pootle_fs_path, project.code,
                                              store_fs.path.strip("/")))
    assert fs_file.file_exists is False
    assert fs_file.latest_hash is None
    assert fs_file.pootle_changed is False
    assert fs_file.fs_changed is False
    assert fs_file.store is None
    assert fs_file.store_exists is False
    assert fs_file.deserialize() is None
    assert fs_file.serialize() is None
    assert str(fs_file) == "<FSFile: %s::%s>" % (pootle_path, fs_path)
    assert hash(fs_file) == hash(
        "%s::%s::%s::%s" %
        (fs_file.path, fs_file.pootle_path, fs_file.store_fs.last_sync_hash,
         fs_file.store_fs.last_sync_revision))
    assert fs_file == FSFile(store_fs)
    testdict = {}
    testdict[fs_file] = "foo"
    testdict[FSFile(store_fs)] = "bar"
    assert len(testdict.keys()) == 1
    assert testdict.values()[0] == "bar"
Пример #9
0
def test_wrap_store_fs(valid_mock, settings, tmpdir):
    """Add a store_fs for a store that doesnt exist yet"""
    settings.POOTLE_FS_WORKING_PATH = os.path.join(str(tmpdir), "fs_file_test")
    valid_mock.side_effect = lambda x: x
    store_fs = MockStoreFS()
    fs_file = FSFile(store_fs)
    assert (fs_file.file_path == os.path.join(store_fs.project.local_fs_path,
                                              store_fs.path.strip("/")))
    assert fs_file.file_exists is False
    assert fs_file.latest_hash is None
    assert fs_file.pootle_changed is False
    assert fs_file.fs_changed is False

    assert fs_file.store is None
    assert fs_file.store_exists is False

    assert fs_file.deserialize() is None
    assert fs_file.serialize() is None
    assert str(fs_file) == "<FSFile: %s::%s>" % (fs_file.pootle_path,
                                                 fs_file.path)
    assert hash(fs_file) == hash(
        "%s::%s::%s::%s" %
        (fs_file.path, fs_file.pootle_path, fs_file.store_fs.last_sync_hash,
         fs_file.store_fs.last_sync_revision))
    assert fs_file == FSFile(store_fs)
    testdict = {}
    testdict[fs_file] = "foo"
    testdict[FSFile(store_fs)] = "bar"
    assert len(testdict.keys()) == 1
    assert testdict.values()[0] == "bar"
Пример #10
0
def test_wrap_store_fs(settings, tmpdir):
    """Add a store_fs for a store that doesnt exist yet
    """
    pootle_fs_path = os.path.join(str(tmpdir), "fs_file_test")
    settings.POOTLE_FS_PATH = pootle_fs_path
    project = Project.objects.get(code="project0")
    pootle_path = "/language0/%s/example.po" % project.code
    fs_path = "/some/fs/example.po"
    store_fs = StoreFS.objects.create(
        pootle_path=pootle_path,
        path=fs_path)
    fs_file = FSFile(store_fs)
    assert (
        fs_file.file_path
        == os.path.join(
            pootle_fs_path, project.code,
            store_fs.path.strip("/")))
    assert fs_file.file_exists is False
    assert fs_file.latest_hash is None
    assert fs_file.pootle_changed is False
    assert fs_file.fs_changed is False
    assert fs_file.store is None
    assert fs_file.store_exists is False
    assert fs_file.deserialize() is None
    assert fs_file.serialize() is None
    assert str(fs_file) == "<FSFile: %s::%s>" % (pootle_path, fs_path)
    assert hash(fs_file) == hash(
        "%s::%s::%s::%s"
        % (fs_file.path,
           fs_file.pootle_path,
           fs_file.store_fs.last_sync_hash,
           fs_file.store_fs.last_sync_revision))
    assert fs_file == FSFile(store_fs)
    testdict = {}
    testdict[fs_file] = "foo"
    testdict[FSFile(store_fs)] = "bar"
    assert len(testdict.keys()) == 1
    assert testdict.values()[0] == "bar"
Пример #11
0
def test_wrap_store_fs_with_store(settings, tmpdir, tp0_store):
    settings.POOTLE_FS_WORKING_PATH = os.path.join(str(tmpdir), "fs_file_test")
    fs_path = "/some/fs/example.po"
    store_fs = StoreFS.objects.create(
        path=fs_path,
        store=tp0_store)
    project = tp0_store.translation_project.project
    fs_file = FSFile(store_fs)
    assert (
        fs_file.file_path
        == os.path.join(
            settings.POOTLE_FS_WORKING_PATH, project.code,
            store_fs.path.strip("/")))
    assert fs_file.file_exists is False
    assert fs_file.latest_hash is None
    assert fs_file.fs_changed is False
    assert fs_file.pootle_changed is True
    assert fs_file.store == tp0_store
    assert fs_file.store_exists is True
    serialized = fs_file.serialize()
    assert serialized
    assert serialized == tp0_store.serialize()
    assert fs_file.deserialize() is None
Пример #12
0
def test_wrap_store_fs_with_store(valid_mock):
    valid_mock.side_effect = lambda x: x
    store_mock = PropertyMock()
    store_mock.configure_mock(
        **{"data.max_unit_revision": 23,
           "serialize.return_value": 73})
    store_fs = MockStoreFS()
    store_fs.store = store_mock
    fs_file = FSFile(store_fs)

    assert (
        fs_file.file_path
        == os.path.join(
            store_fs.project.local_fs_path,
            store_fs.path.strip("/")))
    assert fs_file.file_exists is False
    assert fs_file.latest_hash is None
    assert fs_file.fs_changed is False
    assert fs_file.pootle_changed is True
    assert fs_file.store is store_mock
    assert fs_file.store_exists is True
    assert fs_file.serialize() == 73
    assert fs_file.deserialize() is None
Пример #13
0
def _test_store_fs_files(src_path):
    for store_fs in StoreFS.objects.all():
        fs_file = FSFile(store_fs)
        assert fs_file.fs == store_fs.fs
        assert fs_file.project == store_fs.project
        assert fs_file.store == store_fs.store
        assert fs_file.pootle_path == store_fs.pootle_path
        assert fs_file.path == store_fs.path

        # latest hash must be implemented by the plugin's file class
        with pytest.raises(NotImplementedError):
            fs_file.latest_hash

        if fs_file.exists:
            src_file_path = os.path.join(src_path, fs_file.path.strip("/"))
            with open(src_file_path, "r") as src_file:
                assert src_file.read() == fs_file.read()

        assert (
            str(fs_file)
            == ("<%s: %s::%s>"
                % (fs_file.__class__.__name__,
                   fs_file.pootle_path, fs_file.path)))
        directory = fs_file.directory
        if directory:
            if store_fs.store:
                assert directory == store_fs.store.parent
        else:
            assert not store_fs.store
        assert (
            fs_file.language
            == Language.objects.get(code=fs_file.pootle_path.split("/")[1]))
        assert (
            fs_file.translation_project
            == TranslationProject.objects.get(
                language=fs_file.language, project=fs_file.project))
Пример #14
0
def store_fs_file(settings, tmpdir, test_fs):
    from pootle_fs.files import FSFile
    from pootle_fs.models import StoreFS
    from pootle_project.models import Project

    settings.POOTLE_FS_WORKING_PATH = os.path.join(str(tmpdir), "fs_file_test")
    project = Project.objects.get(code="project0")
    pootle_path = "/language0/%s/example.po" % project.code
    fs_path = "/some/fs/example.po"
    store_fs = StoreFS.objects.create(path=fs_path, pootle_path=pootle_path)
    fs_file = FSFile(store_fs)
    os.makedirs(os.path.dirname(fs_file.file_path))
    with test_fs.open("data/po/complex.po") as src:
        with open(fs_file.file_path, "w") as target:
            data = src.read()
            target.write(data)
    return fs_file
Пример #15
0
def test_wrap_store_fs_bad(settings, tmpdir):

    with pytest.raises(TypeError):
        FSFile("NOT A STORE_FS")
Пример #16
0
def test_file_instance(fs_plugin_suite):
    with pytest.raises(TypeError):
        FSFile("Not a StoreFS!")
    _test_store_fs_files(fs_plugin_suite.fs.url)