コード例 #1
0
ファイル: tests_sakdb_storage.py プロジェクト: ferwitt/sakdb
def test_sync_string() -> None:
    with tempfile.TemporaryDirectory() as tmpdirname:
        # Given.
        dirA = Path(tmpdirname) / "dirA"
        dirB = Path(tmpdirname) / "dirB"

        dirA.mkdir()
        dirB.mkdir()

        g_a = SakDbGraph()
        n_a = SakDbNamespaceGit(g_a, "data", Path(dirA), "master")

        g_a.register_class(DBObjectString)

        with g_a.session():
            a = DBObjectString(n_a, my_string="helloWorld")

        g_b = SakDbGraph()
        n_b = SakDbNamespaceGit(g_b, "data", Path(dirB), "master")

        g_b.register_class(DBObjectString)

        # When
        n_a.add_remote("origin", str(dirB))
        n_b.add_remote("origin", str(dirA))

        n_a.sync()
        n_b.sync()

        b = DBObjectString(n_b, a.key)

        # Then.
        assert a.my_string == "helloWorld"
        assert b.my_string == "helloWorld"
コード例 #2
0
ファイル: tests_sakdb_storage.py プロジェクト: ferwitt/sakdb
def test_sync_list_with_git_command_no_common_base() -> None:
    with tempfile.TemporaryDirectory() as tmpdirname:
        # Given.
        dirA = Path(tmpdirname) / "dirA"
        dirB = Path(tmpdirname) / "dirB"

        dirA.mkdir()
        dirB.mkdir()

        # Add object in first repo with my_list "helloWorld"
        g_a = SakDbGraph()
        n_a = SakDbNamespaceGit(g_a, "data", Path(dirA), "master")
        g_a.register_class(DBObjectList)

        with g_a.session():
            a = DBObjectList(n_a, my_list=[2, 1, 3])

        assert a.my_list[0] == 2
        assert a.my_list[1] == 1
        assert a.my_list[2] == 3
        assert len(a.my_list) == 3

        # Add the same object/key in another object with my_list "fooBar".
        g_b = SakDbGraph()
        n_b = SakDbNamespaceGit(g_b, "data", Path(dirB), "master")
        g_b.register_class(DBObjectList)

        with g_b.session():
            b = DBObjectList(n_b, a.key, my_list=[5, 4, 6, 10])

        assert b.my_list[0] == 5
        assert b.my_list[1] == 4
        assert b.my_list[2] == 6
        assert b.my_list[3] == 10
        assert len(b.my_list) == 4

        # When

        # Link the repositories with remotes.
        n_a.add_remote("origin", str(dirB))
        n_b.add_remote("origin", str(dirA))

        # Sync the repositories. The repo A is supposed to have trhe value from repo B now.
        n_a.sync()
        n_b.sync()
        n_a.sync()
        n_b.sync()

        # Then.
        assert a.my_list[0] == 5
        assert a.my_list[1] == 4
        assert a.my_list[2] == 6
        assert a.my_list[3] == 10
        assert len(a.my_list) == 4

        assert b.my_list[0] == 5
        assert b.my_list[1] == 4
        assert b.my_list[2] == 6
        assert b.my_list[3] == 10
        assert len(b.my_list) == 4
コード例 #3
0
ファイル: tests_sakdb_storage.py プロジェクト: ferwitt/sakdb
def test_sync_dict_with_git_command_no_common_base() -> None:
    with tempfile.TemporaryDirectory() as tmpdirname:
        # Given.
        dirA = Path(tmpdirname) / "dirA"
        dirB = Path(tmpdirname) / "dirB"

        dirA.mkdir()
        dirB.mkdir()

        # Add object in first repo with my_dict "helloWorld"
        g_a = SakDbGraph()
        n_a = SakDbNamespaceGit(g_a, "data", Path(dirA), "master")
        g_a.register_class(DBObjectDict)

        with g_a.session():
            a = DBObjectDict(n_a, my_dict={"foo": 1, "bar": "hey"})

        assert a.my_dict["foo"] == 1
        assert a.my_dict["bar"] == "hey"
        assert len(a.my_dict) == 2

        # Add the same object/key in another object with my_dict "fooBar".
        g_b = SakDbGraph()
        n_b = SakDbNamespaceGit(g_b, "data", Path(dirB), "master")
        g_b.register_class(DBObjectDict)

        with g_b.session():
            b = DBObjectDict(n_b, a.key, my_dict={"foo": 2, "hello": "world"})

        assert b.my_dict["foo"] == 2
        assert b.my_dict["hello"] == "world"
        assert len(b.my_dict) == 2

        # When

        # Link the repositories with remotes.
        n_a.add_remote("origin", str(dirB))
        n_b.add_remote("origin", str(dirA))

        # Sync the repositories. The repo A is supposed to have trhe value from repo B now.
        n_a.sync()
        n_b.sync()
        n_a.sync()
        n_b.sync()

        # Then.
        assert a.my_dict["foo"] == 2
        assert a.my_dict["bar"] == "hey"
        assert a.my_dict["hello"] == "world"
        assert len(a.my_dict) == 3

        assert b.my_dict["foo"] == 2
        assert b.my_dict["bar"] == "hey"
        assert b.my_dict["hello"] == "world"
        assert len(b.my_dict) == 3
