def test_static_file_absolute_path(self, join_mock, is_file_mock): """ Testing StaticFile source with absolute path """ sudo.read_file = lambda path: 'content' is_file_mock.return_value = True with Environment("/base") as env: static_file = StaticFile("/absolute/path/file") content = static_file.get_content() self.assertEqual('content', content) self.assertEqual(is_file_mock.call_count, 1) self.assertEqual(join_mock.call_count, 0)
def test_static_file_relative_path(self, join_mock, is_file_mock): """ Testing StaticFile source with relative path """ sudo.read_file = lambda path: 'content' is_file_mock.return_value = True with Environment("/base") as env: static_file = StaticFile("relative/path/file") content = static_file.get_content() self.assertEqual('content', content) self.assertEqual(is_file_mock.call_count, 1) self.assertEqual(join_mock.call_count, 1) join_mock.assert_called_with('/base', 'files', 'relative/path/file')
def test_static_file_absolute_path(self, join_mock, open_mock): """ Testing StaticFile source with absolute path """ file_mock = MagicMock(name='file_mock') file_mock.__enter__.return_value = file_mock file_mock.read.return_value = 'content' open_mock.return_value = file_mock with Environment("/base") as env: static_file = StaticFile("/absolute/path/file") content = static_file.get_content() self.assertEqual('content', content) self.assertEqual(file_mock.read.call_count, 1) self.assertEqual(join_mock.call_count, 0)
def test_static_file_absolute_path(self, join_mock, open_mock): """ Testing StaticFile source with absolute path """ file_mock = MagicMock(name = 'file_mock') file_mock.__enter__.return_value = file_mock file_mock.read.return_value = 'content' open_mock.return_value = file_mock with Environment("/base") as env: static_file = StaticFile("/absolute/path/file") content = static_file.get_content() self.assertEqual('content', content) self.assertEqual(file_mock.read.call_count, 1) self.assertEqual(join_mock.call_count, 0)