This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#84] Remove the stored test data for SpanishDict
- Loading branch information
shunyi
authored and
shunyi
committed
Apr 17, 2016
1 parent
48e9b78
commit 4b2b9d0
Showing
5 changed files
with
50 additions
and
157 deletions.
There are no files selected for viewing
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from pytest import raises | ||
from unittest.mock import Mock, patch | ||
|
||
from zdict.dictionaries.spanish import SpanishDict | ||
from zdict.exceptions import NotFoundError | ||
|
||
|
||
class TestSpansishDict: | ||
@classmethod | ||
def setup_class(cls): | ||
cls.d = SpanishDict() | ||
cls.word = 'Spanish' | ||
cls.timeout = 5 | ||
cls.record = cls.d.query(cls.word, cls.timeout) | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
del cls.d | ||
del cls.word | ||
del cls.timeout | ||
del cls.record | ||
|
||
def test_provider(self): | ||
assert self.d.provider == 'spanish' | ||
|
||
def test_title(self): | ||
assert self.d.title == 'SpanishDict' | ||
|
||
def test__get_url(self): | ||
url = 'http://www.spanishdict.com/translate/{}'.format(self.word) | ||
assert url == self.d._get_url(self.word) | ||
|
||
def test_show(self): | ||
# god bless this method, hope that it do not raise any exception | ||
self.d.show(self.record) | ||
|
||
@patch('zdict.dictionaries.spanish.Record') | ||
def test_query_normal(self, Record): | ||
self.d.query(self.word, self.timeout) | ||
Record.assert_called_with( | ||
word=self.word, | ||
content=self.record.content, | ||
source='spanish', | ||
) | ||
|
||
def test_query_not_found(self): | ||
self.d._get_raw = Mock(return_value='<div class="card"><div/>') | ||
with raises(NotFoundError): | ||
self.d.query(self.word, self.timeout) | ||
self.d._get_raw.assert_called_with(self.word, self.timeout) |