def test_pages_with_plus_sign_in_the_url():
    html = html_markup('source/rumah+sakit.html')

    parser = parsers.Parser(html)
    tools.eq_(len(parser.pages), 5)
    print(max(parser.pages))
    page_url = 'http://qaamus.com/indonesia-arab/rumah+sakit/4'
    tools.eq_(page_url, parser.pages[3])
Beispiel #2
0
from nose import tools
from qaamus2 import parsers
from tests.config import html_markup

HTML_FIXTURE = html_markup('source/suharto.html')


def test_hasil_utama():
    parser = parsers.Parser(HTML_FIXTURE)
    hasil = "سوهارتو"
    tools.eq_(hasil, parser.utama())


@tools.raises(StopIteration)
def test_tidak_punya_berhubungan():
    parser = parsers.Parser(HTML_FIXTURE)
    next(parser.berhubungan())


def test_has_pagination_false():
    parser = parsers.Parser(HTML_FIXTURE)
    tools.eq_(parser.has_pagination, False)


def test_pages():
    parser = parsers.Parser(HTML_FIXTURE)
    tools.eq_(parser.pages, None)


def test_current_page():
    """meski dia tidak punya pagination class
from unittest.mock import patch, PropertyMock
from nose import tools

from qaamus2.scraper import MunawwirScraper
from qaamus2.models.munawwir_berhub_collections import MunawwirBerhubModelCollections
from qaamus2.models.munawwir_berhub import MunawwirBerhubModel
from tests.config import html_markup


RESPONSE2 = html_markup('source/lari2.html')
RESPONSE = html_markup('source/lari.html')


@patch('qaamus2.scraper.requests.get')
def test_next_page(resp_mock):
    # response_pertama
    resp_mock.return_value.text = RESPONSE

    page_one = MunawwirScraper('lari')

    tools.eq_(RESPONSE, page_one.response)

    resp_mock.return_value.text = RESPONSE2

    page_two = page_one.next_page()

    tools.eq_(RESPONSE2, page_two.response)


@tools.raises(IndexError)
@patch('qaamus2.scraper.requests.get')
Beispiel #4
0
"""Test ini berisi test bilamana hasil utama yang ditampilkan
qaamus.com adalah dari bing translator"""
from unittest.mock import patch
from nose import tools

from qaamus2.scraper import MunawwirScraper
from tests.config import html_markup

RESPONSE = html_markup('source/nikah.html')


@patch('qaamus2.scraper.requests.get')
def test_response(req_mock):
    req_mock.return_value.text = RESPONSE

    nikah = MunawwirScraper('nikah')

    tools.eq_(nikah.response, RESPONSE)


@patch('qaamus2.scraper.requests.get')
def test_utama(req_mock):
    req_mock.return_value.text = RESPONSE

    nikah = MunawwirScraper('nikah')

    hasil = nikah.hasil()

    tools.eq_('nikah', hasil.indo)

    tools.eq_('*Diterjemahkan dengan Bing Translator', hasil.sumber)
Beispiel #5
0
from unittest.mock import patch
from qaamus2.scraper import AngkaScraper
from qaamus2.models.angka import AngkaModel
from nose import tools
from tests.config import html_markup

RESPONSE_TEXT = html_markup('source/2017.html') 

@patch('qaamus2.scraper.requests.get')
def test_scrape_angka_response(mock_obj):
    mock_obj.return_value.text = RESPONSE_TEXT

    angka = AngkaScraper(2017)

    tools.eq_(angka.response, RESPONSE_TEXT)


@patch('qaamus2.scraper.requests.get')
def test_scrape_angka_hasil(mock_obj):

    mock_obj.return_value.text = RESPONSE_TEXT

    angka = AngkaScraper(2017)

    expected = AngkaModel(2017, 'الألفان و السابع عشر', 'http://qaamus.com/terjemah-angka/2017/angka').__dict__

    tools.eq_(expected, angka.hasil().__dict__)
    tools.ok_(isinstance(angka.hasil(), AngkaModel))

@patch('qaamus2.scraper.requests.get')
def test_scrape_angka_check_pilihan(mock_obj):
from nose import tools, with_setup
from qaamus2 import parsers
from tests.config import html_markup

HTML_FIXTURE = html_markup('source/lari.html')


def test_init():
    assert 'nama' in HTML_FIXTURE


def test_utama_without_param():
    parser = parsers.Parser(HTML_FIXTURE)
    hasil = (
        'عَدْوٌ ، جَرْيٌ ، عَدَا - يَعْدُوْ ، جَرَى - يَجْرِي',
        "adwun, jaryun, 'adaa - ya'duu, jaroo - yajrii",
        'Data diambil dari Kamus Al-Munawwir Edisi Indonesia Arab pada halaman 499'
    )
    tools.eq_(parser.utama(), hasil)


def test_utama_strip_tags_true():
    parser = parsers.Parser(HTML_FIXTURE)
    hasil = (
        'عَدْوٌ ، جَرْيٌ ، عَدَا - يَعْدُوْ ، جَرَى - يَجْرِي',
        "adwun, jaryun, 'adaa - ya'duu, jaroo - yajrii",
        'Data diambil dari Kamus Al-Munawwir Edisi Indonesia Arab pada halaman 499'
    )
    tools.eq_(parser.utama(strip_tags=True), hasil)

Beispiel #7
0
from nose import tools
from qaamus2 import parsers
from tests.config import html_markup

FIXTURE = html_markup('source/nikah.html')


def test_dapatkan_hasil_utama():
    parsed = parsers.Parser(FIXTURE)
    utama_expected = ('رخصة الزواج', '*Diterjemahkan dengan Bing Translator')

    tools.eq_(utama_expected, parsed.utama())

def test_dapatkan_hasil_utama_strip_tags_false():
    parsed = parsers.Parser(FIXTURE)
    utama_expected = ('رخصة الزواج', '*Diterjemahkan dengan Bing Translator ')

    tools.eq_(utama_expected, parsed.utama(strip_tags=False))

def test_dapatkan_berhubungan():
    parsed = parsers.Parser(FIXTURE)

    berhubungan = parsed.berhubungan()

    next(berhubungan)

    akad = next(berhubungan)

    tools.eq_('akad nikah', akad[1])

def test_has_pagination():
Beispiel #8
0
from nose import tools
from qaamus2 import parsers
from tests.config import html_markup

HTML_FIXTURE = html_markup('source/panahan.html')


def test_utama_without_param():
    parser = parsers.Parser(HTML_FIXTURE)
    hasil = (
        "رِمَايَةٌ بِالأَسْهُمِ و القِسِيّ",
        "rimaayatun bil ashumi wal qisiyyu",
        "Data diambil dari Kamus Al-Munawwir Edisi Indonesia Arab pada halaman 632"
    )
    tools.eq_(parser.utama(), hasil)


def test_utama_dengan_param():
    parser = parsers.Parser(HTML_FIXTURE)
    hasil = (
        "رِمَايَةٌ بِالأَسْهُمِ و القِسِيّ",
        "rimaayatun bil ashumi wal qisiyyu",
        "Data diambil dari Kamus Al-Munawwir Edisi Indonesia Arab pada halaman 632"
    )
    tools.eq_(parser.utama(strip_tags=True), hasil)


def test_utama_dengan_param_false():
    parser = parsers.Parser(HTML_FIXTURE)
    hasil = (
        "رِمَايَةٌ بِالأَسْهُمِ و القِسِيّ",
Beispiel #9
0
from qaamus2 import Qaamus
from qaamus2.models.munawwir import MunawwirModel
from qaamus2.models.pegon import PegonModel
from qaamus2.models.angka import AngkaModel

from nose import tools
from unittest.mock import patch
from tests.config import html_markup

ANGKA = html_markup('source/2017.html')
PEGON = html_markup('source/suharto.html')
MUNAWWIR = html_markup('source/lari.html')


def test_qaamus_scraper():
    tools.eq_(len(Qaamus.scrapers), 3)


@patch('qaamus2.scraper.requests.get')
def test_pegon_scraper(req_mock):
    req_mock.return_value.text = PEGON
    pegon = Qaamus(layanan='pegon').terjemah(indo='suharto')
    tools.ok_(isinstance(pegon.hasil(), PegonModel))


@patch('qaamus2.scraper.requests.get')
def test_angka_scraper(req_mock):
    req_mock.return_value.text = ANGKA
    angka = Qaamus(layanan='angka').terjemah(indo=2017)
    tools.ok_(isinstance(angka.hasil(), AngkaModel))
Beispiel #10
0
import os
from unittest.mock import patch
from qaamus2.scraper import PegonScraper
from qaamus2.models.pegon import PegonModel
from nose import tools
from tests.config import html_markup

PEGON_HTML = html_markup('source/suharto.html')


@patch('qaamus2.scraper.requests.get')
def test_response(mock_obj):
    mock_obj.return_value.text = PEGON_HTML

    pegon = PegonScraper('suharto')

    tools.eq_(pegon.response, PEGON_HTML)


@patch('qaamus2.scraper.requests.get')
def test_hasil(mock_obj):
    mock_obj.return_value.text = PEGON_HTML

    pegon = PegonScraper('suharto')

    hasil = PegonModel('suharto', 'سوهارتو',
                       'http://qaamus.com/terjemah-nama/suharto').__dict__

    tools.eq_(hasil, pegon.hasil().__dict__)

Beispiel #11
0
from nose import tools
from qaamus2 import parsers
from tests.config import html_markup

HTML_FIXTURE = html_markup('source/2017.html')


def test_hasil_utama():
    parser = parsers.Parser(HTML_FIXTURE)
    hasil = "الألفان و السابع عشر"
    tools.eq_(hasil, parser.utama())


@tools.raises(StopIteration)
def test_tidak_punya_berhubungan():
    parser = parsers.Parser(HTML_FIXTURE)
    next(parser.berhubungan())


def test_has_pagination_false():
    parser = parsers.Parser(HTML_FIXTURE)
    tools.eq_(parser.has_pagination, False)


def test_pages():
    parser = parsers.Parser(HTML_FIXTURE)
    tools.eq_(parser.pages, None)


def test_current_page():
    """meski dia tidak punya pagination class