Make _load_data_file public
Turns out this method is generally useful, so it should be public. The old private method is maintained as is, with the public version simply being a facade over it. In the future we may wish to consider extracting it all to a utility function, but this is the minimal change to get some usefulness. Tests are updated accordingly.
This commit is contained in:
parent
87f389688a
commit
83b50808a0
@ -174,6 +174,10 @@ class HTTPTestCase(testtools.TestCase):
|
||||
|
||||
return message
|
||||
|
||||
def load_data_file(self, filename):
|
||||
"""Read a file from the current test directory."""
|
||||
return self._load_data_file(filename)
|
||||
|
||||
def _assert_response(self):
|
||||
"""Compare the response with expected data."""
|
||||
self._test_status(self.test_data['status'], self.response['status'])
|
||||
@ -505,7 +509,7 @@ class HTTPTestCase(testtools.TestCase):
|
||||
"""
|
||||
if isinstance(data, str):
|
||||
if data.startswith('<@'):
|
||||
info = self._load_data_file(data.replace('<@', '', 1))
|
||||
info = self.load_data_file(data.replace('<@', '', 1))
|
||||
if utils.not_binary(content_type):
|
||||
data = six.text_type(info, 'UTF-8')
|
||||
else:
|
||||
|
@ -35,7 +35,7 @@ class DataFileTest(unittest.TestCase):
|
||||
|
||||
def _assert_content_read(self, filepath):
|
||||
self.assertEqual(
|
||||
'dummy content', self.http_case._load_data_file(filepath))
|
||||
'dummy content', self.http_case.load_data_file(filepath))
|
||||
|
||||
def test_load_file(self, m_open):
|
||||
self.http_case.test_directory = '.'
|
||||
@ -52,7 +52,7 @@ class DataFileTest(unittest.TestCase):
|
||||
filepath = '/top-level.private'
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
self.http_case._load_data_file(filepath)
|
||||
self.http_case.load_data_file(filepath)
|
||||
self.assertFalse(m_open.called)
|
||||
|
||||
def test_load_file_in_parent_dir(self, m_open):
|
||||
@ -60,7 +60,7 @@ class DataFileTest(unittest.TestCase):
|
||||
filepath = '../file-in-parent-dir.txt'
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
self.http_case._load_data_file(filepath)
|
||||
self.http_case.load_data_file(filepath)
|
||||
self.assertFalse(m_open.called)
|
||||
|
||||
def test_load_file_within_test_directory(self, m_open):
|
||||
@ -73,5 +73,5 @@ class DataFileTest(unittest.TestCase):
|
||||
self.http_case.test_directory = '/a/b/c'
|
||||
filepath = '../../b/E/file-in-test-dir.txt'
|
||||
with self.assertRaises(ValueError):
|
||||
self.http_case._load_data_file(filepath)
|
||||
self.http_case.load_data_file(filepath)
|
||||
self.assertFalse(m_open.called)
|
||||
|
Loading…
x
Reference in New Issue
Block a user