예제 #1
0
def test_superchat(mocker):
    '''api互換processorのテスト:スパチャ'''
    processor = CompatibleProcessor()

    _json = _open_file("tests/testdata/compatible/superchat.json")

    _, chatdata = parser.parse(parser.get_contents(json.loads(_json)))
    data = {"video_id": "", "timeout": 7, "chatdata": chatdata}
    ret = processor.process([data])

    assert ret["kind"] == "youtube#liveChatMessageListResponse"
    assert ret["pollingIntervalMillis"] == data["timeout"] * 1000
    assert ret.keys() == {
        "kind", "etag", "pageInfo", "nextPageToken", "pollingIntervalMillis",
        "items"
    }
    assert ret["pageInfo"].keys() == {"totalResults", "resultsPerPage"}
    assert ret["items"][0].keys() == {
        "kind", "etag", "id", "snippet", "authorDetails"
    }
    assert ret["items"][0]["snippet"].keys() == {
        'type', 'liveChatId', 'authorChannelId', 'publishedAt',
        'hasDisplayContent', 'displayMessage', 'superChatDetails'
    }
    assert ret["items"][0]["authorDetails"].keys() == {
        'channelId', 'channelUrl', 'displayName', 'profileImageUrl',
        'isVerified', 'isChatOwner', 'isChatSponsor', 'isChatModerator'
    }
    assert ret["items"][0]["snippet"]["superChatDetails"].keys() == {
        'amountMicros', 'currency', 'amountDisplayString', 'tier',
        'backgroundColor'
    }
    assert "LCC." in ret["items"][0]["id"]
    assert ret["items"][0]["snippet"]["type"] == "superChatEvent"
예제 #2
0
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]"
예제 #3
0
def test_compatible_processor():
    stream = pytchat.create("Hj-wnLIYKjw",
                            seektime=6000,
                            processor=CompatibleProcessor())
    while stream.is_alive():
        chat = stream.get()
        for key in chat.keys():
            assert key in root_keys
        for key in chat["items"][0].keys():
            assert key in item_keys
        for key in chat["items"][0]["snippet"].keys():
            assert key in snippet_keys
        for key in chat["items"][0]["authorDetails"].keys():
            assert key in author_details_keys
        break