Init Project Flexly CMS
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import unittest
|
||||
|
||||
from site_engine.core.values import Binding, LinkRef, Query, ValueShapeError, classify
|
||||
|
||||
|
||||
class ValuesTest(unittest.TestCase):
|
||||
def test_binding_everywhere(self):
|
||||
self.assertEqual(classify({"bind": "entry.title"}), Binding("entry.title"))
|
||||
self.assertEqual(classify({"bind": "page.body"}, "markdown"), Binding("page.body"))
|
||||
|
||||
def test_binding_root_must_be_known(self):
|
||||
with self.assertRaises(ValueShapeError):
|
||||
classify({"bind": "os.environ"})
|
||||
|
||||
def test_link_only_for_link_fields(self):
|
||||
raw = {"page": "contacts", "label": "Связаться"}
|
||||
self.assertEqual(classify(raw, "link"), LinkRef("page", "contacts", "Связаться", False))
|
||||
self.assertEqual(classify(raw, None), raw) # для group это просто объект
|
||||
|
||||
def test_link_needs_exactly_one_target(self):
|
||||
with self.assertRaises(ValueShapeError):
|
||||
classify({"page": "a", "url": "/b"}, "link")
|
||||
|
||||
def test_query_mvp_subset(self):
|
||||
q = classify({"query": {"collection": "services", "where": {"tech": {"in": ["python"]}}, "limit": 3}}, "query")
|
||||
self.assertEqual(q, Query("services", None, {"tech": {"in": ["python"]}}, None, 3))
|
||||
|
||||
def test_query_rejects_deferred_features(self):
|
||||
for bad in ({"collection": "s", "offset": 1}, {"collection": "s", "paginate": 10},
|
||||
{"collection": "s", "where": {"x": {"contains": "a"}}}):
|
||||
with self.assertRaises(ValueShapeError):
|
||||
classify({"query": bad}, "query")
|
||||
|
||||
def test_query_field_rejects_plain_dict(self):
|
||||
with self.assertRaises(ValueShapeError):
|
||||
classify({"collection": "s"}, "query")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user