Esempio n. 1
0
    def setUp(self):
        self.config = MSDSConfig(localdir=tempfile.mkdtemp())
        self.api = MSDataSyncAPI(self.config, msds_log)
        self.impl = MSDSImpl(msds_log, self.api)

        # method stub
        self.api.post_sync_step = dingus.Dingus()

        def remove_localdir():
            os.rmdir(self.config["localdir"])

        self.addCleanup(remove_localdir)

        self.rsyncconfig = self.RemoteSyncParamsStub({
            "filename1": (False, False),  # this file didn't change
            "filename2": (False, False),  # this file didn't change
            "filename3": (False, True),  # this file changed
            "asdf": (False, True),  # this file changed
        })

        self.filename_id_map = {
            "filename1": (1, 10),
            "filename2": (2, 20),
            "filename3": (3, 30),
            "filename4": (4, 40),
        }
Esempio n. 2
0
 def setUp(self):
     self.config = MSDSConfig()
     self.api = MSDataSyncAPI(self.config, msds_log)
Esempio n. 3
0
class MSDataSyncAPITests(unittest.TestCase):
    """
    This class is for unit tests of the `MSDataSyncAPI` class.
    At present, there is only one test.
    """
    def setUp(self):
        self.config = MSDSConfig()
        self.api = MSDataSyncAPI(self.config, msds_log)

    def test1_find_local_file_or_directory(self):
        """
        Tests `MSDataSyncAPI.find_local_file_or_directory()`. Checks
        that TEMP files are correctly removed from list of files to
        copy to staging directory.
        """
        wanted_filename = "asdf"
        path = "/path/to/this/dir"
        p = lambda f: os.path.join(path, f)

        # localfiledict - as specified in MSDataSyncAPI.getFiles() docstring
        lfd = {
            ".": ["1", "2", "3"],
            "/": path,
            "asdf": {
                ".": ["a", "b", "c", "TEMPBASE", "TEMPDAT", "TEMPDIR",
                      "TEMP", "TEMPprefix", "suffixTEMP"],
                "/": p("asdf"),
                },
            "qwerty": {
                ".": ["A", "B", "C", "TEMPBASE", "TEMPDAT", "TEMPDIR"],
                "/": p("qwerty"),
                "hjkl": {
                    ".": ["h", "j", "k", "l"],
                    "/": p("qwerty/hjkl"),
                    },
                "zxc": {
                    ".": ["z", "x", "c", "tempqwerty"],
                    "/": p("qwerty/zxc"),
                    },
                },
            "foo": {
                ".": ["X", "Y", "Z"],
                "/": p("foo"),
                },
            "bar": {
                ".": ["4", "5", "6"],
                "/": p("bar"),
                },
            "suffix": {
                ".": ["S1", "S2", "S3", "suffixTEMP"],
                "/": p("suffix"),
                },
            "baz": {
                ".": ["B1", "B2", "B3", "temp"],
                "/": p("baz"),
                },
            }

        result = self.api.find_local_file_or_directory(lfd, "asdf")
        self.assertIsNone(result, "asdf skipped")

        result = self.api.find_local_file_or_directory(lfd, "qwerty")
        self.assertIsNone(result, "qwerty skipped")

        result = self.api.find_local_file_or_directory(lfd, "foo")
        self.assertTrue(bool(result), "subdirectory")

        result = self.api.find_local_file_or_directory(lfd, "bar")
        self.assertEqual(result, p("bar"), "another subdirectory")

        result = self.api.find_local_file_or_directory(lfd, "2")
        self.assertEqual(result, p("2"), "file at top level")

        # this one is surprising maybe
        result = self.api.find_local_file_or_directory(lfd, "B")
        self.assertEqual(result, p("qwerty/B"), "file within ignored directory")

        result = self.api.find_local_file_or_directory(lfd, "Y")
        self.assertEqual(result, p("foo/Y"), "file within subdirectory")

        result = self.api.find_local_file_or_directory(lfd, "suffix")
        self.assertEqual(result, p("suffix"), "TEMP at end of filename")

        result = self.api.find_local_file_or_directory(lfd, "baz")
        self.assertIsNone(result, "lowercase TEMP")

        # this one is also surprising maybe?
        result = self.api.find_local_file_or_directory(lfd, "hjkl")
        self.assertEqual(result, p("qwerty/hjkl"), "subdir within excluded dir")

        result = self.api.find_local_file_or_directory(lfd, "zxc")
        self.assertIsNone(result, "excluded subdir within excluded dir")
