#!/usr/bin/env python
# test has been developed by Robert Harakaly and changed for SAM by Victor Galaktionov 
# create a new LFC directory in the name server (lfc_mkdir)
#Do not use explicity values: dteam, etc...
# meta: proxy=true
# meta: preconfig=../../LFC-config

import os,sys,lfc
from testClass import _test, _ntest, _testRunner, SAM_Run, LFC_VO, TEST_HOME

class test_create_dir_ok(_test):
    def info(self):
        return "Directory creation"
    def test(self):
        self.name = LFC_VO + "/python_mkdir_test"   #"/grid/dteam/python_mkdir_test"
        ret = lfc.lfc_mkdir(self.name, 0755)
        return ("",ret)
    def ret(self):
        return ("",0)
    def compare(self,testVal, retVal):
        (ret, retRetVal) = retVal
        (test, testRetVal) = testVal
        retval = True
        if (retRetVal != testRetVal):
            retval = False
        return retval
    def clean(self):
        lfc.lfc_rmdir(self.name)



class test_create_dir_pd(_test):
    def __init__(self):
        self.retVal=-1
    def info(self):
        return "Directory creation (permission denied)"
    def test(self):
        self.name = "/python_mkdir_test"
        ret = lfc.lfc_mkdir(self.name, 0755)
        return ("",ret)
    def ret(self):
        return ("",-1)
    def clean(self):
        lfc.lfc_rmdir(self.name)
    def compare(self,testVal, retVal):
        (ret, retRetVal) = retVal
        (test, testRetVal) = testVal
        retval = True
        if (retRetVal != testRetVal):
            retval = False
        return retval

class lfc_mkdir_test(_testRunner):
    def __init__(self):
        self.name = "lfc_mkdir_test"
        self.tests=[test_create_dir_ok, test_create_dir_pd]


#************* Interface for SAM and Python tests ***************
SAM_Run(lfc_mkdir_test)

