Ejemplo n.º 1
0
    def test_copy_highlevel(self):
        s = webracer.Agent(**base_config)
        s.get('/set_cookie_value', query=dict(v='start'))
        s.assert_status(200)
        s.assert_response_cookie('sink', value='start')

        a = s.copy()
        b = s.copy()

        a.get('/read_cookie_value/sink')
        a.assert_status(200)
        self.assertEqual('start', a.response.body)

        a.get('/set_cookie_value', query=dict(v='avalue'))
        a.assert_status(200)
        a.assert_response_cookie('sink', value='avalue')

        a.get('/read_cookie_value/sink')
        a.assert_status(200)
        self.assertEqual('avalue', a.response.body)

        # b has original start value

        b.get('/read_cookie_value/sink')
        b.assert_status(200)
        self.assertEqual('start', b.response.body)
Ejemplo n.º 2
0
 def test_custom_user_agent(self):
     # XXX improve this api
     config = utils.add_dicts(base_config, dict(user_agent='Quux-o-matic/1.0'))
     s = webracer.Agent(**config)
     s.get('/get_user_agent')
     self.assertEqual(200, s.response.code)
     self.assertEqual('Quux-o-matic/1.0', s.response.body)
Ejemplo n.º 3
0
 def test_specifying_cookie_jar(self):
     cookie_jar = ocookie.CookieJar()
     s = webracer.Agent(cookie_jar=cookie_jar, **base_config)
     s.get('/set_cookie')
     s.assert_status(200)
     s.assert_response_cookie('visited', value='yes')
     assert 'visited' in cookie_jar
     self.assertEqual('yes', cookie_jar['visited'].value)
Ejemplo n.º 4
0
 def test_double_user_agent_override(self):
     # XXX improve this api
     config = utils.add_dicts(base_config, dict(user_agent='Quux-o-matic/1.0'))
     s = webracer.Agent(**config)
     headers = {'user-agent': 'Barlicious/2.0'}
     s.get('/get_user_agent', headers=headers)
     self.assertEqual(200, s.response.code)
     self.assertEqual('Barlicious/2.0', s.response.body)
Ejemplo n.º 5
0
    def test_request_with_relative_redirect(self):
        s = webracer.Agent(host='localhost', port=8061, follow_redirects=False)
        s.get('/relative-redirect')
        s.assert_status('redirect')
        # check that the location header has a relative redirect,
        # as bottle helpfully fixes it for us
        self.assertEqual('found', s.response.headers['location'])

        response = self.get('/relative-redirect')
        self.assert_status(200)
        assert response.body == 'found'
Ejemplo n.º 6
0
 def test_with_retry_default(self):
     retry_app.status_codes = [200, 500, 404, 200]
     config = utils.add_dicts(base_config,
                              dict(retry_failed=True, retry_count=5))
     with webracer.Agent(**config) as s:
         s.get('/')
         s.assert_status(200)
         s.get('/')
         s.assert_status(404)
         s.get('/')
         s.assert_status(200)
         s.get('/')
         s.assert_status(999)
Ejemplo n.º 7
0
    def test_request(self):
        '''Tests that the client works when use_cookie_jar is False.
        '''

        config = utils.add_dicts(base_config, dict(use_cookie_jar=False))
        s = webracer.Agent(**config)
        s.get('/ok')
        self.assertEqual(200, s.response.code)
        self.assertEqual('ok', s.response.body)

        # response cookie access
        self.assertEqual([], utils.listit(s.response.raw_cookies))
        self.assertEqual({}, s.response.cookies)

        # response assertions
        s.assert_not_response_cookie('visited')
        s.assert_not_cookie_jar_cookie('visited')
Ejemplo n.º 8
0
 def test_with_retry_sequence(self):
     retry_app.status_codes = [200, 500, 404, 200]
     config = utils.add_dicts(
         base_config,
         dict(
             retry_failed=True,
             retry_count=5,
             retry_condition=range_iter(400, 599),
         ))
     with webracer.Agent(**config) as s:
         s.get('/')
         s.assert_status(200)
         # 404 is now retried
         s.get('/')
         s.assert_status(200)
         s.get('/')
         s.assert_status(999)
Ejemplo n.º 9
0
    def test_with_retry_custom(self):
        retry_app.status_codes = [200, 500, 404, 200]

        def retry_fn(response):
            return response.code == 200

        config = utils.add_dicts(
            base_config,
            dict(
                retry_failed=True,
                retry_count=5,
                retry_condition=retry_fn,
            ))
        with webracer.Agent(**config) as s:
            s.get('/')
            s.assert_status(500)
            s.get('/')
            s.assert_status(404)
            s.get('/')
            s.assert_status(999)
Ejemplo n.º 10
0
    def test_no_cookie_jar(self):
        '''Tests that the client works when use_cookie_jar is True,
        when cookies are set in response.
        '''

        config = utils.add_dicts(base_config, dict(use_cookie_jar=False))
        s = webracer.Agent(**config)
        s.get('/set_cookie')
        self.assertEqual(200, s.response.code)
        self.assertEqual('ok', s.response.body)

        # response cookie access
        self.assertEqual(1, len(s.response.raw_cookies))
        self.assertEqual(1, len(s.response.cookies))
        assert 'visited' in s.response.cookies

        cookie = s.response.cookies['visited']
        self.assertEqual('yes', cookie.value)

        # response assertions
        s.assert_response_cookie('visited')
        s.assert_not_cookie_jar_cookie('visited')
Ejemplo n.º 11
0
 def test_get(self):
     s = webracer.Agent(**base_config)
     s.get('/ok')
     self.assertEqual(200, s.response.code)
     self.assertEqual('ok', s.response.body)
Ejemplo n.º 12
0
 def test_current_url_after_following_redirect(self):
     s = webracer.Agent(webracer.Config(follow_redirects=True, **base_config))
     s.get('/redirect')
     self.assertEqual('http://localhost:8052/found', s.current_url)
Ejemplo n.º 13
0
 def test_current_url_after_single_request(self):
     s = webracer.Agent(**base_config)
     s.get('/redirect')
     self.assertEqual('http://localhost:8052/redirect', s.current_url)
Ejemplo n.º 14
0
 def test_current_url_before_request(self):
     s = webracer.Agent(**base_config)
     assert s.current_url is None