提交
This commit is contained in:
1 parent
f7d1004e6b
commit
310b2efe8a
91 files changed
+14420
-10840
No files matched your search
@@ -0,0 +1,74 @@
|
||||
import unittest
|
||||
|
||||
from app.services.oa_post_select import (
|
||||
extract_post_ids,
|
||||
post_contains_match,
|
||||
validate_post_form_values,
|
||||
)
|
||||
|
||||
|
||||
class TestOaPostSelect(unittest.TestCase):
|
||||
def test_validate_multi_ok(self):
|
||||
schema = {
|
||||
"rule": [
|
||||
{
|
||||
"type": "post",
|
||||
"field": "F1",
|
||||
"title": "职位",
|
||||
"props": {"multiple": True},
|
||||
}
|
||||
]
|
||||
}
|
||||
data = {"F1": [{"id": "p1", "name": "工程师"}, {"id": "p2", "name": "经理"}]}
|
||||
self.assertEqual(validate_post_form_values(schema, data), [])
|
||||
|
||||
def test_validate_required_empty(self):
|
||||
schema = {
|
||||
"rule": [
|
||||
{
|
||||
"type": "post",
|
||||
"field": "F1",
|
||||
"title": "职位",
|
||||
"$required": True,
|
||||
"props": {"multiple": True},
|
||||
}
|
||||
]
|
||||
}
|
||||
errs = validate_post_form_values(schema, {"F1": []})
|
||||
self.assertTrue(any("必填" in e for e in errs))
|
||||
|
||||
def test_validate_max(self):
|
||||
schema = {
|
||||
"rule": [
|
||||
{
|
||||
"type": "post",
|
||||
"field": "F1",
|
||||
"title": "职位",
|
||||
"props": {"multiple": True, "max": 1},
|
||||
}
|
||||
]
|
||||
}
|
||||
errs = validate_post_form_values(
|
||||
schema,
|
||||
{"F1": [{"id": "p1", "name": "A"}, {"id": "p2", "name": "B"}]},
|
||||
)
|
||||
self.assertTrue(any("上限" in e for e in errs))
|
||||
|
||||
def test_extract_and_contains(self):
|
||||
self.assertEqual(extract_post_ids({"id": "p1", "name": "A"}), {"p1"})
|
||||
self.assertTrue(
|
||||
post_contains_match(
|
||||
[{"id": "p1", "name": "A"}],
|
||||
["p1", "p2"],
|
||||
)
|
||||
)
|
||||
self.assertFalse(
|
||||
post_contains_match(
|
||||
[{"id": "p3", "name": "C"}],
|
||||
["p1", "p2"],
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user