示例#1
0
    def test_fs_cp_remote_to_local(self):
        """ Test file copying from a remote to the local system

        Test "agavecli fs cp" when copying a file from a remote agave system
        to a local system.
        """
        try:
            # Create an instance of the agave databse in /tmp.
            path = self.set_tmp_agave_db()
            self.create_valid_access_token(path)
            tmp_file = self.create_remote_dummy_file()
            local_file = "{}/testfile.txt".format(path)

            # cmd: agavecli fs cp agave://tacc-globalfs-user/ <file> -A /tmp/<dir>.
            args = agavecli.main_parser.parse_args([
                "fs", "cp", "agave://tacc-globalfs-user/" + tmp_file,
                local_file, "-A", path
            ])
            agavecli.main(args)
        finally:
            assert filecmp.cmp(tmp_file, local_file)

            # rm agavedb dir.
            shutil.rmtree(path)
            # rm dummy file in current working directory.
            if os.path.exists(tmp_file):
                os.remove(tmp_file)
示例#2
0
    def test_fs_cp_local_to_remote(self):
        """ Test file copying from the local to a remote system

        Test "agavecli fs cp" when copying a file from the local system to
        a remote one.
        """
        try:
            # Create an instance of the agave databse in /tmp.
            path = self.set_tmp_agave_db()
            self.create_valid_access_token(path)
            tmp_file = self.create_local_dummy_file()

            # cmd: agavecli fs cp <file> agave://tacc-globalfs-user/ -A /tmp/<dir>.
            args = agavecli.main_parser.parse_args([
                "fs", "cp", tmp_file, "agave://tacc-globalfs-user/", "-A", path
            ])
            agavecli.main(args)
        finally:
            _, tmp_filename = os.path.split(tmp_file)
            assert filecmp.cmp(tmp_file, tmp_filename)

            # rm agavedb dir.
            shutil.rmtree(path)
            # rm dummy file.
            os.remove(tmp_file)
            # rm dummy file in current working directory.
            if os.path.exists(tmp_filename):
                os.remove(tmp_filename)
示例#3
0
    def test_client_rm(self, mock_input, mock_pass, capfd):
        """ Test "agavecli client rm <client>

        Patch username and password from user to send a client delete request
        to mock server.
        """
        # Patch username and password.
        mock_input.return_value = "hi"
        mock_pass.return_value = "pass"

        try:
            # Create an instance of the agave databse in /tmp.
            path = self.set_tmp_agave_db()

            # cmd: agavecli client create -n test_client -A /tmp/<dir>.
            args = agavecli.main_parser.parse_args(
                ["client", "create", "-n", "test_client", "-A", path])
            agavecli.main(args)
            # cmd: agavecli client rm test_client -A /tmp/<dir>.
            args = agavecli.main_parser.parse_args(
                ["client", "rm", "test_client", "-A", path])
            agavecli.main(args)
        finally:
            # Read and delete tmp instace f agave database.
            with open(path + "/agave.json", "r") as f:
                agavedb = json.load(f)
                shutil.rmtree(path)

        out, err = capfd.readouterr()
        assert out == ""
        assert "POST /clients/v2 HTTP/1.1\" 200" in err
        assert "DELETE /clients/v2/test_client HTTP/1.1\" 200" in err
示例#4
0
    def test_client_ls(self, mock_input, mock_pass, capfd):
        """ Test "agavecli client ls"

        Patch username and password from user to send a client list request   
        to mock server.
        """
        # Patch username and password.
        mock_input.return_value = "hi"
        mock_pass.return_value = "pass"

        try:
            # Create an instance of the agave databse in /tmp.
            path = self.set_tmp_agave_db()

            # cmd: agavecli client ls -A /tmp/<dir>.
            args = agavecli.main_parser.parse_args(
                ["client", "ls", "-A", path])
            agavecli.main(args)
        finally:
            # Read and delete tmp instace f agave database.
            with open(path + "/agave.json", "r") as f:
                agavedb = json.load(f)
                shutil.rmtree(path)

        out, err = capfd.readouterr()
        assert sample_client_list_response["result"][0]["name"] in out
        assert "GET /clients/v2 HTTP/1.1\" 200" in err
示例#5
0
    def test_client_create(self, mock_input, mock_pass):
        """ Test "agavecli client create <client>"

        Patch username and password from user to send a client create request 
        to mock server.
        """
        # Patch username and password.
        mock_input.return_value = "hi"
        mock_pass.return_value = "pass"

        try:
            # Create an instance of the agave databse in /tmp.
            path = self.set_tmp_agave_db()

            # cmd: agavecli client create -A /tmp/<dir>.
            args = agavecli.main_parser.parse_args(
                ["client", "create", "-A", path])
            agavecli.main(args)
        finally:
            # Read and delete tmp instace f agave database.
            with open(path + "/agave.json", "r") as f:
                agavedb = json.load(f)
                shutil.rmtree(path)

        assert agavedb["current"]["apikey"] == \
                sample_client_create_response["result"]["consumerKey"]
        assert agavedb["current"]["apisecret"] == \
                sample_client_create_response["result"]["consumerSecret"]