Exemplo n.º 1
0
def test_exceptions_raises_nosign_and_date():
    with pytest.raises(AstrologerException) as excinfo:
        paolo.get(sign='sign-not-in-list', kind='tomorrow')
    assert "Sign not allowed, did you mean one of ['capricorn', 'aquarius', 'pisces', 'aries', 'taurus', 'gemini', 'cancer', 'leo', 'virgo', 'libra', 'scorpio', 'sagittarius']" in str(
        excinfo.value)
    with pytest.raises(AstrologerException) as excinfo:
        branko.get(sign='sign-not-in-list')
    assert "Sign not allowed, did you mean one of ['capricorn', 'aquarius', 'pisces', 'aries', 'taurus', 'gemini', 'cancer', 'leo', 'virgo', 'libra', 'scorpio', 'sagittarius']" in str(
        excinfo.value)
Exemplo n.º 2
0
def test_exceptions_using_connection_error(mocker):
    mocked_post = mocker.patch('horoscofox.signs.paolosign.requests.post')
    mocked_get = mocker.patch('horoscofox.signs.brankosign.requests.get')
    mocked_get.side_effect = mocked_post.side_effect = ConnectionError()
    with pytest.raises(AstrologerException) as excinfo:
        paolo.get(sign='virgo', kind='today')
    assert 'Connection error!' in str(excinfo.value)
    with pytest.raises(AstrologerException) as excinfo:
        branko.get(sign='virgo', kind='today')
    assert 'Connection error!' in str(excinfo.value)
Exemplo n.º 3
0
def test_exceptions_using_api(mocker):
    mocked_post = mocker.patch('horoscofox.signs.paolosign.requests.post')
    mocked_post.return_value.status_code = 500
    mocked_get = mocker.patch('horoscofox.signs.brankosign.requests.get')
    mocked_get.return_value.status_code = 500
    with pytest.raises(AstrologerException) as excinfo:
        paolo.get(sign='virgo', kind='today')
    assert 'Error using API!' in str(excinfo.value)
    with pytest.raises(AstrologerException) as excinfo:
        branko.get(sign='virgo', kind='today')
    assert 'Error using API!' in str(excinfo.value)
Exemplo n.º 4
0
def test_client_info(mocker):
    mock_response = {
        "result": {
            "elem": {
                "info": {
                    "text":
                    "Il metodo, l'ordine, la precisione, tutto deve essere inquadrato o quantomeno affrontato con attenzione.",
                    "short_text": "Il metodo, l'ordine, la precisione",
                    "content_id": "2705214",
                    "content_date": "2019-10-29 00:00:00",
                    "title": "VERGINE",
                    "subtitle": "29 Ottobre 2019",
                },
                "datetime": "2019-10-29 00:04:56",
                "timestamp": 1522281896,
                "t_active": "true",
                "t_days": 1,
                "t_frequency_days": 7,
                "ads": "admob",
                "rewarded_video_libs": [],
            },
            "id": "6747600",
        }
    }
    mocked_post = mocker.patch("horoscofox.signs.paolosign.requests.post")
    mocked_post.return_value.status_code = 200
    mocked_post.return_value.json.return_value = mock_response

    mocked_date = mocker.patch("horoscofox.signs.paolosign.date")
    target = datetime(2019, 1, 1, 0, 0).date()
    mocked_date.today.return_value = target

    resp = paolo.virgo.info()
    assert (
        resp.text ==
        "Il metodo, l'ordine, la precisione, tutto deve essere inquadrato o quantomeno affrontato con attenzione."
    )
    assert resp.date_start == datetime(2019, 1, 1, 0, 0).date()
    assert resp.date_end == datetime(2019, 12, 31, 0, 0).date()

    resp = paolo.get(sign="virgo", kind="info")
    assert (
        resp.text ==
        "Il metodo, l'ordine, la precisione, tutto deve essere inquadrato o quantomeno affrontato con attenzione."
    )
    assert resp.date_start == datetime(2019, 1, 1, 0, 0).date()
    assert resp.date_end == datetime(2019, 12, 31, 0, 0).date()