Esempio n. 4
0
 def setUp(self):
     self.config = MSDSConfig()
     self.api = MSDataSyncAPI(self.config, msds_log)
Esempio n. 5
0
class MSDataSyncAPITests(unittest.TestCase):
    """
    This class is for unit tests of the `MSDataSyncAPI` class.
    At present, there is only one test.
    """
    def setUp(self):
        self.config = MSDSConfig()
        self.api = MSDataSyncAPI(self.config, msds_log)

    def test1_find_local_file_or_directory(self):
        """
        Tests `MSDataSyncAPI.find_local_file_or_directory()`. Checks
        that TEMP files are correctly removed from list of files to
        copy to staging directory.
        """
        wanted_filename = "asdf"
        path = "/path/to/this/dir"
        p = lambda f: os.path.join(path, f)

        # localfiledict - as specified in MSDataSyncAPI.getFiles() docstring
        lfd = {
            ".": ["1", "2", "3"],
            "/": path,
            "asdf": {
                ".": [
                    "a", "b", "c", "TEMPBASE", "TEMPDAT", "TEMPDIR", "TEMP",
                    "TEMPprefix", "suffixTEMP"
                ],
                "/":
                p("asdf"),
            },
            "qwerty": {
                ".": ["A", "B", "C", "TEMPBASE", "TEMPDAT", "TEMPDIR"],
                "/": p("qwerty"),
                "hjkl": {
                    ".": ["h", "j", "k", "l"],
                    "/": p("qwerty/hjkl"),
                },
                "zxc": {
                    ".": ["z", "x", "c", "tempqwerty"],
                    "/": p("qwerty/zxc"),
                },
            },
            "foo": {
                ".": ["X", "Y", "Z"],
                "/": p("foo"),
            },
            "bar": {
                ".": ["4", "5", "6"],
                "/": p("bar"),
            },
            "suffix": {
                ".": ["S1", "S2", "S3", "suffixTEMP"],
                "/": p("suffix"),
            },
            "baz": {
                ".": ["B1", "B2", "B3", "temp"],
                "/": p("baz"),
            },
        }

        result = self.api.find_local_file_or_directory(lfd, "asdf")
        self.assertIsNone(result, "asdf skipped")

        result = self.api.find_local_file_or_directory(lfd, "qwerty")
        self.assertIsNone(result, "qwerty skipped")

        result = self.api.find_local_file_or_directory(lfd, "foo")
        self.assertTrue(bool(result), "subdirectory")

        result = self.api.find_local_file_or_directory(lfd, "bar")
        self.assertEqual(result, p("bar"), "another subdirectory")

        result = self.api.find_local_file_or_directory(lfd, "2")
        self.assertEqual(result, p("2"), "file at top level")

        # this one is surprising maybe
        result = self.api.find_local_file_or_directory(lfd, "B")
        self.assertEqual(result, p("qwerty/B"),
                         "file within ignored directory")

        result = self.api.find_local_file_or_directory(lfd, "Y")
        self.assertEqual(result, p("foo/Y"), "file within subdirectory")

        result = self.api.find_local_file_or_directory(lfd, "suffix")
        self.assertEqual(result, p("suffix"), "TEMP at end of filename")

        result = self.api.find_local_file_or_directory(lfd, "baz")
        self.assertIsNone(result, "lowercase TEMP")

        # this one is also surprising maybe?
        result = self.api.find_local_file_or_directory(lfd, "hjkl")
        self.assertEqual(result, p("qwerty/hjkl"),
                         "subdir within excluded dir")

        result = self.api.find_local_file_or_directory(lfd, "zxc")
        self.assertIsNone(result, "excluded subdir within excluded dir")