<commit_before>from project.repo_wrapper import *

from unittest import TestCase
import shutil, tempfile
import svn.remote
import svn.admin

class SVN_Wrapper_Abstract_Test(TestCase):
    def test_Get_Info(self):
        res = Get_Info_For_Repo_Name( 'some wrong repo' )
        self.assertEqual( res[0], VCS_REPO_FAIL_CALL )

    def test_Get_Log(self):
        res = Get_Log_For_Repo_Name( 'some wrong repo' )
        self.assertEqual( res[0], VCS_REPO_FAIL_CALL )

    def test_Get_List(self):
        res = Get_List_For_Repo_Name( 'some wrong repo', 'some wrong path' )
        self.assertEqual( res[0], VCS_REPO_FAIL_CALL )

    def test_Repo_Conf_Name_Gen(self):
        repo_root = 'root_folder'
        repo_name = 'repo_name'
        t = Repo_File_Paths( repo_root, repo_name )

        self.assertEqual( t.conf_folder( ),             os.path.join( repo_root, repo_name, 'conf', '' ) )
        self.assertEqual( t.svnserve_conf_full_name( ), os.path.join( repo_root, repo_name, 'conf', 'svnserve.conf' ) )
        if REPO_TYPE == svn_serve:
            self.assertEqual( t.pass_full_name( ),      os.path.join( repo_root, 'passwd' ) ) # one passwd in root
        else:
            if REPO_TYPE == svn_apache:
                self.assertEqual( t.pass_full_name( ),  os.path.join( repo_root, 'htpasswd' ) ) # one passwd in root

        self.assertEqual( t.auth_full_name( ),          os.path.join( repo_root, repo_name, 'conf', 'authz' ) )

    def test_Gen_Repo_User_PW(self):
        pw= Gen_Repo_User_PW()
        self.assertNotEqual( pw, '')

    def test_VCS_Configured(self):
        self.assertEqual( VCS_Configured(), True )

class SVN_Wrapper_Temp_Dir_Test(TestCase):
    test_temp_dir = None

    def setUp(self):
        # Create a temporary directory
        if not self.test_temp_dir:
            self.test_temp_dir = tempfile.mkdtemp()

    def tearDown(self):
        # Remove the directory after the test
        if self.test_temp_dir:
            shutil.rmtree(self.test_temp_dir)
            self.test_temp_dir = None

    def test_Repo_Users_In_Temp_Dir(self):
        repo_root = self.test_temp_dir
        repo_name = 'repo_name'
        t = Repo_File_Paths( repo_root, repo_name )
        fn = t.pass_full_name()

        Add_User_To_Main_PassFile( fn, { 'user_name1' : 'pass', 'user_name2' : '<PASSWORD>' } )
        f = open( fn )

        if REPO_TYPE == svn_serve:
            self.assertEqual(f.read(), '[users]\nuser_name1=pass\nuser_name2=pass2\n\n')
        else:
            if REPO_TYPE == svn_apache:
                self.assertEqual(f.read(), '[users]\nuser_name1:pass\nuser_name2:pass2\n\n')
        f.close()

    def test_Repo_Conf_In_Temp_Dir(self):
        repo_root = self.test_temp_dir
        repo_name = 'repo_name'
        t = Repo_File_Paths( repo_root, repo_name )
        fn = t.svnserve_conf_full_name()

        import os
        os.makedirs( t.conf_folder() ) # force path to cfg

        Write_Ini_for_CFG( fn, 'some_section', { 'option' : 'value' } )
        f = open( fn )
        self.assertEqual(f.read(), '[some_section]\noption = value\n\n')
        f.close()

    def test_SVN_Client(self):
        path = self.test_temp_dir + '/test_repo_name'
        print(path)
        import os
        print(os.path.isdir( path ))
        print(os.path.exists( path ))
        self.assertFalse(os.path.exists( path ))
        a = svn.admin.Admin( )
        a.create( path )
        print(os.path.isdir( path ))
        print(os.path.exists( path ))
        self.assertTrue(os.path.exists( path ))
        
        try:
            r = svn.remote.RemoteClient( path, '', '' )
        except Exception as e:
            print( e )

        print( r.info() )
        self.assertIsNone( r.info() )<commit_msg>#99 try svn with credentials<commit_after>from project.repo_wrapper import *

from unittest import TestCase
import shutil, tempfile
import svn.remote
import svn.admin

