From 945f00f53104520b78110a15918ee68451660a9a Mon Sep 17 00:00:00 2001 From: Azide Date: Thu, 1 Sep 2022 01:59:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/platforms/static/tag_cases.json | 129 ++++++++++++++++++++ tests/platforms/test_platform_tag_filter.py | 19 +++ 2 files changed, 148 insertions(+) create mode 100644 tests/platforms/static/tag_cases.json create mode 100644 tests/platforms/test_platform_tag_filter.py diff --git a/tests/platforms/static/tag_cases.json b/tests/platforms/static/tag_cases.json new file mode 100644 index 0000000..01c9af9 --- /dev/null +++ b/tests/platforms/static/tag_cases.json @@ -0,0 +1,129 @@ +[ + { + "case": { + "post_tags": [ + "111", + "222", + "333", + "444" + ], + "subscribed_tags": [ + "222" + ], + "banned_tags": [ + "555" + ] + }, + "result": false + }, + { + "case": { + "post_tags": [ + "111", + "222", + "333", + "444" + ], + "subscribed_tags": [], + "banned_tags": [ + "555" + ] + }, + "result": false + }, + { + "case": { + "post_tags": [ + "111", + "222", + "333", + "444" + ], + "subscribed_tags": [], + "banned_tags": [ + "444" + ] + }, + "result": true + }, + { + "case": { + "post_tags": [ + "111", + "222", + "333", + "444" + ], + "subscribed_tags": [ + "222" + ], + "banned_tags": [] + }, + "result": false + }, + { + "case": { + "post_tags": [ + "111", + "222", + "333", + "444" + ], + "subscribed_tags": [], + "banned_tags": [] + }, + "result": false + }, + { + "case": { + "post_tags": [ + "111", + "222", + "333", + "444" + ], + "subscribed_tags": ["111","555","666"], + "banned_tags": [] + }, + "result": false + }, + { + "case": { + "post_tags": [ + "111", + "222", + "333", + "444" + ], + "subscribed_tags": ["111","555"], + "banned_tags": ["333"] + }, + "result": true + }, + { + "case": { + "post_tags": [ + "111", + "222", + "333", + "444" + ], + "subscribed_tags": ["111","333"], + "banned_tags": ["111"] + }, + "result": true + }, + { + "case": { + "post_tags": [ + "111", + "222", + "333", + "444" + ], + "subscribed_tags": ["222"], + "banned_tags": ["555","333"] + }, + "result": true + } +] \ No newline at end of file diff --git a/tests/platforms/test_platform_tag_filter.py b/tests/platforms/test_platform_tag_filter.py new file mode 100644 index 0000000..c644b05 --- /dev/null +++ b/tests/platforms/test_platform_tag_filter.py @@ -0,0 +1,19 @@ +import pytest +from nonebug.app import App + +from .utils import get_json + + +@pytest.fixture(scope="module") +def test_cases(): + return get_json("tag_cases.json") + + +@pytest.mark.asyncio +async def test_filter_user_custom_tag(app: App, test_cases): + from nonebot_bison.platform import platform_manager + + bilibili = platform_manager["bilibili"] + for case in test_cases: + res = bilibili.is_banned_post(**case["case"]) + assert res == case["result"]