From 7996c6adad80d47e58a949139d0793c2fa7f8659 Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Thu, 9 Jan 2020 00:15:36 +0900 Subject: [PATCH] Add test --- tests/test_compatible_processor.py | 15 ++ tests/testdata/unregistered_currency.json | 160 ++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 tests/testdata/unregistered_currency.json diff --git a/tests/test_compatible_processor.py b/tests/test_compatible_processor.py index 39cf9fe..49cfa9c 100644 --- a/tests/test_compatible_processor.py +++ b/tests/test_compatible_processor.py @@ -124,6 +124,21 @@ def test_superchat(mocker): assert "LCC." in ret["items"][0]["id"] assert ret["items"][0]["snippet"]["type"]=="superChatEvent" +def test_unregistered_currency(mocker): + processor = CompatibleProcessor() + + _json = _open_file("tests/testdata/unregistered_currency.json") + + _, chatdata = parser.parse(parser.get_contents(json.loads(_json))) + + data = { + "video_id" : "", + "timeout" : 7, + "chatdata" : chatdata + } + ret = processor.process([data]) + assert ret["items"][0]["snippet"]["superChatDetails"]["currency"] == "[UNREGISTERD]" + def _open_file(path): with open(path,mode ='r',encoding = 'utf-8') as f: diff --git a/tests/testdata/unregistered_currency.json b/tests/testdata/unregistered_currency.json new file mode 100644 index 0000000..5318c8c --- /dev/null +++ b/tests/testdata/unregistered_currency.json @@ -0,0 +1,160 @@ +{ + "timing": { + "info": { + "st": 164 + } + }, + "csn": "", + "response": { + "responseContext": { + "serviceTrackingParams": [{ + "service": "CSI", + "params": [{ + "key": "GetLiveChat_rid", + "value": "" + }, { + "key": "c", + "value": "WEB" + }, { + "key": "cver", + "value": "2.20191219.03.01" + }, { + "key": "yt_li", + "value": "0" + }] + }, { + "service": "GFEEDBACK", + "params": [{ + "key": "e", + "value": "" + }, { + "key": "logged_in", + "value": "0" + }] + }, { + "service": "GUIDED_HELP", + "params": [{ + "key": "logged_in", + "value": "0" + }] + }, { + "service": "ECATCHER", + "params": [{ + "key": "client.name", + "value": "WEB" + }, { + "key": "client.version", + "value": "2.2" + }, { + "key": "innertube.build.changelist", + "value": "228" + }, { + "key": "innertube.build.experiments.source_version", + "value": "2858" + }, { + "key": "innertube.build.label", + "value": "youtube.ytfe.innertube_" + }, { + "key": "innertube.build.timestamp", + "value": "154" + }, { + "key": "innertube.build.variants.checksum", + "value": "e" + }, { + "key": "innertube.run.job", + "value": "ytfe-innertube-replica-only.ytfe" + }] + }], + "webResponseContextExtensionData": { + "ytConfigData": { + "csn": "ADw", + "visitorData": "%3D%3D" + } + } + }, + "continuationContents": { + "liveChatContinuation": { + "continuations": [{ + "timedContinuationData": { + "timeoutMs": 10000, + "continuation": "continuation" + } + }], + "actions": [{ + "addChatItemAction": { + "item": { + "liveChatPaidMessageRenderer": { + "id": "dummy_id", + "timestampUsec": "1576850000000000", + "authorName": { + "simpleText": "author_name" + }, + "authorPhoto": { + "thumbnails": [ + { + "url": "https://yt3.ggpht.com/------------/AAAAAAAAAAA/AAAAAAAAAAA/xxxxxxxxxxxx/s32-x-x-xx-xx-xx-c0xffffff/photo.jpg", + "width": 32, + "height": 32 + }, + { + "url": "https://yt3.ggpht.com/------------/AAAAAAAAAAA/AAAAAAAAAAA/xxxxxxxxxxxx/s32-x-x-xx-xx-xx-c0xffffff/photo.jpg", + "width": 64, + "height": 64 + } + ] + }, + "purchaseAmountText": { + "simpleText": "[UNREGISTERD]10,800" + }, + "message": { + "runs": [ + { + "text": "This is unregistered currency." + } + ] + }, + "headerBackgroundColor": 4291821568, + "headerTextColor": 4294967295, + "bodyBackgroundColor": 4293271831, + "bodyTextColor": 4294967295, + "authorExternalChannelId": "http://www.youtube.com/channel/author_channel_url", + "authorNameTextColor": 3019898879, + "contextMenuEndpoint": { + "commandMetadata": { + "webCommandMetadata": { + "ignoreNavigation": true + } + }, + "liveChatItemContextMenuEndpoint": { + "params": "___params___" + } + }, + "timestampColor": 2164260863, + "contextMenuAccessibility": { + "accessibilityData": { + "label": "コメントの操作" + } + } + } + }, "clientId": "00000000000000000000" + } + } + ]} + }, + + "xsrf_token": "xsrf_token", + "url": "/live_chat/get_live_chat?continuation=0", + "endpoint": { + "commandMetadata": { + "webCommandMetadata": { + "url": "/live_chat/get_live_chat?continuation=0", + "rootVe": 0 + } + }, + "urlEndpoint": { + "url": "/live_chat/get_live_chat?continuation=0" + } + } + } +} + \ No newline at end of file