|
@@ 75-91 (lines=17) @@
|
| 72 |
|
calls = [call(assets[0]), call(assets[1])] |
| 73 |
|
self.assertEqual(calls, mock_rm.call_args_list) |
| 74 |
|
|
| 75 |
|
@patch('os.path.isdir', Mock(return_value=False)) |
| 76 |
|
@patch('doorstop.core.document.Document.copy_assets') |
| 77 |
|
@patch('os.makedirs') |
| 78 |
|
@patch('builtins.open') |
| 79 |
|
def test_publish_document_copies_assets(self, mock_open, mock_makedirs, mock_copyassets): |
| 80 |
|
"""Verify that assets are published""" |
| 81 |
|
dirpath = os.path.join('mock', 'directory') |
| 82 |
|
assets_path = os.path.join(dirpath, 'assets') |
| 83 |
|
path = os.path.join(dirpath, 'published.custom') |
| 84 |
|
document = MockDocument('/some/path') |
| 85 |
|
mock_open.side_effect = lambda *args, **kw: mock.mock_open(read_data="$body").return_value |
| 86 |
|
# Act |
| 87 |
|
path2 = publisher.publish(document, path, '.html') |
| 88 |
|
# Assert |
| 89 |
|
self.assertIs(path, path2) |
| 90 |
|
mock_makedirs.assert_called_once_with(os.path.join(dirpath, Document.ASSETS)) |
| 91 |
|
mock_copyassets.assert_called_once_with(assets_path) |
| 92 |
|
|
| 93 |
|
def test_publish_document_unknown(self): |
| 94 |
|
"""Verify an exception is raised when publishing unknown formats.""" |
|
@@ 116-131 (lines=16) @@
|
| 113 |
|
self.assertEqual(expected_calls, mock_open.call_args_list) |
| 114 |
|
mock_index.assert_called_once_with(dirpath, tree=self.mock_tree) |
| 115 |
|
|
| 116 |
|
@patch('os.path.isdir', Mock(return_value=False)) |
| 117 |
|
@patch('os.makedirs') |
| 118 |
|
@patch('doorstop.core.publisher._index') |
| 119 |
|
@patch('builtins.open') |
| 120 |
|
def test_publish_tree_no_index(self, mock_open, mock_index, mock_makedirs): |
| 121 |
|
"""Verify a tree can be published.""" |
| 122 |
|
dirpath = os.path.join('mock', 'directory') |
| 123 |
|
mock_open.side_effect = lambda *args, **kw: mock.mock_open(read_data="$body").return_value |
| 124 |
|
expected_calls = [call(os.path.join('mock', 'directory', 'MOCK.html'), 'wb'), call(publisher.HTMLTEMPLATE, 'r')] |
| 125 |
|
# Act |
| 126 |
|
dirpath2 = publisher.publish(self.mock_tree, dirpath, index=False) |
| 127 |
|
# Assert |
| 128 |
|
self.assertIs(dirpath, dirpath2) |
| 129 |
|
self.assertEqual(0, mock_index.call_count) |
| 130 |
|
print(mock_open.call_args_list) |
| 131 |
|
self.assertEqual(expected_calls, mock_open.call_args_list) |
| 132 |
|
|
| 133 |
|
def test_index(self): |
| 134 |
|
"""Verify an HTML index can be created.""" |
|
@@ 100-114 (lines=15) @@
|
| 97 |
|
self.assertRaises(DoorstopError, |
| 98 |
|
publisher.publish, self.document, 'a.txt', '.a') |
| 99 |
|
|
| 100 |
|
@patch('os.path.isdir', Mock(return_value=False)) |
| 101 |
|
@patch('os.makedirs') |
| 102 |
|
@patch('doorstop.core.publisher._index') |
| 103 |
|
@patch('builtins.open') |
| 104 |
|
def test_publish_tree(self, mock_open, mock_index, mock_makedirs): |
| 105 |
|
"""Verify a tree can be published.""" |
| 106 |
|
dirpath = os.path.join('mock', 'directory') |
| 107 |
|
mock_open.side_effect = lambda *args, **kw: mock.mock_open(read_data="$body").return_value |
| 108 |
|
expected_calls = [call(os.path.join('mock', 'directory', 'MOCK.html'), 'wb'), call(publisher.HTMLTEMPLATE, 'r')] |
| 109 |
|
# Act |
| 110 |
|
dirpath2 = publisher.publish(self.mock_tree, dirpath) |
| 111 |
|
# Assert |
| 112 |
|
self.assertIs(dirpath, dirpath2) |
| 113 |
|
self.assertEqual(expected_calls, mock_open.call_args_list) |
| 114 |
|
mock_index.assert_called_once_with(dirpath, tree=self.mock_tree) |
| 115 |
|
|
| 116 |
|
@patch('os.path.isdir', Mock(return_value=False)) |
| 117 |
|
@patch('os.makedirs') |