forked from 00dani/lemoncurry
Refactor how the routing for different kinds of entry works - this will make implementing webmentions easier, hopefully?
This commit is contained in:
parent
c359b7640e
commit
9580068c5b
12 changed files with 136 additions and 73 deletions
|
@ -6,16 +6,21 @@ from .. import breadcrumbs as b
|
|||
|
||||
@pytest.fixture
|
||||
def nested_crumbs():
|
||||
x = {'route': 'nc.x', 'label': 'x', 'parent': None}
|
||||
y = {'route': 'nc.y', 'label': 'y', 'parent': 'nc.x'}
|
||||
z = {'route': 'nc.z', 'label': 'z', 'parent': 'nc.y'}
|
||||
x = b.Crumb('nc.x', label='x')
|
||||
y = b.Crumb('nc.y', label='y', parent='nc.x')
|
||||
z = b.Crumb('nc.z', label='z', parent='nc.y')
|
||||
crumbs = (x, y, z)
|
||||
|
||||
for crumb in crumbs:
|
||||
b.breadcrumbs[crumb['route']] = crumb
|
||||
b.breadcrumbs[crumb.route] = crumb
|
||||
yield namedtuple('NestedCrumbs', 'x y z')(*crumbs)
|
||||
for crumb in crumbs:
|
||||
del b.breadcrumbs[crumb['route']]
|
||||
del b.breadcrumbs[crumb.route]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def crumb_match(nested_crumbs):
|
||||
return namedtuple('Match', 'view_name')(nested_crumbs.z.route)
|
||||
|
||||
|
||||
class TestAdd:
|
||||
|
@ -24,9 +29,10 @@ class TestAdd:
|
|||
assert route not in b.breadcrumbs
|
||||
b.add(route, 'some label')
|
||||
assert route in b.breadcrumbs
|
||||
assert b.breadcrumbs[route] == {
|
||||
'route': route, 'label': 'some label', 'parent': None
|
||||
}
|
||||
assert b.breadcrumbs[route] == route
|
||||
route = b.breadcrumbs[route]
|
||||
assert route.label == 'some label'
|
||||
assert route.parent is None
|
||||
|
||||
def test_inserts_a_breadcrumb_with_parent(self):
|
||||
route = 'tests.add.with_parent'
|
||||
|
@ -34,14 +40,15 @@ class TestAdd:
|
|||
assert route not in b.breadcrumbs
|
||||
b.add(route, 'child label', parent)
|
||||
assert route in b.breadcrumbs
|
||||
assert b.breadcrumbs[route] == {
|
||||
'route': route, 'label': 'child label', 'parent': parent
|
||||
}
|
||||
assert b.breadcrumbs[route] == route
|
||||
route = b.breadcrumbs[route]
|
||||
assert route.label == 'child label'
|
||||
assert route.parent == parent
|
||||
|
||||
|
||||
class TestFind:
|
||||
def test_finds_chain_of_crumbs(self, nested_crumbs):
|
||||
crumbs = b.find(nested_crumbs.z['route'])
|
||||
def test_finds_chain_of_crumbs(self, nested_crumbs, crumb_match):
|
||||
crumbs = b.find(crumb_match)
|
||||
assert len(crumbs) == 3
|
||||
assert crumbs[0] == nested_crumbs.x
|
||||
assert crumbs[1] == nested_crumbs.y
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue