From: Tim Beale Date: Sun, 2 Dec 2018 22:01:14 +0000 (+1300) Subject: tests: Add SMB Py binding .chkpath() test case X-Git-Url: http://git.samba.org/samba.git/?p=amitay%2Fsamba.git;a=commitdiff_plain;h=fa77209dea48c623fa3052a65b2d8dad9f146198 tests: Add SMB Py binding .chkpath() test case chkpath was only tested incidentally (and that assertion was wrong). Add a proper test to prove it works correctly. We can then clean-up the incorrect assertion in the next patch. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676 Signed-off-by: Tim Beale Reviewed-by: Andrew Bartlett --- diff --git a/python/samba/tests/smb.py b/python/samba/tests/smb.py index e0e60e37102..6f33ff105fc 100644 --- a/python/samba/tests/smb.py +++ b/python/samba/tests/smb.py @@ -65,6 +65,26 @@ class SMBTests(samba.tests.TestCase): self.conn.unlink(test_file) self.assertFalse(self.conn.chkpath(test_file)) + def test_chkpath(self): + """Tests .chkpath determines whether or not a directory exists""" + + self.assertTrue(self.conn.chkpath(test_dir)) + + # should return False for a non-existent directory + bad_dir = self.make_sysvol_path(test_dir, 'dont_exist') + self.assertFalse(self.conn.chkpath(bad_dir)) + + # should return False for files (because they're not directories) + self.conn.savefile(test_file, binary_contents) + self.assertFalse(self.conn.chkpath(test_file)) + + # check correct result after creating and then deleting a new dir + new_dir = self.make_sysvol_path(test_dir, 'test-new') + self.conn.mkdir(new_dir) + self.assertTrue(self.conn.chkpath(new_dir)) + self.conn.rmdir(new_dir) + self.assertFalse(self.conn.chkpath(new_dir)) + def test_save_load_text(self): self.conn.savefile(test_file, test_contents.encode('utf8')) @@ -99,3 +119,7 @@ class SMBTests(samba.tests.TestCase): contents = self.conn.loadfile(test_file) self.assertEquals(contents, binary_contents, msg='contents of test file did not match what was written') + + def make_sysvol_path(self, dirpath, filename): + # return the dir + filename as a sysvol path + return os.path.join(dirpath, filename).replace('/', '\\')