Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test validate_channel_id #657

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Scripts/validation.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from Scripts.shared_imports import *
import typing as T

def validate_video_id(
video_url_or_id,
silent: bool = ...,
pass_exception: bool = ...,
basicCheck: bool = ...,
): ...
def validate_post_id(post_url) -> None: ...
def validate_channel_id(
inputted_channel: str,
) -> T.Tuple[bool, T.Optional[str], T.Optional[T.Any]]: ...
def validate_regex(regex_from_user: str): ...
def validate_config_settings(config) -> None: ...
29 changes: 29 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from unittest.mock import patch

import pytest


def test_validate_channel_id():
ic = "https://www.youtube.com/channel/UCzb9_b2UY29xuY-S8BsmpOg"
from Scripts.validation import validate_channel_id

with pytest.raises(AttributeError):
validate_channel_id(ic)


def test_validate_channel_id_w_mock_youtube():
channel_id = "UCzb9_b2UY29xuY-S8BsmpOg"
ic = f"https://www.youtube.com/channel/{channel_id}"
with patch("Scripts.validation.auth.YOUTUBE", spec=True) as m_youtube:
from Scripts import validation

res = validation.validate_channel_id(ic)
assert res == (
True,
channel_id,
m_youtube.channels.return_value.list.return_value.execute.return_value[
"items"
][0]["snippet"]["title"],
)