File: functional_tests.py

package info (click to toggle)
clientcookie 0.4.19-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 480 kB
  • ctags: 571
  • sloc: python: 4,213; makefile: 46
file content (60 lines) | stat: -rwxr-xr-x 1,854 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python

# These tests access the network.

import unittest, string
from unittest import TestCase

import ClientCookie
from ClientCookie import build_opener, install_opener, urlopen
from ClientCookie import CookieJar, HTTPCookieProcessor, \
     HTTPHandler, HTTPRefreshProcessor, \
     HTTPEquivProcessor, \
     HTTPRedirectDebugProcessor, HTTPResponseDebugProcessor

try: True
except NameError:
    True = 1
    False = 0

class FunctionalTests(TestCase):
    def test_clientcookie(self):
        # XXX set up test page on SF or python.org
        # this test page depends on cookies, and an http-equiv refresh
        cj = CookieJar()
        handlers = [
            HTTPCookieProcessor(cj),
            HTTPRefreshProcessor(max_time=None, honor_time=False),
            HTTPEquivProcessor(),

#            HTTPHandler(True),
#            HTTPRedirectDebugProcessor(),
#            HTTPResponseDebugProcessor(),
            ]

        o = apply(build_opener, handlers)
        install_opener(o)
        r = urlopen("http://boards.ign.com/help/cookie_test.asp")
        data = r.read()
        self.assert_(string.find(data, "Your browser supports cookies!") >= 0)
        self.assert_(len(cj) == 1)

        # test response.seek() (added by HTTPEquivProcessor)
        r.seek(0)
        samedata = r.read()
        self.assert_(samedata == data)

##     def test_cacheftp(self):
##         from urllib2 import CacheFTPHandler, build_opener
##         o = build_opener(CacheFTPHandler())
##         r = o.open("ftp://ftp.python.org/pub/www.python.org/robots.txt")
##         data1 = r.read()
##         r.close()
##         r = o.open("ftp://ftp.python.org/pub/www.python.org/2.3.2/announce.txt")
##         data2 = r.read()
##         r.close()
##         self.assert_(data1 != data2)


if __name__ == "__main__":
    unittest.main()