Skip to content

Commit 99b845a

Browse files
xcp/accessor.py: Fix test_accessor.py for Python3(more updates later)
Signed-off-by: Bernhard Kaindl <bernhard.kaindl@cloud.com>
1 parent 2a3b324 commit 99b845a

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

tests/test_accessor.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@
33
import xcp.accessor
44

55
class TestAccessor(unittest.TestCase):
6-
def test_http(self):
7-
#raise unittest.SkipTest("comment out if you really mean it")
8-
a = xcp.accessor.createAccessor("https://updates.xcp-ng.org/netinstall/8.2.1", True)
6+
def check_repo_access(self, a):
7+
"""Common helper function for testing Accessor.access() with repo files"""
98
a.start()
109
self.assertTrue(a.access('.treeinfo'))
1110
self.assertFalse(a.access('no_such_file'))
1211
self.assertEqual(a.lastError, 404)
1312
a.finish()
1413

14+
def test_http_accessor_access(self):
15+
"""Test HTTPAccessor.access()"""
16+
17+
# Temporary: To be obsoleted by a dedicated test case using a pytest-native
18+
# httpd which will cover code paths like HTTP Basic Auth in an upcoming commit:
19+
a = xcp.accessor.createAccessor("https://updates.xcp-ng.org/netinstall/8.2.1", True)
20+
self.check_repo_access(a)
21+
1522
def test_file(self):
23+
"""Test FileAccessor.access()"""
24+
1625
a = xcp.accessor.createAccessor("file://tests/data/repo/", True)
17-
a.start()
18-
self.assertTrue(a.access('.treeinfo'))
19-
self.assertFalse(a.access('no_such_file'))
20-
self.assertEqual(a.lastError, 404)
21-
a.finish()
26+
self.check_repo_access(a)
27+
28+
def test_filesystem_accessor_access(self):
29+
"""Test FilesystemAccessor.access()"""
30+
31+
a = xcp.accessor.FilesystemAccessor("tests/data/repo/", True)
32+
self.check_repo_access(a)

xcp/accessor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(self, location, ro):
9696

9797
def openAddress(self, address):
9898
try:
99-
filehandle = open(os.path.join(self.location, address), 'r')
99+
filehandle = open(os.path.join(self.location, address), "rb")
100100
except OSError as e:
101101
if e.errno == errno.EIO:
102102
self.lastError = 5
@@ -217,7 +217,7 @@ def __init__(self, baseAddress, ro):
217217

218218
def openAddress(self, address):
219219
try:
220-
file = open(os.path.join(self.baseAddress, address))
220+
file = open(os.path.join(self.baseAddress, address), "rb")
221221
except IOError as e:
222222
if e.errno == errno.EIO:
223223
self.lastError = 5

0 commit comments

Comments
 (0)