combo/tests/test_cells.py

57 lines
1.2 KiB
Python

import pytest
from combo.data.models import Page, CellBase, TextCell, LinkCell
pytestmark = pytest.mark.django_db
def test_cell_reference():
page = Page()
page.save()
cell = TextCell()
cell.page = page
cell.text = 'foobar'
cell.order = 0
cell.save()
assert CellBase.get_cell(cell.get_reference()) == cell
def test_additional_label():
page = Page()
page.save()
cell = TextCell()
cell.page = page
cell.text = '<p>foobar</p>'
cell.order = 0
cell.save()
assert cell.get_additional_label() == 'foobar'
cell = TextCell()
cell.page = page
cell.text = '<p>%s</p>' % 'foo'*30
cell.order = 0
cell.save()
assert len(cell.get_additional_label()) < 100
assert '...' in cell.get_additional_label()
def test_link_cell():
page = Page()
page.save()
cell = LinkCell()
cell.page = page
cell.title = 'Example Site'
cell.url = 'http://example.net'
cell.order = 0
cell.save()
from django.template import Context
ctx = Context()
assert cell.render(ctx).strip() == '<a href="http://example.net">Example Site</a>'
assert cell.get_additional_label() == 'Example Site'