summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorTim Beale <timbeale@catalyst.net.nz>2018-12-03 11:15:14 +1300
committerAndrew Bartlett <abartlet@samba.org>2018-12-12 04:38:13 +0100
commitb84cea18fcc54f599db9580fd027b8d530d6b4bd (patch)
treefb57143fa620118e60dfc13cd48fb976ae3e95dd /python
parentfa77209dea48c623fa3052a65b2d8dad9f146198 (diff)
downloadsamba-b84cea18fcc54f599db9580fd027b8d530d6b4bd.tar.gz
tests: Fix SMB Py binding .unlink() test case assertion
The current assertion would never detect if the unlink API is broken. The chkpath() API is only useful for checking if directories exist, so it will always return False for a regular file (regardless of whether the file actually exists or not). Rework the test case so we assert that the file exists by trying to read its contents (which will throw an error if the file doesn't exist). BUG: https://bugzilla.samba.org/show_bug.cgi?id=13676 Signed-off-by: Tim Beale <timbeale@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'python')
-rw-r--r--python/samba/tests/smb.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/python/samba/tests/smb.py b/python/samba/tests/smb.py
index 6f33ff105fc..e4366ce7b52 100644
--- a/python/samba/tests/smb.py
+++ b/python/samba/tests/smb.py
@@ -20,6 +20,8 @@ import os
import random
import sys
from samba import smb
+from samba import NTSTATUSError
+from samba.ntstatus import NT_STATUS_OBJECT_NAME_NOT_FOUND
PY3 = sys.version_info[0] == 3
addom = 'addom.samba.example.com/'
@@ -57,13 +59,30 @@ class SMBTests(samba.tests.TestCase):
self.assertIn('Policies', ls,
msg='"Policies" directory not found in sysvol')
+ def file_exists(self, filepath):
+ """Returns whether a regular file exists (by trying to open it)"""
+ try:
+ self.conn.loadfile(filepath)
+ exists = True;
+ except NTSTATUSError as err:
+ if err.args[0] == NT_STATUS_OBJECT_NAME_NOT_FOUND:
+ exists = False
+ else:
+ raise err
+ return exists
+
def test_unlink(self):
"""
The smb.unlink API should delete file
"""
+ # create the test file
+ self.assertFalse(self.file_exists(test_file))
self.conn.savefile(test_file, binary_contents)
+ self.assertTrue(self.file_exists(test_file))
+
+ # delete it and check that it's gone
self.conn.unlink(test_file)
- self.assertFalse(self.conn.chkpath(test_file))
+ self.assertFalse(self.file_exists(test_file))
def test_chkpath(self):
"""Tests .chkpath determines whether or not a directory exists"""