Beispiel #1
0
    def setUp(self):
        # Create a test patch to delete.
        add_test_patch("22222", 22222, delete_pch.back_path)

        # Create a secondary patch to ensure only the desired patch is deleted.
        add_test_patch("22223", 22223, delete_pch.back_path)

        # Create a version directory with 3 versions
        for i in range(1, 4):
            add_test_patch(os.path.join("22224", "22224_v{}".format(i)), 22224,
                           delete_pch.back_path)
Beispiel #2
0
    def setUp(self):
        util.backend_path = test_path
        # Create a test patch to delete.
        util.add_test_patch("22222", 22222)

        # Create a secondary patch to ensure only the desired patch is deleted.
        util.add_test_patch("22223", 22223)

        # Create a version directory with 3 versions
        for i in range(1, 4):
            util.add_test_patch(os.path.join("22224", "22224_v{}".format(i)),
                                22224)
    def test_version_history_directory_creation(self):
        """Attempt to save a patch that already exists
        to the LibraryApp folder.

        The test will validate that a new directory is created
        that takes the name of the patch id, and that the
        contents of the new directory contain the metadata
        and renamed patch files to conform to the version of
        each patch.
        """

        self.setUp()

        # Try to break the method with a NoneType
        exc = (FileNotFoundError, errors.SavingError)
        self.assertRaises(exc, save.save_to_backend, None)
        self.assertRaises(exc, save.save_to_backend, ("ERROR", "ERROR"))
        self.assertRaises(exc, save.save_to_backend, (None, "ERROR"))
        self.assertRaises(exc, save.save_to_backend, ("ERROR", None))

        # Make sure there is no directory
        path = os.path.join(os.getcwd(), "zoia_lib", "tests",
                            ".ZoiaLibraryApp")
        self.assertFalse(
            "55555" in os.listdir(path),
            "Found a directory with the expected patch id of "
            "55555 when it should not exist.",
        )

        # Now add the directory and some patches
        # Create a dummy patch with dummy metadata.
        add_test_patch(os.path.join("55555", "55555_v1"), 55555,
                       save.back_path)
        # Try to save the same patch again without making any changes to the
        # binary contents of the patch.
        add_test_patch(os.path.join("55555", "55555_v2"), 55555,
                       save.back_path)
        # Try to save the same patch again after making a change to the
        # binary contents of the patch.
        with open(os.path.join(path, "55555", "55555_v1.bin"), "rb") as fb:
            binary = fb.read()
            binary += b"ed"
        with open(os.path.join(path, "55555", "55555_v1.bin"), "wb") as f:
            f.write(binary)

        # Ensure a directory was created.
        self.assertTrue(
            "55555" in os.listdir(path),
            "Did not find a directory with the expected patch id "
            "of 55555.",
        )

        path = os.path.join(path, "55555")

        self.assertTrue(
            len(os.listdir(path)) == 4,
            "Directory did not contain the expected number of "
            "files.",
        )

        for i in range(1, 3):
            self.assertTrue(
                "55555_v{}.bin".format(i) in os.listdir(path),
                'The expected patch file "55555_v{}.bin" '
                "was not found.".format(i),
            )
            self.assertTrue(
                "55555_v{}.json".format(i) in os.listdir(path),
                'The expected patch file "55555_v{}.json" '
                "was not found.".format(i),
            )

        self.tearDown()