<commit_before># -*- coding: utf-8 -*-

# Copyright(C) 2014      Bezleputh
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.


from weboob.tools.test import BackendTest


class TwitterTest(BackendTest):
    BACKEND = 'twitter'

    def test_twitter(self):
        l = list(self.backend.iter_threads())
        assert len(l)
        thread = self.backend.get_thread(l[0].id)
        assert len(thread.root.content)<commit_msg>[twitter] improve tests<commit_after># -*- coding: utf-8 -*-

# Copyright(C) 2014      Bezleputh
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.

from nose.plugins.skip import SkipTest
from weboob.tools.test import BackendTest
from weboob.capabilities.base import CapBaseObject


class TwitterTest(BackendTest):
    BACKEND = 'twitter'

    def test_twitter_logged(self):
        if self.backend.browser.username:
            assert(self.backend.browser.get_me())
        else:
            raise SkipTest("User credentials not defined")

    def test_twitter_list(self):
        if self.backend.browser.username:
            l = list(self.backend.iter_threads())
            assert len(l)
            thread = self.backend.get_thread(l[0].id)
            assert len(thread.root.content)
        else:
            raise SkipTest("User credentials not defined")

    def test_ls_me(self):
        if self.backend.browser.username:
            l = list(self.backend.iter_resources([CapBaseObject], ['me']))
            assert len(l)
            thread = self.backend.get_thread(l[0].id)
            assert len(thread.root.content)
        else:
            raise SkipTest("User credentials not defined")

    def test_ls_search(self):
        l = list(self.backend.iter_resources([CapBaseObject], ['search', 'weboob']))
        assert len(l)
        thread = self.backend.get_thread(l[0].id)
        assert len(thread.root.content)

    def test_ls_hashtag(self):
        l = list(self.backend.iter_resources([CapBaseObject], ['hashtags', 'weboob']))
        assert len(l)
        thread = self.backend.get_thread(l[0].id)
        assert len(thread.root.content)

    def test_ls_profils(self):
        l = list(self.backend.iter_resources([CapBaseObject], ['profils', 'jf_cope']))
        assert len(l)
        thread = self.backend.get_thread(l[0].id)
        assert len(thread.root.content)

    def test_ls_trend(self):
        l = list(self.backend.iter_resources([CapBaseObject], ['trendy']))
        assert len(l)
        l1 = list(self.backend.iter_resources([CapBaseObject], ['trendy', u'%s' % l[0].split_path[0]]))
        assert len(l1)
        thread = self.backend.get_thread(l1[0].id)
        assert len(thread.root.content)
{'fraction_non_alphanumeric': 0.10379292670425423, 'fraction_numerical': 0.006150691952844695, 'mean_word_length': 3.0826359832635983, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4975755', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1132, 'n_words': 359}