예제 #1
0
def test_gen_poll_url_xml_no_xmltodict(monkeypatch):
    gpurl = generic_poll_text.GenPollUrl(json=False, xml=True, parse=lambda x: x, url="testing")
    monkeypatch.setattr(generic_poll_text, "Request", MockRequest)
    monkeypatch.setattr(generic_poll_text, "urlopen", Mockurlopen)
    generic_poll_text.Request.return_value = b"OK"
    with pytest.raises(Exception):
        gpurl.poll()
예제 #2
0
def test_gen_poll_url_json(monkeypatch):
    gpurl = generic_poll_text.GenPollUrl(parse=lambda x: x,
                                         data=[1, 2, 3],
                                         url="testing")
    monkeypatch.setattr(generic_poll_text, "Request", MockRequest)
    monkeypatch.setattr(generic_poll_text, "urlopen", Mockurlopen)
    generic_poll_text.Request.return_value = b'{"test": "OK"}'
    assert gpurl.poll()["test"] == "OK"
예제 #3
0
def test_gen_poll_url_text(monkeypatch):
    gpurl = generic_poll_text.GenPollUrl(json=False,
                                         parse=lambda x: x,
                                         url="testing")
    monkeypatch.setattr(generic_poll_text, "Request", MockRequest)
    monkeypatch.setattr(generic_poll_text, "urlopen", Mockurlopen)
    generic_poll_text.Request.return_value = b"OK"
    assert gpurl.poll() == "OK"
예제 #4
0
def test_gen_poll_url_headers_and_json():
    gpurl = generic_poll_text.GenPollUrl(
        headers={"fake-header": "fake-value"},
        data={"argument": "data value"},
        user_agent="qtile test"
    )

    assert gpurl.headers["User-agent"] == "qtile test"
    assert gpurl.headers["fake-header"] == "fake-value"
    assert gpurl.headers["Content-Type"] == "application/json"
    assert gpurl.data.decode() == '{"argument": "data value"}'
예제 #5
0
def test_gen_poll_url_xml_has_xmltodict(monkeypatch):
    # injected fake xmltodict module but we have to reload the widget module
    # as the ImportError test is only run once when the module is loaded.
    monkeypatch.setitem(sys.modules, "xmltodict", Mockxml("xmltodict"))
    reload(generic_poll_text)
    gpurl = generic_poll_text.GenPollUrl(json=False, xml=True, parse=lambda x: x, url="testing")
    monkeypatch.setattr(generic_poll_text, "Request", MockRequest)
    monkeypatch.setattr(generic_poll_text, "urlopen", Mockurlopen)
    generic_poll_text.Request.return_value = b"OK"
    print(gpurl.poll())
    assert gpurl.poll()["test"] == "OK"
예제 #6
0
def test_gen_poll_url_no_json():
    gpurl = generic_poll_text.GenPollUrl(json=False)
    assert "Content-Type" not in gpurl.headers
예제 #7
0
def test_gen_poll_url_not_configured():
    gpurl = generic_poll_text.GenPollUrl()
    assert gpurl.poll() == "Invalid config"