Beispiel #1
0
class TestVdir(object):
    def create_file(self, location, content):
        d = Path(os.path.dirname(path_expand(location)))
        print()
        print("TESTDIR:", d)

        d.mkdir(parents=True, exist_ok=True)

        writefile(path_expand(location), content)

    def setup(self):
        StopWatch.start("vdir setup")
        self.vdir = Vdir()
        self.endpoint = 'box:/test.txt'
        self.directory_and_name = '/testdir/test'
        self.directory = 'testdir'
        self.file = 'test'
        self.create_file('~/.cloudmesh/vdir/test/test.txt', 'test file')
        self.destination = path_expand("~/.cloudmesh/vdir/test")
        variables = Variables()
        service = Parameter.expand(variables['storage'])[0]
        self.p = Provider(service=service)
        self.p.put(source='~/.cloudmesh/vdir/test/test.txt',
                   destination='/',
                   recursive=False)
        StopWatch.stop("vdir setup")

    def test_collection(self):
        HEADING()
        StopWatch.start("vdir collection")
        col = self.vdir.col
        StopWatch.stop("vdir collection")

        assert col.name == 'local-vdir'

    @pytest.fixture(scope='class')
    def dummy_file(self):
        self.endpoint = 'box:/test.txt'
        self.directory_and_name = 'test'

        StopWatch.start("vdir add")
        self.vdir = Vdir()
        testfile = self.vdir.add(endpoint=self.endpoint,
                                 dir_and_name=self.directory_and_name)
        StopWatch.stop("vdir add")
        return testfile

    @pytest.fixture(scope='class')
    def dummy_dir(self):
        self.directory = 'testdir'

        StopWatch.start("vdir mkdir")
        self.vdir = Vdir()
        testdir = self.vdir.mkdir(dirname=self.directory)
        StopWatch.stop("vdir mkdir")
        return testdir

    def test_mkdir(self, dummy_dir):
        HEADING()

        assert dummy_dir is not None

    def test_add(self, dummy_file):
        HEADING()

        assert dummy_file is not None

    def test_ls(self):
        HEADING()
        StopWatch.start("vdir ls")
        results = self.vdir.ls(directory=None)
        StopWatch.stop("vdir ls")

        assert results is not None

    def test_get(self):
        HEADING()
        StopWatch.start("vdir get")
        file = self.vdir.get(name=self.file, destination=self.destination)
        StopWatch.stop("vdir get")
        print(file)

        assert file is not None

    def test_status(self):
        HEADING()
        StopWatch.start("vdir status")
        file = self.vdir.status(dir_or_name=self.file)
        StopWatch.stop("vdir status")

        assert file is not None

    def test_cd(self):
        HEADING()
        StopWatch.start("vdir cd")
        self.vdir.cd(dirname=self.directory)
        StopWatch.stop("vdir cd")

        assert self.vdir.directory == self.directory

    def test_delete(self):
        HEADING()
        StopWatch.start("vdir delete")
        file = self.vdir.delete(dir_or_name=self.file)
        directory = self.vdir.delete(dir_or_name=self.directory)
        StopWatch.stop("vdir delete")

        assert all(obj is not None for obj in [file, directory])

    def test_results(self):
        HEADING()

        StopWatch.benchmark()
Beispiel #2
0
    def do_vdir(self, args, arguments):
        """
        ::

          Usage:
                vdir mkdir DIR
                vdir cd [DIR]
                vdir ls [DIR]
                vdir add [FILEENDPOINT] [DIR_AND_NAME]
                vdir delete [DIR_OR_NAME]
                vdir status [DIR_OR_NAME]
                vdir get NAME DESTINATION

          Arguments:
              DIR           a directory name
              FILEENDPOINT  location of file
              DIR_AND_NAME  path of file link
              DIR_OR_NAME   name of directory or link
              DESTINATION   directory to download to
              NAME          name of link

          Options:
              -f      specify the file

          Descripton:

              A virtual directory is explained in our NIST doecumentation. It
              contains a number of links that point to other storage services on
              which the file is stored. The links include the provider, the name
              of the profider and its type are identified in the
              ~/.cloudmesh4.yaml file.

              the location is identified as

                 {provider}:{directory}/{filensme}

              A cloudmesh directory can be used to uniquely specify the file:

                 cm:
                    name: the unique name of the file
                    kind: vdir
                    cloud: local
                    directory: directory
                    filename: filename
                    directory: directory
                    provider: provider
                    created: date
                    modified: date

              vdir get NAME DESTINATION

                 locates the file with the name on a storage provider,
                 and fetches it from there.


        """

        print(arguments)

        d = Vdir()

        if arguments['add']:
            d.add(arguments.FILEENDPOINT, arguments.DIR_AND_NAME)
        elif arguments['ls']:
            d.ls(arguments.DIR)
        elif arguments['get']:
            d.get(arguments.NAME, arguments.DESTINATION)
        elif arguments['mkdir']:
            d.mkdir(arguments.DIR)
        elif arguments['cd']:
            d.cd(arguments.DIR)
        elif arguments['delete']:
            d.delete(arguments.DIR_OR_NAME)
        elif arguments['status']:
            d.status(arguments.DIR_OR_NAME)
class Test_vdir:
    def setup(self):
        self.vdir = Vdir()
        self.endpoint = 'box:/test.txt'
        self.dir_and_name = '/testdir/test'
        self.dir = 'testdir'
        self.file = 'test'

    def test_collection(self):
        HEADING()
        col = self.vdir.col

        assert col.name == 'local-vdir'

    @pytest.fixture(scope='class')
    def dummy_file(self):
        self.vdir = Vdir()
        self.endpoint = 'box:/test.txt'
        self.dir_and_name = 'test'
        testfile = self.vdir.add(endpoint=self.endpoint,
                                 dir_and_name=self.dir_and_name)
        return testfile

    @pytest.fixture(scope='class')
    def dummy_dir(self):
        self.vdir = Vdir()
        self.dir = 'testdir'
        testdir = self.vdir.mkdir(dirname=self.dir)
        return testdir

    def test_mkdir(self, dummy_dir):
        HEADING()

        assert dummy_dir is not None

    def test_add(self, dummy_file):
        HEADING()

        assert dummy_file is not None

    def test_ls(self):
        HEADING()
        results = self.vdir.ls(directory=None)

        assert results is not None

    def test_get(self):
        HEADING()
        file = self.vdir.get(name=self.file)

        assert file is not None

    def test_status(self):
        HEADING()
        file = self.vdir.status(dir_or_name=self.file)

        assert file is not None

    def test_cd(self):
        HEADING()
        self.vdir.cd(dirname=self.dir)

        assert self.vdir.directory == self.dir

    def test_delete(self):
        HEADING()

        self.vdir.delete(dir_or_name=self.file)
        self.vdir.delete(dir_or_name=self.dir)