def test_cookie_paths_are_observed(): response = TestAgent(TestApp()).get('/setcookie?name=doobedo&value=dowop&path=/') response = response.get('/setcookie?name=dowahdowah&value=beebeebo&path=/private') response = response.get('/cookies') assert_equal(response.body, 'doobedo:<dowop>') response = response.get('/private/cookies') assert_equal(response.body, 'doobedo:<dowop>; dowahdowah:<beebeebo>')
def test_get_allows_relative_uri(): agent = TestAgent(wz.Response(['<html><p>salt</p><p>pepper</p><p>pickle</p>'])) try: agent.get('../') except AssertionError: # Expect an AssertionError, as we haven't made an initial request to be # relative to pass else: raise AssertionError("Didn't expect relative GET request to work") agent = agent.get('/rhubarb/custard/') agent = agent.get('../') assert_equal(agent.request.url, 'http://localhost/rhubarb/')
def test_lxml_attr_is_consistent(): body_text = html.div( html.p(u"foo")).encode('utf-8') agent = TestAgent(wz.Response([body_text])) page = agent.get(u'/') div_element = page.one('//div') assert page.lxml == div_element.lxml
def test_html_returns_unicode(): body_text = html.div( html.p(u"£")).encode('utf-8') agent = TestAgent(wz.Response([body_text])) page = agent.get(u'/') assert page.html() == body_text.decode('utf-8') assert page.html('utf-8') == body_text
def test_click_ignores_fragment(): class UrlFragmentApp(MockApp): page1 = (u"GET", lambda r: wz.Response(['<a href="/page2#fragment">link to page 1</a>'])) page2 = (u"GET", lambda r: wz.Response(['This is page2'])) agent = TestAgent(UrlFragmentApp) assert_equal( agent.get('/page1').one("//a").click().request.path, '/page2')
def test_form_getitem_doesnt_match(): form_text = html.body( html.form( html.input(name="foo", value="a")), html.input(name="foo", value="b")) agent = TestAgent(wz.Response([form_text])) form_page = agent.get(u'/') form = form_page.one(u"//form") assert form[u"foo"] == u"a"
def test_has_class(): body = '''<p class="foo bar">Mr Flibble says Hello!</p>''' agent = TestAgent(wz.Response(body)) page = agent.get('/') p = page.one("//p") assert p.has_class("foo") assert p.has_class("bar") assert not p.has_class("f") assert not p.has_class("fo") assert not p.has_class("Flibble")
def test_unicode_chars(): body_text = html.div( html.p(u"£")).encode('utf-8') agent = TestAgent(wz.Response([body_text])) page = agent.get(u'/') assert page.body == body_text assert tostring(page.lxml) == body_text assert page.html().encode('utf-8') == body_text div_element = page.one('//div') assert div_element.html().encode('utf-8') == body_text assert tostring(div_element.lxml) == body_text
def test_reset(): agent = TestAgent(TestApp()) assert_raises( testino.NoRequestMadeError, agent.reset ) page = agent.get(u'/form-text') assert page.one(u"//input[@name='a'][1]").value == u'a' page.one(u"//input[@name='a'][1]").value = u'foobar' assert page.one(u"//input[@name='a'][1]").value == u'foobar' page.reset() assert page.one(u"//input[@name='a'][1]").value == u'a' input_b = page.one(u"//input[@name='b']") assert input_b.value == u'' input_b.value = u'flibble' assert input_b.value == u'flibble' page.reset() assert input_b.value == u''
def test_cookies_are_resent(): response = TestAgent(TestApp()).get('/setcookie?name=foo&value=bar&path=/') response = response.get('/cookies') assert_equal(response.body, 'foo:<bar>')