diff options
author | Lumir Balhar <lbalhar@redhat.com> | 2016-12-13 11:20:42 +0100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2017-03-10 07:31:10 +0100 |
commit | 9c55bb9f657268de20e86222a57f4cbce73f8f27 (patch) | |
tree | 48ccebb9cce4ed4b106f020a909dfde59cf88a64 /python | |
parent | b454b0903c876f1cbc9447610ea243bf7ef2ea1e (diff) | |
download | samba-9c55bb9f657268de20e86222a57f4cbce73f8f27.tar.gz |
python: samba.tests.glue: Add new tests for samba._glue.
Add new file with tests of samba._glue module.
Signed-off-by: Lumir Balhar <lbalhar@redhat.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Diffstat (limited to 'python')
-rw-r--r-- | python/samba/tests/glue.py | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/python/samba/tests/glue.py b/python/samba/tests/glue.py new file mode 100644 index 00000000000..5f112f00ba0 --- /dev/null +++ b/python/samba/tests/glue.py @@ -0,0 +1,74 @@ +# Unix SMB/CIFS implementation. +# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 +# +# 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. +# +# 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. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +"""Tests for the _glue Python bindings.""" + +from samba import _glue +from samba import param +import samba.tests + + +class GlueTests(samba.tests.TestCase): + + def setUp(self): + super(GlueTests, self).setUp() + + def test_generate_random_str(self): + string = _glue.generate_random_str(10) + self.assertEqual(type(string), str) + self.assertEqual(len(string), 10) + + def test_generate_random_password(self): + password = _glue.generate_random_password(5, 10) + self.assertEqual(type(password), str) + self.assertTrue(5 <= len(password) <= 10) + + def test_unix2nttime(self): + self.assertEqual(_glue.unix2nttime(1), 116444736010000000) + + def test_nttime2unix(self): + self.assertEqual(_glue.nttime2unix(116444736010000000), 1) + + def test_nttime2string(self): + string = _glue.nttime2string(116444736010000000) + self.assertEqual(type(string), str) + self.assertIn('1970', string) + + def test_debug_level(self): + prev_level = _glue.get_debug_level() + try: + self.assertIsNone(_glue.set_debug_level(0)) + self.assertEqual(_glue.get_debug_level(), 0) + self.assertIsNone(_glue.set_debug_level(5)) + self.assertEqual(_glue.get_debug_level(), 5) + finally: + _glue.set_debug_level(prev_level) + + def test_interface_ips(self): + lp = param.LoadParm() + ips = _glue.interface_ips(lp) + self.assertEqual(type(ips), list) + + def test_strcasecmp(self): + self.assertEqual(_glue.strcasecmp_m('aA', 'Aa'), 0) + self.assertNotEqual(_glue.strcasecmp_m('ab', 'Aa'), 0) + + def test_strstr_m(self): + string = 'testing_string_num__one' + self.assertEqual(_glue.strstr_m(string, '_'), '_string_num__one') + self.assertEqual(_glue.strstr_m(string, '__'), '__one') + self.assertEqual(_glue.strstr_m(string, 'ring'), 'ring_num__one') |