コード例 #4
0
ファイル: tests_sakdb_storage.py プロジェクト: ferwitt/sakdb
def test_sync_dict() -> None:
    # Given.
    with tempfile.TemporaryDirectory() as tmpdirname:
        # Given.
        dirA = Path(tmpdirname) / "dirA"
        dirB = Path(tmpdirname) / "dirB"

        dirA.mkdir()
        dirB.mkdir()

        g_a = SakDbGraph()
        n_a = SakDbNamespaceGit(g_a, "data", Path(dirA), "master")

        g_a.register_class(DBObjectDict)

        with g_a.session():
            a = DBObjectDict(n_a, my_dict={"foo": 1, "bar": "hey"})

        g_b = SakDbGraph()
        n_b = SakDbNamespaceGit(g_b, "data", Path(dirB), "master")
        g_b.register_class(DBObjectDict)

        # When
        n_a.add_remote("origin", str(dirB))
        n_b.add_remote("origin", str(dirA))

        n_a.sync()
        n_b.sync()

        b = DBObjectDict(n_b, a.key)

        # Then.
        assert a.my_dict["foo"] == 1
        assert a.my_dict["bar"] == "hey"
        assert len(a.my_dict) == 2

        assert b.my_dict["foo"] == 1
        assert b.my_dict["bar"] == "hey"
        assert len(b.my_dict) == 2
コード例 #5
0
ファイル: tests_sakdb_storage.py プロジェクト: ferwitt/sakdb
def test_sync_list() -> None:
    with tempfile.TemporaryDirectory() as tmpdirname:
        # Given.
        dirA = Path(tmpdirname) / "dirA"
        dirB = Path(tmpdirname) / "dirB"

        dirA.mkdir()
        dirB.mkdir()

        g_a = SakDbGraph()
        n_a = SakDbNamespaceGit(g_a, "data", Path(dirA), "master")

        g_a.register_class(DBObjectList)

        with g_a.session():
            a = DBObjectList(n_a, my_list=[2, 1, 3])

        g_b = SakDbGraph()
        n_b = SakDbNamespaceGit(g_b, "data", Path(dirB), "master")

        g_b.register_class(DBObjectList)

        # When
        n_a.add_remote("origin", str(dirB))
        n_b.add_remote("origin", str(dirA))

        n_a.sync()
        n_b.sync()

        b = DBObjectList(n_b, a.key)

        # Then.
        assert a.my_list[0] == 2
        assert a.my_list[1] == 1
        assert a.my_list[2] == 3

        assert b.my_list[0] == 2
        assert b.my_list[1] == 1
        assert b.my_list[2] == 3
コード例 #6
0
ファイル: tests_sakdb_storage.py プロジェクト: ferwitt/sakdb
def test_sync_with_git_command_common_base() -> None:
    with tempfile.TemporaryDirectory() as tmpdirname:
        # Given.
        dirA = Path(tmpdirname) / "dirA"
        dirB = Path(tmpdirname) / "dirB"

        dirA.mkdir()
        dirB.mkdir()

        # Add object in first repo with my_string "helloWorld"
        g_a = SakDbGraph()
        n_a = SakDbNamespaceGit(g_a, "data", Path(dirA), "master")
        g_a.register_class(DBObjectString)

        with g_a.session():
            a = DBObjectString(n_a, my_string="helloWorld")

        assert a.my_string == "helloWorld"

        # Add the same object/key in another object with my_string "fooBar".
        g_b = SakDbGraph()
        n_b = SakDbNamespaceGit(g_b, "data", Path(dirB), "master")
        g_b.register_class(DBObjectString)

        # Link the repositories with remotes.
        n_a.add_remote("origin", str(dirB))
        n_b.add_remote("origin", str(dirA))
        n_a.sync()
        n_b.sync()
        n_a.sync()
        n_b.sync()

        b = DBObjectString(n_b, a.key)
        assert b.my_string == "helloWorld"

        # When
        with g_a.session():
            a.my_string = "changedA"

        with g_b.session():
            b.my_string = "changedB"

        # Sync the repositories. The repo A is supposed to have trhe value from repo B now.
        n_a.sync()
        n_b.sync()
        n_a.sync()
        n_b.sync()

        # Then.
        assert a.my_string == "changedB"
        assert b.my_string == "changedB"