Beispiel #1
0
class TestService:
    @classmethod
    @pytest.fixture(autouse=True)
    def setup_class(self, monkeypatch):
        self.service = GenericService()

    def test_get_request(self, monkeypatch):
        monkeypatch.setattr(urllib2, 'urlopen', lambda x, y: DummyHandler())
        response = self.service._get_request('http://example.com')
        assert response == '123'
        response = self.service._get_request('http://example.com', 'dummy_data')
        assert response == '123'

    def test_json_request(self, monkeypatch):
        monkeypatch.setattr(urllib2, 'urlopen', lambda x: DummyHandler())
        monkeypatch.setattr(json, 'loads', lambda x: {'response': '123'})
        response = self.service._json_request('http://example.com')
        assert response == {'response': '123'}

    def test_quote_url(self):
        quoted_url = self.service._quote_url('http://example.com')
        assert quoted_url == 'http%3A%2F%2Fexample.com'

    def test_parse_xml(self):
        xml_text = "<root><test><play>Dummy message</play></test></root>"
        parsed_text = self.service._parse_xml('play', xml_text)
        assert parsed_text == "Dummy message"

    def test_do_service(self):
        with pytest.raises(NotImplementedError):
            self.service.do_service('bla')
Beispiel #2
0
class TestService:
    @classmethod
    @pytest.fixture(autouse=True)
    def setup_class(self, monkeypatch):
        self.service = GenericService()

    def test_get_request(self, monkeypatch):
        monkeypatch.setattr(urllib2, 'urlopen', lambda x, y: DummyHandler())
        response = self.service._get_request('http://example.com')
        assert response == '123'
        response = self.service._get_request('http://example.com',
                                             'dummy_data')
        assert response == '123'

    def test_json_request(self, monkeypatch):
        monkeypatch.setattr(urllib2, 'urlopen', lambda x: DummyHandler())
        monkeypatch.setattr(json, 'loads', lambda x: {'response': '123'})
        response = self.service._json_request('http://example.com')
        assert response == {'response': '123'}

    def test_quote_url(self):
        quoted_url = self.service._quote_url('http://example.com')
        assert quoted_url == 'http%3A%2F%2Fexample.com'

    def test_parse_xml(self):
        xml_text = "<root><test><play>Dummy message</play></test></root>"
        parsed_text = self.service._parse_xml('play', xml_text)
        assert parsed_text == "Dummy message"

    def test_do_service(self):
        with pytest.raises(NotImplementedError):
            self.service.do_service('bla')
Beispiel #3
0
 def __init__(self, obj):
     GenericService.__init__(self)
     self._obj = obj
Beispiel #4
0
 def __init__(self, obj):
     GenericService.__init__(self)
     self._obj = obj
Beispiel #5
0
 def setup_class(self, monkeypatch):
     self.service = GenericService()
Beispiel #6
0
 def setup_class(self, monkeypatch):
     self.service = GenericService()