def test_external_file_reader_local(self): with utils.ExternalFileReader(self._temp_file_path) as reader: self.assertEqual(os.path.abspath(self._temp_file_path), os.path.abspath(reader.path)) with utils.ExternalFileReader(os.path.abspath( self._temp_file_path)) as reader: self.assertEqual(os.path.abspath(self._temp_file_path), os.path.abspath(reader.path))
def test_external_file_reader_https_example(self): resource = 'https://example.com/index.html' with utils.ExternalFileReader(resource) as reader: self.assertTrue(os.path.exists(reader.path)) local_path = reader.path with open(reader.path, 'r') as page: content = page.read() self.assertTrue('Example' in content) self.assertFalse(os.path.exists(local_path))
def _test_external_file_reader(self, url): body = 'Example' * 200 responses.add('GET', url, body=body, stream=True) with utils.ExternalFileReader(url) as reader: self.assertTrue(os.path.exists(reader.path)) local_path = reader.path with open(reader.path, 'r') as page: content = page.read() self.assertEqual(body, content) self.assertFalse(os.path.exists(local_path))