def test_remove_stop_words() -> None:
    with CustomTestClient():
        load_stopwords_into_db()
        expected = ["polisen"]
        c: Counter = _remove_stop_words(
            Counter(["det", "här", "är", "polisen"]))
        assert list(c.keys()) == expected
def test_calculator_service(monkeypatch) -> None:
    with CustomTestClient():
        load_stopwords_into_db()
        monkeypatch.setattr(requests, "get", mock_get_200_short)
        stats = calculate_monthstats("201912")
        assert stats.article_count == 3
        assert stats.word_mean == 17
        assert stats.word_median == 19
def test_initiating_calculator_service_not_found(monkeypatch) -> None:
    with CustomTestClient() as c:
        load_stopwords_into_db()
        monkeypatch.setattr(requests, "get", mock_get_404)
        res = c.get('/v1/statistics/monthstats/201912')
        assert res.status_code == 404
        data = res.get_json()
        assert data[
            "description"] == "No articles exist for the provided yearmonth"
def test_initiating_calculator_service_bad_request_getting_article_data(
        monkeypatch) -> None:
    with CustomTestClient() as c:
        load_stopwords_into_db()
        monkeypatch.setattr(requests, "get", mock_get_400)
        res = c.get('/v1/statistics/monthstats/201912')
        assert res.status_code == 400
        data = res.get_json()
        assert data["description"] == "Bad request message"
def test_initiating_calculator_service(monkeypatch) -> None:
    with CustomTestClient() as c:
        load_stopwords_into_db()
        monkeypatch.setattr(requests, "get", mock_get_200_short)
        monkeypatch.setattr(requests, "post", mock_post_200)
        monkeypatch.setattr(requests, "put", mock_put_200)
        res = c.get('/v1/statistics/monthstats/201912')
        assert res.status_code == 200
        data = res.get_json()
        assert data["message"] == "Monthstat record successfully added"
Example #6
0
def test_adding_initial_stopwords() -> None:
    with CustomTestClient():
        load_stopwords_into_db()
        stopwords = stopword_repo.find_all()
        assert len(stopwords) == 518