class SVN_Wrapper_Abstract_Test(TestCase):
    def test_Get_Info(self):
        res = Get_Info_For_Repo_Name( 'some wrong repo' )
        self.assertEqual( res[0], VCS_REPO_FAIL_CALL )

    def test_Get_Log(self):
        res = Get_Log_For_Repo_Name( 'some wrong repo' )
        self.assertEqual( res[0], VCS_REPO_FAIL_CALL )

    def test_Get_List(self):
        res = Get_List_For_Repo_Name( 'some wrong repo', 'some wrong path' )
        self.assertEqual( res[0], VCS_REPO_FAIL_CALL )

    def test_Repo_Conf_Name_Gen(self):
        repo_root = 'root_folder'
        repo_name = 'repo_name'
        t = Repo_File_Paths( repo_root, repo_name )

        self.assertEqual( t.conf_folder( ),             os.path.join( repo_root, repo_name, 'conf', '' ) )
        self.assertEqual( t.svnserve_conf_full_name( ), os.path.join( repo_root, repo_name, 'conf', 'svnserve.conf' ) )
        if REPO_TYPE == svn_serve:
            self.assertEqual( t.pass_full_name( ),      os.path.join( repo_root, 'passwd' ) ) # one passwd in root
        else:
            if REPO_TYPE == svn_apache:
                self.assertEqual( t.pass_full_name( ),  os.path.join( repo_root, 'htpasswd' ) ) # one passwd in root

        self.assertEqual( t.auth_full_name( ),          os.path.join( repo_root, repo_name, 'conf', 'authz' ) )

    def test_Gen_Repo_User_PW(self):
        pw= Gen_Repo_User_PW()
        self.assertNotEqual( pw, '')

    def test_VCS_Configured(self):
        self.assertEqual( VCS_Configured(), True )

class SVN_Wrapper_Temp_Dir_Test(TestCase):
    test_temp_dir = None

    def setUp(self):
        # Create a temporary directory
        if not self.test_temp_dir:
            self.test_temp_dir = tempfile.mkdtemp()

    def tearDown(self):
        # Remove the directory after the test
        if self.test_temp_dir:
            shutil.rmtree(self.test_temp_dir)
            self.test_temp_dir = None

    def test_Repo_Users_In_Temp_Dir(self):
        repo_root = self.test_temp_dir
        repo_name = 'repo_name'
        t = Repo_File_Paths( repo_root, repo_name )
        fn = t.pass_full_name()

        Add_User_To_Main_PassFile( fn, { 'user_name1' : 'pass', 'user_name2' : 'pass2' } )
        f = open( fn )

        if REPO_TYPE == svn_serve:
            self.assertEqual(f.read(), '[users]\nuser_name1=pass\nuser_name2=pass2\n\n')
        else:
            if REPO_TYPE == svn_apache:
                self.assertEqual(f.read(), '[users]\nuser_name1:pass\nuser_name2:pass2\n\n')
        f.close()

    def test_Repo_Conf_In_Temp_Dir(self):
        repo_root = self.test_temp_dir
        repo_name = 'repo_name'
        t = Repo_File_Paths( repo_root, repo_name )
        fn = t.svnserve_conf_full_name()

        import os
        os.makedirs( t.conf_folder() ) # force path to cfg

        Write_Ini_for_CFG( fn, 'some_section', { 'option' : 'value' } )
        f = open( fn )
        self.assertEqual(f.read(), '[some_section]\noption = value\n\n')
        f.close()

    def test_SVN_Client(self):
        path = self.test_temp_dir + '/test_repo_name'
        print(path)
        import os
        print(os.path.isdir( path ))
        print(os.path.exists( path ))
        self.assertFalse(os.path.exists( path ))
        a = svn.admin.Admin( )
        a.create( path )
        print(os.path.isdir( path ))
        print(os.path.exists( path ))
        self.assertTrue(os.path.exists( path ))

        try:
            r = svn.remote.RemoteClient( path, 'u', 'p' )
        except Exception as e:
            print( e )

        print( r.info() )
        self.assertIsNone( r.info() )
{'fraction_non_alphanumeric': 0.11413765612543184, 'fraction_numerical': 0.0033218176986446984, 'mean_word_length': 2.422919508867667, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1178844', 'n_tokens_mistral': 2601, 'n_tokens_neox': 2572, 'n_words': 498}