2007-12-14 03:26:25 +03:00
# Unix SMB/CIFS implementation.
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
2009-12-20 19:49:48 +03:00
#
2007-12-14 03:26:25 +03:00
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
2009-12-20 19:49:48 +03:00
#
2007-12-14 03:26:25 +03:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
2009-12-20 19:49:48 +03:00
#
2007-12-14 03:26:25 +03:00
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
2010-12-05 18:56:27 +03:00
""" Tests for samba.param. """
2008-05-22 01:59:34 +04:00
from samba import param
2010-06-19 20:58:18 +04:00
import samba . tests
2016-12-10 16:11:04 +03:00
import os
2010-06-19 20:58:18 +04:00
2016-12-10 16:11:04 +03:00
class LoadParmTestCase ( samba . tests . TestCaseInTempDir ) :
def setUp ( self ) :
super ( LoadParmTestCase , self ) . setUp ( )
self . tempf = os . path . join ( self . tempdir , " test " )
open ( self . tempf , ' w ' ) . write ( " empty " )
def tearDown ( self ) :
os . unlink ( self . tempf )
super ( LoadParmTestCase , self ) . tearDown ( )
2007-12-14 03:26:25 +03:00
def test_init ( self ) :
file = param . LoadParm ( )
self . assertTrue ( file is not None )
2007-12-14 16:28:21 +03:00
def test_length ( self ) :
2007-12-14 03:26:25 +03:00
file = param . LoadParm ( )
2020-02-07 01:02:38 +03:00
self . assertEqual ( 0 , len ( file ) )
2007-12-14 03:26:25 +03:00
2007-12-18 01:16:12 +03:00
def test_set_workgroup ( self ) :
file = param . LoadParm ( )
file . set ( " workgroup " , " bla " )
2020-02-07 01:02:38 +03:00
self . assertEqual ( " BLA " , file . get ( " workgroup " ) )
2007-12-18 01:16:12 +03:00
def test_is_mydomain ( self ) :
file = param . LoadParm ( )
file . set ( " workgroup " , " bla " )
self . assertTrue ( file . is_mydomain ( " BLA " ) )
self . assertFalse ( file . is_mydomain ( " FOOBAR " ) )
def test_is_myname ( self ) :
file = param . LoadParm ( )
file . set ( " netbios name " , " bla " )
self . assertTrue ( file . is_myname ( " BLA " ) )
self . assertFalse ( file . is_myname ( " FOOBAR " ) )
2008-01-24 01:15:39 +03:00
def test_load_default ( self ) :
file = param . LoadParm ( )
file . load_default ( )
2007-12-14 03:26:25 +03:00
2012-06-11 19:52:57 +04:00
def test_section_nonexistent ( self ) :
2009-12-20 19:49:48 +03:00
samba_lp = param . LoadParm ( )
samba_lp . load_default ( )
2012-06-11 19:52:57 +04:00
self . assertRaises ( KeyError , samba_lp . __getitem__ , " nonexistent " )
2016-09-13 12:22:38 +03:00
def test_log_level ( self ) :
samba_lp = param . LoadParm ( )
samba_lp . set ( " log level " , " 5 auth:4 " )
2020-02-07 01:02:38 +03:00
self . assertEqual ( 5 , samba_lp . log_level ( ) )
2016-09-13 12:22:38 +03:00
2016-12-10 16:11:04 +03:00
def test_dump ( self ) :
samba_lp = param . LoadParm ( )
2023-06-06 14:28:13 +03:00
# Just test successful method execution (outputs to stdout)
2020-02-07 01:02:38 +03:00
self . assertEqual ( None , samba_lp . dump ( ) )
2016-12-10 16:11:04 +03:00
def test_dump_to_file ( self ) :
samba_lp = param . LoadParm ( )
2020-02-07 01:02:38 +03:00
self . assertEqual ( None , samba_lp . dump ( False , self . tempf ) )
2016-12-10 16:11:04 +03:00
content = open ( self . tempf , ' r ' ) . read ( )
self . assertIn ( ' [global] ' , content )
self . assertIn ( ' interfaces ' , content )
def test_dump_a_parameter ( self ) :
samba_lp = param . LoadParm ( )
samba_lp . load_default ( )
2023-06-06 14:28:13 +03:00
# Just test successful method execution
2020-02-07 01:02:38 +03:00
self . assertEqual ( None , samba_lp . dump_a_parameter ( ' interfaces ' ) )
2016-12-10 16:11:04 +03:00
def test_dump_a_parameter_to_file ( self ) :
samba_lp = param . LoadParm ( )
samba_lp . load_default ( )
2020-02-07 01:02:38 +03:00
self . assertEqual ( None ,
2016-12-10 16:11:04 +03:00
samba_lp . dump_a_parameter ( ' interfaces ' ,
' global ' ,
self . tempf ) )
content = open ( self . tempf , ' r ' ) . read ( )
2019-01-24 00:29:19 +03:00
self . assertIn ( ' 10.53.57. ' , content )
2016-12-10 16:11:04 +03:00
def test_samdb_url ( self ) :
samba_lp = param . LoadParm ( )
samdb_url = samba_lp . samdb_url ( )
self . assertTrue ( samdb_url . startswith ( ' tdb:// ' ) )
self . assertTrue ( samdb_url . endswith ( ' /sam.ldb ' ) )