| 1 |
""" |
| 2 |
cloud_sptheme.tests -- test relbar_toc extension |
| 3 |
""" |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
import logging |
| 10 |
log = logging.getLogger(__name__) |
| 11 |
import os |
| 12 |
|
| •13 |
from unittest import mock |
| 14 |
|
| 15 |
from .utils import TestCase, unittest |
| 16 |
|
| 17 |
from cloud_sptheme.ext import relbar_links |
| 18 |
|
| 19 |
__all__ = [ |
| 20 |
] |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
class UtilsTestCase(TestCase): |
| 43 |
|
| 44 |
def setUp(self): |
| 45 |
super(UtilsTestCase, self).setUp() |
| 46 |
|
| 47 |
|
| 48 |
patch = mock.patch.object(relbar_links, "_", side_effect=lambda s: s) |
| •49 |
patch.start() |
| 50 |
self.addCleanup(patch.stop) |
| 51 |
|
| 52 |
def test_insert_no_links(self): |
| 53 |
""" |
| 54 |
test insert hooks -- with no links present (e.g. json builder) |
| 55 |
""" |
| 56 |
from cloud_sptheme.ext.relbar_links import insert_relbar_links |
| 57 |
app = mock.Mock() |
| 58 |
insert_relbar_links(app, None, None, {}, None) |
| 59 |
|
| 60 |
def test_insert_default(self): |
| 61 |
""" |
| 62 |
test insert hooks -- with default links |
| 63 |
""" |
| 64 |
from cloud_sptheme.ext.relbar_links import insert_relbar_links |
| 65 |
app = mock.Mock() |
| 66 |
app.config.master_doc = "test-contents" |
| 67 |
app.config.relbar_links = ["toc"] |
| 68 |
app.config.relbar_links_after = ["next", "previous"] |
| 69 |
links = [ |
| 70 |
("genindex", "General Index", "I", "genidx"), |
| 71 |
("next-test-page", "Next Page", "N", "next"), |
| 72 |
("previous-test-page", "Previous Page", "P", "previous"), |
| 73 |
] |
| 74 |
insert_relbar_links(app, None, None, dict(rellinks=links), None) |
| 75 |
self.assertEqual(links, [ |
| 76 |
("genindex", "General Index", "I", "genidx"), |
| 77 |
("test-contents", "Table Of Contents", "C", "toc"), |
| 78 |
("next-test-page", "Next Page", "N", "next"), |
| 79 |
("previous-test-page", "Previous Page", "P", "previous"), |
| 80 |
]) |
| 81 |
|
| 82 |
def test_insert_custom(self): |
| 83 |
""" |
| 84 |
test insert hooks -- with custom links |
| 85 |
""" |
| 86 |
from cloud_sptheme.ext.relbar_links import insert_relbar_links |
| 87 |
app = mock.Mock() |
| 88 |
app.config.relbar_links = [dict(page="my-page", label="my page")] |
| 89 |
app.config.relbar_links_after = ["previous"] |
| 90 |
links = [ |
| 91 |
("genindex", "General Index", "I", "genidx"), |
| 92 |
("next-test-page", "Next Page", "N", "next"), |
| 93 |
("previous-test-page", "Previous Page", "P", "previous"), |
| 94 |
] |
| 95 |
insert_relbar_links(app, None, None, dict(rellinks=links), None) |
| 96 |
self.assertEqual(links, [ |
| 97 |
("genindex", "General Index", "I", "genidx"), |
| 98 |
("next-test-page", "Next Page", "N", "next"), |
| 99 |
("my-page", "my page", None, "my page"), |
| 100 |
("previous-test-page", "Previous Page", "P", "previous"), |
| 101 |
]) |
| 102 |
|
| 103 |
def test_parse_entry(self): |
| 104 |
""" |
| 105 |
test parse_entry() helper |
| 106 |
""" |
| 107 |
from cloud_sptheme.ext.relbar_links import parse_entry |
| 108 |
app = mock.Mock() |
| 109 |
app.config.master_doc = "test-master-doc" |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
self.assertRaises(ValueError, parse_entry, app, dict()) |
| 115 |
|
| 116 |
self.assertRaises(ValueError, parse_entry, app, dict(page="page")) |
| 117 |
|
| 118 |
self.assertRaises(ValueError, parse_entry, app, dict(label="label")) |
| 119 |
|
| 120 |
self.assertEqual(parse_entry(app, dict(page="page", label="label")), |
| 121 |
("page", "label", None, "label")) |
| 122 |
|
| 123 |
self.assertEqual(parse_entry(app, dict(page="page", title="title", key="key", label="label")), |
| 124 |
("page", "title", "key", "label")) |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
self.assertRaises(ValueError, parse_entry, app, ()) |
| 130 |
|
| 131 |
self.assertRaises(ValueError, parse_entry, app, ("a",)) |
| 132 |
|
| 133 |
self.assertEqual(parse_entry(app, ("page", "label")), |
| 134 |
("page", "label", None, "label")) |
| 135 |
|
| 136 |
self.assertRaises(ValueError, parse_entry, app, ("a", "b", "c")) |
| 137 |
|
| 138 |
self.assertEqual(parse_entry(app, ("page", "title", "key", "label")), |
| 139 |
("page", "title", "key", "label")) |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
self.assertEqual(parse_entry(app, "toc"), |
| 145 |
("test-master-doc", "Table Of Contents", "C", "toc")) |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|