Ejemplo n.º 1
0
class TestUrbanDict:
    def setup_method(self, method):
        self.dict = UrbanDict(get_args())

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

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

    def test__get_url(self):
        uri = 'http://api.urbandictionary.com/v0/define?term=mock'
        assert self.dict._get_url('mock') == uri

    def test_query_notfound(self):
        notfound_payload = '''
            {"tags":[],"result_type":"no_results","list":[],"sounds":[]}
        '''
        self.dict._get_raw = Mock(return_value=notfound_payload)

        with raises(NotFoundError):
            self.dict.query('mock')

        self.dict._get_raw.assert_called_with('mock')

    @patch('zdict.dictionaries.urban.Record')
    def test_query_normal(self, Record):
        self.dict._get_raw = Mock(return_value='{"mock": true}')
        self.dict.query('mock')
        Record.assert_called_with(
            word='mock',
            content='{"mock": true}',
            source='urban'
        )

    def test_show(self):
        content = '''
        {
            "list": [
                {
                    "word": "mock",
                    "definition": "Mock",
                    "example": "..."
                }
            ]
        }
        '''
        r = Record(word='mock', content=content, source='urban')

        # god bless this method, hope that it do not raise any exception
        self.dict.show(r)
Ejemplo n.º 2
0
class TestUrbanDict:
    def setup_method(self, method):
        self.dict = UrbanDict(get_args())

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

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

    def test__get_url(self):
        uri = 'http://api.urbandictionary.com/v0/define?term=mock'
        assert self.dict._get_url('mock') == uri

    def test_query_notfound(self):
        notfound_payload = '''
            {"tags":[],"result_type":"no_results","list":[],"sounds":[]}
        '''
        self.dict._get_raw = Mock(return_value=notfound_payload)

        with raises(NotFoundError):
            self.dict.query('mock')

        self.dict._get_raw.assert_called_with('mock')

    @patch('zdict.dictionaries.urban.Record')
    def test_query_normal(self, Record):
        self.dict._get_raw = Mock(return_value='{"mock": true}')
        self.dict.query('mock')
        Record.assert_called_with(word='mock',
                                  content='{"mock": true}',
                                  source='urban')

    def test_show(self):
        content = '''
        {
            "list": [
                {
                    "word": "mock",
                    "definition": "Mock",
                    "example": "..."
                }
            ]
        }
        '''
        r = Record(word='mock', content=content, source='urban')

        # god bless this method, hope that it do not raise any exception
        self.dict.show(r)
Ejemplo n.º 3
0
 def setup_method(self, method):
     self.dict = UrbanDict()
Ejemplo n.º 4
0
 def setup_method(self, method):
     self.dict = UrbanDict(get_args())
Ejemplo n.º 5
0
 def setup_method(self, method):
     self.dict = UrbanDict(get_args())
Ejemplo n.º 6
0
 def setup_class(cls):
     cls.dict = UrbanDict(get_args())
     cls.not_found_word = 'some_not_existing_word'
     cls.word = 'urban'
     cls.record = cls.dict.query(cls.word)