Exemplo n.º 5
0
def test_client_today(mocker):
    mock_response = {
        "result": {
            "elem": {
                "daily": {
                    "text": "Va tutto male",
                    "short_text": "Bel periodo si",
                    "content_id": "7985824",
                    "content_date": "2018-03-29 00:00:00",
                    "title": "SCORPIONE",
                    "subtitle": "29 Marzo 2018",
                },
                "datetime": "2018-03-29 00:04:56",
                "timestamp": 1522281896,
                "t_active": "true",
                "t_days": 1,
                "t_frequency_days": 7,
                "ads": "admob",
                "rewarded_video_libs": [],
            },
            "id": "5713030",
        }
    }

    mocked_post = mocker.patch("horoscofox.signs.paolosign.requests.post")
    mocked_post.return_value.status_code = 200
    mocked_post.return_value.json.return_value = mock_response

    resp = paolo.scorpio.today()
    assert resp.text == "Va tutto male"
    assert resp.date_start == datetime(2018, 3, 29, 0, 0).date()
    assert resp.date_end == datetime(2018, 3, 30, 0, 0).date()

    resp = paolo.get(sign="scorpio", kind="today")
    assert resp.text == "Va tutto male"
    assert resp.date_start == datetime(2018, 3, 29, 0, 0).date()
    assert resp.date_end == datetime(2018, 3, 30, 0, 0).date()
Exemplo n.º 6
0
def test_client_json_response(mocker):
    mock_response = {
        "result": {
            "elem": {
                "weekly": {
                    "text":
                    "La brutta persona che eravate un tempo non esiste già più. Ora siete una brutta persona completamente nuova.",
                    "short_text":
                    "La brutta persona che eravate un tempo non esiste già più",
                    "content_id": "12345678",
                    "content_date": "2018-03-26 00:00:00",
                    "title": "VERGINE",
                    "subtitle": "26 Marzo 2018",
                },
                "datetime": "2018-03-26 00:10:30",
                "timestamp": 1522281896,
                "t_active": "true",
                "t_days": 1,
                "t_frequency_days": 7,
                "ads": "admob",
                "rewarded_video_libs": [],
            },
            "id": "12345678",
        }
    }
    mocked_post = mocker.patch("horoscofox.signs.paolosign.requests.post")
    mocked_post.return_value.status_code = 200
    mocked_post.return_value.json.return_value = mock_response

    resp = paolo.get(sign="virgo", kind="week").json()
    assert (
        resp["text"] ==
        "La brutta persona che eravate un tempo non esiste già più. Ora siete una brutta persona completamente nuova."
    )
    assert resp["date_start"] == "2018-03-26"
    assert resp["date_end"] == "2018-04-02"
Exemplo n.º 7
0
import horoscofox
from horoscofox import paolo

print('♏️  Scorpio Today')
scorpio_today = paolo.scorpio.today()
print(scorpio_today.date_start)
print(scorpio_today.date_end)
print(scorpio_today.text)

print('♏️  Scorpio Tomorrow')
scorpio_tomorrow = paolo.scorpio.tomorrow()
print(scorpio_tomorrow.date_start)
print(scorpio_tomorrow.date_end)
print(scorpio_tomorrow.text)

print('♍️  Virgo Today')
virgo_today = paolo.get(sign=horoscofox.VIRGO, kind=horoscofox.TODAY)
print(virgo_today.text)

print('♍️  Virgo Info')
virgo_info = paolo.get(sign=horoscofox.VIRGO, kind=horoscofox.INFO)
print(virgo_info.text)
Exemplo n.º 8
0
def test_exceptions_raises_virgo_and_nodate():
    with pytest.raises(AstrologerException) as excinfo:
        paolo.get(sign='virgo', kind='day-after-tomorrow')
    assert "Kind not allowed, did you mean one of ['today', 'tomorrow', 'week', 'month', 'info']" in str(
        excinfo.value)