示例#1
0
 def setup_class(cls):
     cls.dict = SpanishDict(get_args())
     cls.en_word = 'Spanish'
     cls.en_record = cls.dict.query(cls.en_word)
     cls.es_word = 'tranquilo'
     cls.es_record = cls.dict.query(cls.es_word)
     cls.not_found_word = 'asdfsdf'
示例#2
0
 def setup_method(self, method):
     self.dict = SpanishDict()
     self.word = 'Spanish'
     self.timeout = 5
     with open(CONTENT_TEST_DATA, 'r') as f:
         self.content = f.read()
     with open(RAW_HTML_TEST_DATA, 'r') as f:
         self.raw_html = f.read()
示例#3
0
class TestSpansishDict:
    def setup_method(self, method):
        self.dict = SpanishDict()
        self.word = 'Spanish'
        self.timeout = 5
        with open(CONTENT_TEST_DATA, 'r') as f:
            self.content = f.read()
        with open(RAW_HTML_TEST_DATA, 'r') as f:
            self.raw_html = f.read()

    def teardown_method(self, method):
        del self.dict

    def test_provider(self):
        assert self.dict.provider == 'spanish'

    def test_title(self):
        assert self.dict.title == 'SpanishDict'

    def test__get_url(self):
        url = 'http://www.spanishdict.com/translate/{}'.format(self.word)
        assert url == self.dict._get_url(self.word)

    def test_show(self):
        content = self.content
        r = Record(word=self.word, content=content, source=self.dict.provider)

        # god bless this method, hope that it do not raise any exception
        self.dict.show(r)

    @patch('zdict.dictionaries.spanish.Record')
    def test_query_normal(self, Record):
        self.dict._get_raw = Mock(return_value=self.raw_html)
        self.dict.query(self.word, self.timeout)
        Record.assert_called_with(
            word=self.word,
            content=json.dumps(json.loads(self.content)),
            source='spanish',
        )

    def test_query_not_found(self):
        self.dict._get_raw = Mock(return_value='<div class="card"><div/>')
        with raises(NotFoundError):
            self.dict.query(self.word, self.timeout)
        self.dict._get_raw.assert_called_with(self.word, self.timeout)
示例#4
0
 def setup_class(cls):
     cls.dict = SpanishDict(get_args())
     cls.word = 'Spanish'
     cls.record = cls.dict.query(cls.word)