Exemplo n.º 1
0
    def test_saves_to_file(self):
        state = SyncState(self.state_path)
        state.push_path("a")
        state.push_path("b")
        state.sync_path("c")
        state.sync_path("d")

        self.assertStateFile("""\
2016-01-01T12:00:00 +push a
2016-01-01T12:00:00 +push b
2016-01-01T12:00:00 +sync c
2016-01-01T12:00:00 +sync d
""")

        state.push_done("a")
        state.sync_done("d")

        self.assertStateFile("""\
2016-01-01T12:00:00 +push a
2016-01-01T12:00:00 +push b
2016-01-01T12:00:00 +sync c
2016-01-01T12:00:00 +sync d
2016-01-01T12:00:00 -push a
2016-01-01T12:00:00 -sync d
""")
Exemplo n.º 2
0
    def test_saves_to_file(self):
        state = SyncState(self.state_path)
        state.push_path("a")
        state.push_path("b")
        state.sync_path("c")
        state.sync_path("d")

        self.assertStateFile("""\
2016-01-01T12:00:00 +push a
2016-01-01T12:00:00 +push b
2016-01-01T12:00:00 +sync c
2016-01-01T12:00:00 +sync d
""")

        state.push_done("a")
        state.sync_done("d")

        self.assertStateFile("""\
2016-01-01T12:00:00 +push a
2016-01-01T12:00:00 +push b
2016-01-01T12:00:00 +sync c
2016-01-01T12:00:00 +sync d
2016-01-01T12:00:00 -push a
2016-01-01T12:00:00 -sync d
""")
Exemplo n.º 3
0
    def test_survives_fatal_errors(self):
        state = SyncState(self.state_path)
        s3 = S3Null({
            "S3_URI_PREFIX": "s3://foo",
            "ROOT_PATH": root_dir,
        }, state)

        os.mkdir(os.path.join(root_dir, "server"))

        state.sync_path("server")
        state.sync_path("")
        # We can abuse push_path because pushed paths are not checked.
        state.push_path("a")
        state.push_path("b")

        stderr = StringIO()
        s3._cached_stderr = stderr
        s3._fail_on = set(("a", ""))
        s3.run()

        # Some went through.
        self.assertEqual(s3._pushed, set(("b", )))
        self.assertEqual(s3._synced, set(("server",)))

        # Some failed.
        self.assertRegex(
            stderr.getvalue(),
            re.compile(r"^Error while processing: a$", re.MULTILINE))
        self.assertRegex(
            stderr.getvalue(),
            re.compile(r"^Error while processing: $", re.MULTILINE))

        # Those that failed still need to be done.
        self.assertEqual(state.current_state, {
            "push": ["a"],
            "sync": [""],
        })

        # The state on disk does not show the failures as done.
        # The funky "\n\" in what follows is to prevent git from swallowing
        # the space at the end of the line.
        self.assertStateFile("""\
2016-01-01T12:00:00 +sync server
2016-01-01T12:00:00 +sync \n\
2016-01-01T12:00:00 +push a
2016-01-01T12:00:00 +push b
2016-01-01T12:00:00 -push b
2016-01-01T12:00:00 -sync server
""")
Exemplo n.º 4
0
    def test_survives_fatal_errors(self):
        state = SyncState(self.state_path)
        s3 = S3Null({
            "S3_URI_PREFIX": "s3://foo",
            "ROOT_PATH": root_dir,
        }, state)

        os.mkdir(os.path.join(root_dir, "server"))

        state.sync_path("server")
        state.sync_path("")
        # We can abuse push_path because pushed paths are not checked.
        state.push_path("a")
        state.push_path("b")

        stderr = StringIO()
        s3._cached_stderr = stderr
        s3._fail_on = set(("a", ""))
        s3.run()

        # Some went through.
        self.assertEqual(s3._pushed, set(("b", )))
        self.assertEqual(s3._synced, set(("server",  )))

        # Some failed.
        self.assertRegexpMatches(
            stderr.getvalue(),
            re.compile(ur"^Error while processing: a$", re.MULTILINE))
        self.assertRegexpMatches(
            stderr.getvalue(),
            re.compile(ur"^Error while processing: $", re.MULTILINE))

        # Those that failed still need to be done.
        self.assertEqual(state.current_state, {
            "push": set(("a", )),
            "sync": set(("", ))
        })

        # The state on disk does not show the failures as done.
        # The funky "\n\" in what follows is to prevent git from swallowing
        # the space at the end of the line.
        self.assertStateFile("""\
2016-01-01T12:00:00 +sync server
2016-01-01T12:00:00 +sync \n\
2016-01-01T12:00:00 +push a
2016-01-01T12:00:00 +push b
2016-01-01T12:00:00 -push b
2016-01-01T12:00:00 -sync server
""")
Exemplo n.º 5
0
    def test_records_state_in_memory(self):
        state = SyncState(self.state_path)
        state.push_path("a")
        state.push_path("b")
        state.sync_path("c")
        state.sync_path("d")
        self.assertEqual(state.current_state, {
            "push": ["a", "b"],
            "sync": ["c", "d"],
        })

        state.push_done("a")
        state.sync_done("d")

        self.assertEqual(state.current_state, {
            "push": ["b"],
            "sync": ["c"],
        })
Exemplo n.º 6
0
    def test_records_state_in_memory(self):
        state = SyncState(self.state_path)
        state.push_path("a")
        state.push_path("b")
        state.sync_path("c")
        state.sync_path("d")
        self.assertEqual(state.current_state, {
            "push": set(("a", "b")),
            "sync": set(("c", "d"))
        })

        state.push_done("a")
        state.sync_done("d")

        self.assertEqual(state.current_state, {
            "push": set(("b",)),
            "sync": set(("c",))
        })
Exemplo n.º 7
0
    def test_pushes_and_syncs(self):
        state = SyncState(self.state_path)
        s3 = S3Null({
            "S3_URI_PREFIX": "s3://foo",
            "ROOT_PATH": root_dir,
        }, state)

        os.mkdir(os.path.join(root_dir, "server"))

        state.sync_path("server")
        state.sync_path("")
        # We can abuse push_path because pushed paths are not checked.
        state.push_path("a")
        state.push_path("b")

        s3.run()

        self.assertEqual(s3._pushed, set(("a", "b")))
        self.assertEqual(s3._synced, set(("server", "")))
Exemplo n.º 8
0
    def test_pushes_and_syncs(self):
        state = SyncState(self.state_path)
        s3 = S3Null({
            "S3_URI_PREFIX": "s3://foo",
            "ROOT_PATH": root_dir,
        }, state)

        os.mkdir(os.path.join(root_dir, "server"))

        state.sync_path("server")
        state.sync_path("")
        # We can abuse push_path because pushed paths are not checked.
        state.push_path("a")
        state.push_path("b")

        s3.run()

        self.assertEqual(s3._pushed, set(("a", "b")))
        self.assertEqual(s3._synced, set(("server", "")))
Exemplo n.º 9
0
 def test_emits_on_push_path(self):
     state = SyncState(self.state_path)
     paths = []
     state.ee.on('push', lambda x: paths.append(x))
     state.push_path("a")
     self.assertEqual(paths, ["a"])
Exemplo n.º 10
0
 def test_emits_on_push_path(self):
     state = SyncState(self.state_path)
     paths = []
     state.ee.on('push', paths.append)
     state.push_path("a")
     self.assertEqual(paths, ["a"])