Exemplo n.º 1
0
def test_no_internet():
    twc = twitter_word_count(None)
    twc.get_last_week_tweets = MagicMock(
        side_effect=requests.exceptions.ConnectionError
    )  # Simulamos que no hay conexión a internet
    with pytest.raises(ValueError):
        twc.get_most_used_words_and_tweets()
Exemplo n.º 2
0
def test_stop_words_tweet():
    tweets = [
        'ella el', 'nosotros y ellos', 'un una', 'unos', 'yo', 'tu tu', 'que',
        'estas'
    ]
    twc = twitter_word_count(None)
    twc.get_last_week_tweets = MagicMock(return_value=tweets)
    assert twc.get_most_used_words_and_tweets() == []
Exemplo n.º 3
0
def test_less_than_10_tweets():
    tweets = [
        'Hola buenas dias, me llamo Pepe', 'buenas noches', 'me llamo pepe'
    ]
    twc = twitter_word_count(None)
    twc.get_last_week_tweets = MagicMock(return_value=tweets)
    assert twc.get_most_used_words_and_tweets() == [
        ['buenas', 22.2, ['Hola buenas dias, me llamo Pepe', 'buenas noches']],
        ['llamo', 22.2, ['Hola buenas dias, me llamo Pepe', 'me llamo pepe']],
        ['pepe', 22.2, ['Hola buenas dias, me llamo Pepe', 'me llamo pepe']],
        ['hola', 11.1, ['Hola buenas dias, me llamo Pepe']],
        ['dias', 11.1, ['Hola buenas dias, me llamo Pepe']],
        ['noches', 11.1, ['buenas noches']]
    ]
Exemplo n.º 4
0
def test_more_than_10_tweets():
    tweets = [
        'Hola buenas dias, me llamo Pepe', 'buenas noches', 'me llamo pepe',
        'pedro juan alberto sabado miercoles jueves'
    ]
    twc = twitter_word_count(None)
    twc.get_last_week_tweets = MagicMock(return_value=tweets)
    assert twc.get_most_used_words_and_tweets() == [
        ['buenas', 13.3, ['Hola buenas dias, me llamo Pepe', 'buenas noches']],
        ['llamo', 13.3, ['Hola buenas dias, me llamo Pepe', 'me llamo pepe']],
        ['pepe', 13.3, ['Hola buenas dias, me llamo Pepe', 'me llamo pepe']],
        ['hola', 6.7, ['Hola buenas dias, me llamo Pepe']],
        ['dias', 6.7, ['Hola buenas dias, me llamo Pepe']],
        ['noches', 6.7, ['buenas noches']],
        ['pedro', 6.7, ['pedro juan alberto sabado miercoles jueves']],
        ['juan', 6.7, ['pedro juan alberto sabado miercoles jueves']],
        ['alberto', 6.7, ['pedro juan alberto sabado miercoles jueves']],
        ['sabado', 6.7, ['pedro juan alberto sabado miercoles jueves']]
    ]
Exemplo n.º 5
0
def search_frequency_words(request):
    if request.method == 'POST':
        form = search_form(request.POST)
        if form.is_valid():
            screen_name = form.cleaned_data['screen_name']
            language = form.cleaned_data['language']

            try:
                frequency_words = twitter_word_count(
                    settings.API_TWITTER).get_most_used_words_and_tweets(
                        screen_name, language)
            except TypeError:
                return HttpResponse('No hay tweets disponibles')

            return render(request, 'tweets_list.html',
                          {'frequency_words': frequency_words})
        response = HttpResponse('El formulario no es valido')
        response.status_code = 400
        return response
    response = HttpResponse('Petición no válida')
    response.status_code = 400
    return response
Exemplo n.º 6
0
def test_puntuation_marks():
    tweets = [',,,,', '....', '???', '!!!!', '¡¡¡¡¡', ';;;;', '::::::']
    twc = twitter_word_count(None)
    twc.get_last_week_tweets = MagicMock(return_value=tweets)
    assert twc.get_most_used_words_and_tweets() == []
Exemplo n.º 7
0
def test_boolean():
    twc = twitter_word_count(None)
    twc.get_last_week_tweets = MagicMock(return_value=True)
    with pytest.raises(TypeError):
        twc.get_most_used_words_and_tweets()