Esempio n. 1
0
def test_tesaurus_buat_url_dengan_kelas():
    te = Tesaurus()
    te.kata = "mock"
    te.kelas_kata = "adjektiva"
    laman = te._buat_url()
    expect = f"{te.HOST}/mock/adjektiva"
    assert laman == expect
Esempio n. 2
0
def test_simulasi_404_error():
    te = Tesaurus()
    te.kata = "mock"
    sample = SimpleNamespace(status_code=404, text="")
    with pytest.raises(TidakDitemukan) as excinfo:
        te._cek_galat(sample)
    assert "Tidak dapat menemukan kata mock pada semua kelas kata" in str(
        excinfo)
Esempio n. 3
0
def test_simulasi_xxx_error():
    te = Tesaurus()
    te.kata = "mock"
    sample = SimpleNamespace(status_code=500, text="")
    with pytest.raises(TerjadiKesalahan) as excinfo:
        te._cek_galat(sample)
    assert "Terjadi kesalahan ketika berkomunikasi dengan website Tesaurus" in str(
        excinfo)
Esempio n. 4
0
def test_tesaurus_sesi_close():
    te = Tesaurus()
    te.tutup()
    full_closed = True
    for adapter in te.sesi.adapters.values():
        if len(adapter.poolmanager.pools) > 0:
            full_closed = False
    assert full_closed is True
Esempio n. 5
0
def test_tesaurus_buat_url_kelas_tidak_diketahui():
    te = Tesaurus()
    te.kata = "mock"
    te.kelas_kata = "adjective"
    with pytest.raises(KelasKataTidakDiketahui) as excinfo:
        te._buat_url()
    assert "Kelas kata adjective tidak diketahui." in str(excinfo.value)
Esempio n. 6
0
def test_tesaurus_buat_url():
    te = Tesaurus()
    te.kata = "mock"
    laman = te._buat_url()
    expect = f"{te.HOST}/mock"
    assert laman == expect
Esempio n. 7
0
def test_tesaurus_sesi():
    sample = requests.Session()
    mock_header = {"Sample-Header": "Mocked"}
    sample.headers.update(mock_header)
    te = Tesaurus(sample)
    assert te.sesi.headers.get("Sample-Header") == "Mocked"
Esempio n. 8
0
def test_simulasi_str_tanpa_entri():
    te = Tesaurus()
    te.kata = "makan"
    assert "makan\nTidak ada hasil." == str(te)
Esempio n. 9
0
def test_simulasi_terkait_error_silent_2():
    te = Tesaurus()
    te.kata = "makan"
    te._buat_terkait(SAMPLE_HTML_2)
    assert len(te.terkait) == 1
Esempio n. 10
0
def test_simulasi_terkait_error_silent():
    te = Tesaurus()
    te.kata = "makan"
    te._buat_terkait(SAMPLE_HTML_1)
    assert te.terkait == []
Esempio n. 11
0
def test_simulasi_terkait_kosong():
    te = Tesaurus()
    te._buat_terkait("<div>mock</div>")
    assert te.terkait == []
Esempio n. 12
0
def test_tesaurus_terkait():
    te = Tesaurus()
    assert te.terkait == []
Esempio n. 13
0
def test_tesaurus_entri():
    te = Tesaurus()
    assert te.entri == []