Пример #1
0
    def test_load_user_failed(self):
        """
        """
        twitch = Twitch()
        twitch._user_profile = Mock(return_value=None)

        self.assertEqual(None, twitch._load_user("foo11"))
Пример #2
0
    def test_load_json_decode_error(self):
        """
        """
        twitch = Twitch()
        twitch.tcp.get = Mock(side_effect=json.decoder.JSONDecodeError('a', 'b', 10))  # NOQA

        self.assertEqual(None, twitch._load_json("bar"))
Пример #3
0
    def test_load_json_type_error(self):
        """
        """
        twitch = Twitch()
        twitch.tcp.get = Mock(side_effect=TypeError)

        self.assertEqual(None, twitch._load_json("baz"))
Пример #4
0
    def test_user_profile(self):
        """
        """
        record = {
            "name": "bazbar",
            "created_at": "2016-02-26T17:29:16Z",
            "updated_at": "2016-03-26T17:29:16Z",
        }
        twitch = Twitch()
        mock_response = Mock()
        mock_response.json.return_value = record
        twitch.tcp.get = Mock(return_value=mock_response)

        self.assertEqual(record, twitch._user_profile("randomuser"))
Пример #5
0
    def test_chatters(self):
        """
        """
        viewer = self.create_user("viewer")
        moderator = self.create_user("moderator")
        chatters = {
            "chatters": {
                "viewers": [viewer.name, "foobar"],
                "moderators": [moderator.name]
            }
        }
        twitch = Twitch()
        mock_response = Mock()
        mock_response.json.return_value = chatters
        twitch.tcp.get = Mock(return_value=mock_response)

        self.assertEqual(twitch.chatters("foo"), [moderator, viewer])
Пример #6
0
    def test_load_user(self):
        """
        """
        record = {
            "name": "bazbar",
            "created_at": "2016-02-26T17:29:16Z",
            "updated_at": "2016-03-26T17:29:16Z",
        }

        twitch = Twitch()
        twitch._user_profile = Mock(return_value=record)
        twitch._user_follows = Mock(return_value=None)

        user = twitch._load_user(record["name"])

        self.assertEqual(user.name, record["name"])
        self.assertEqual(user.created, parse_date(record["created_at"]))
        self.assertEqual(user.updated, parse_date(record["updated_at"]))
        self.assertEqual(user.follows, 0)
Пример #7
0
def chatters(request):
    """
    /{stream}

    - stream: stream name

    Returns a list of chatters with their registration date
    """
    channel = request.matchdict["stream"].lower()
    users = Twitch().chatters(channel)

    if users is None:
        raise exc.HTTPInternalServerError(
            "Error while loading channel details {}".format(channel))

    return {
        'chatters': users,
    }
Пример #8
0
def stream(request):
    """
    /stream/{stream}

    - stream: stream name

    Returns basic stream info (viewers, chatters, followers, etc)
    """
    name = request.matchdict["stream"].lower()
    info = Twitch().stream(name)

    if info is None:
        raise exc.HTTPInternalServerError(
            "Error while loading stream details {}".format(name))  # NOQA

    if info is False:
        raise exc.HTTPNotFound("Offline stream {}".format(name))

    return {
        'streams': [info],
    }
Пример #9
0
def directory(request):
    """
    /directory/{directory} (optional)

    - directory: sub-section of the directory

    Returns basic stream info (viewers, chatters, followers, etc) for the top 20
    streams in a section
    """
    directory = request.matchdict["directory"].lower()
    info = Twitch().streams(directory)

    if info is None:
        raise exc.HTTPInternalServerError(
            "Error while loading streams details {}".format(directory))  # NOQA

    if info is False:
        raise exc.HTTPNotFound("Unknown directory {}".format(directory))

    return {
        'streams': info,
    }
Пример #10
0
    def test_chatters_bogus(self, _load_json):
        """
        """
        twitch = Twitch()

        self.assertEqual(None, twitch.chatters("boo"))
Пример #11
0
    def test_chatters_failed(self, _load_json):
        """
        """
        twitch = Twitch()

        self.assertEqual(None, twitch.chatters("bar"))
Пример #12
0
    def test_user_follows_bogus(self, _load_json):
        """
        """
        twitch = Twitch()

        self.assertEqual(None, twitch._user_follows("bar43"))
Пример #13
0
    def test_user_follows_failed(self, _load_json):
        """
        """
        twitch = Twitch()

        self.assertEqual(None, twitch._user_follows("bar45"))
Пример #14
0
    def test_user_follows(self, _load_json):
        """
        """
        twitch = Twitch()

        self.assertEqual(420, twitch._user_follows("randomuser34"))
Пример #15
0
    def test_user_profile_bogus(self, _load_json):
        """
        """
        twitch = Twitch()

        self.assertEqual(None, twitch._user_profile("bar23"))