Example #1
0
 def setup_buffers2(self, session):
     """Set up the buffers for the tests below."""
     wrapper = city.CityWrapper(session=session, uid=42)
     images = wrapper.add(city.Image(path=FILE_PATHS[0], uid=1),
                          city.Image(path=FILE_PATHS[1], uid=2))
     session._reset_buffers(BufferContext.USER)
     return images
Example #2
0
 def test_get_file_cuds(self):
     """Test extracting the file cuds from a datatstructure."""
     image1 = city.Image(path="x")
     image2 = city.Image(path="y")
     c = city.City(name="Freiburg")
     x = {"a": image1, "b": 1, "c": None, "d": [c, image2]}
     r = get_file_cuds(x)
     self.assertEqual(r, [image1, image2])
Example #3
0
 def setup_buffers1(self, session):
     """Set up the buffers for the tests below."""
     wrapper = city.CityWrapper(session=session)
     images = wrapper.add(
         city.Image(path=FILE_PATHS[0]), city.Image(path=FILE_PATHS[1])
     )
     session._reset_buffers(BufferContext.USER)
     wrapper.remove(images[1].uid)
     images[0].path = FILE_PATHS[0]
     images = list(images) + [wrapper.add(city.Image(path=FILE_PATHS[2]))]
     session.prune()
     return images
Example #4
0
 def setup_buffers3(self, session):
     """Set up the buffers for the upload and download tests."""
     wrapper = city.CityWrapper(session=session)
     images = wrapper.add(
         city.Image(path=FILE_PATHS[0]),
         city.Image(path=FILE_PATHS[1]),
         city.Image(path=FILE_PATHS[1]),
     )
     images_second = wrapper.add(
         city.Image(path=SECOND_FILE_PATHS[0]),
         city.Image(path=SECOND_FILE_PATHS[1]),
     )
     session._reset_buffers(BufferContext.USER)
     wrapper.remove(images[1].uid)
     images[0].path = FILE_PATHS[0]
     images[2].path = FILE_PATHS[1]
     images_second[0].path = SECOND_FILE_PATHS[0]
     images_second[1].path = SECOND_FILE_PATHS[1]
     images = [list(images)[0], list(images)[2]] + [
         wrapper.add(city.Image(path=FILE_PATHS[2]))
     ]
     session.prune()
     return images, images_second
Example #5
0
    def test_move_files(self):
        """Test moving the files."""
        with TransportSessionClient(SqliteSession, URI) as session:
            # Image path is full path
            wrapper = city.CityWrapper(session=session)
            images = wrapper.add(
                city.Image(path=FILE_PATHS[0]),
                city.Image(path=FILE_PATHS[1]),
                city.Image(path=FILE_PATHS[2]),
            )
            result = move_files(images, None, CLIENT_DIR)
            target = [
                "%s-%s" % (image.uid.hex, file)
                for image, file in zip(images, FILES)
            ]
            target_full_path = [os.path.join(CLIENT_DIR, t) for t in target]

            self.assertEqual(set(os.listdir(FILES_DIR)), set(FILES))
            self.assertEqual(set(os.listdir(CLIENT_DIR)), set(target))
            self.assertEqual(result, target_full_path)

            self.tearDown()
            self.setUp()

            # Image path is path on a different system
            paths = [
                FILES[0],
                os.path.join("foo", "bar", FILES[1]),
                os.path.abspath(".").split(os.path.sep)[0]
                + os.path.sep
                + FILES[2],
            ]
            images = wrapper.add(
                city.Image(path=paths[0]),
                city.Image(path=paths[1]),
                city.Image(path=paths[2]),
            )
            result = move_files(images, FILES_DIR, CLIENT_DIR)
            target = [
                "%s-%s" % (image.uid.hex, file)
                for image, file in zip(images, FILES)
            ]
            target_full_path = [os.path.join(CLIENT_DIR, t) for t in target]
            self.assertEqual(set(os.listdir(CLIENT_DIR)), set(target))
            self.assertEqual(result, target_full_path)

            self.tearDown()
            self.setUp()

            # Not target given --> Nothing will be moved
            images = wrapper.add(
                city.Image(path=paths[0]),
                city.Image(path=paths[1]),
                city.Image(path=paths[2]),
            )
            result = move_files(images, FILES_DIR, None)
            self.assertEqual(set(os.listdir(CLIENT_DIR)), set())
            self.assertEqual(result, paths)

            # Target does not exist
            images = wrapper.add(
                city.Image(path=paths[0]),
                city.Image(path=paths[1]),
                city.Image(path=paths[2]),
            )
            result = move_files(images, FILES_DIR, "not-existent")
            self.assertEqual(set(os.listdir(CLIENT_DIR)), set())
            self.assertEqual(result, list())

            # paths don't exist
            images = wrapper.add(
                city.Image(path=paths[0]),
                city.Image(path=paths[1]),
                city.Image(path=paths[2]),
            )
            result = move_files(images, None, CLIENT_DIR)
            self.assertEqual(set(os.listdir(CLIENT_DIR)), set())
            self.assertEqual(result, list())