Jc@sdZddkZddkZddkZddkZddkZddkZddkZddkZddk l Z l Z yddk l Z Wn#ej oddk l Z nXddkZddklZlZddklZdgZdZd efd YZyeWnej od ZnXd efd YZdefdYZdefdYZdefdYZdefdYZ defdYZ!ei"dei#Z$dZ%defdYZ&defdYZ'de&fdYZ(e(e&i)dsF Routines for testing WSGI applications. Most interesting is TestApp iN(t BaseCookiet CookieError(tStringIO(tResponsetRequest(tlinttTestAppcGs ti|S(s An os.tempnam with the warning turned off, because sometimes you just need to use this and don't care about the stupid security warning. (tosttempnam(targs((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyttempnam_no_warningst NoDefaultcBseZRS((t__name__t __module__(((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyR $scCst|}|i|S(N(tlisttsort(tl((s4/usr/lib/python2.6/site-packages/webtest/__init__.pytsorted*s  tAppErrorcBseZRS((R R (((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyR/scBseZeZdddZdZddZdZdddde dZ ddddde ddZ ddddde ddZ ddddde ddZ ddde d Zd Zd Zd Zd ZdZRS(cCs|t|ttfo&ddkl}||d|}n||_||_|djo h}n||_|i dS(s5 Wraps a WSGI application in a more convenient interface for testing. ``app`` may be an application, or a Paste Deploy app URI, like ``'config:filename.ini#test'``. ``extra_environ`` is a dictionary of values that should go into the environment for each request. These can provide a communication channel with the application. ``relative_to`` is a directory, and filenames used for file uploads are calculated relative to this. Also ``config:`` URIs that aren't absolute. i(tloadappt relative_toN( t isinstancetstrtunicodet paste.deployRtappRtNonet extra_environtreset(tselfRRRR((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyt__init__7s     cCs h|_dS(sc Resets the state of the application; currently just clears saved cookies. N(tcookies(R((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyRSscCs5|ii}t|d<|o|i|n|S(Nspaste.throw_errors(RtcopytTruetupdate(RRtenviron((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyt _make_environZs  cCs:ti|\}}}}}ti||||dfS(Nt(turlparseturlsplitt urlunsplit(Rturltschemetnetloctpathtquerytfragment((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyt_remove_fragmentasc Cs|i|}t}|obt|ttfpti|dt}nd|jo|d7}n |d7}||7}nt|}d|jo |idd\}|dR{tctnameRbRt old_stdouttoutt start_timetrestend_timet total_timetheaderteRatmorsel((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyR<sb     '             cCs t}|djodSt|ttfoS|i|jo>td|iditt ||i i |i fndS|djoN|idjo|idjodStd|i|i i |i fn||ijotd|i|fndS(Nt*s*Bad response: %s (not one of %s for %s) %ss, iis7Bad response: %s (not 200 OK or 3xx redirect for %s) %ssBad response: %s (not %s)(R!RRRFt status_intRR4R]tmapRtrequestR)RfR(RR4RR>((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyR}Ws(   cCs(|i}|otd|ndS(Ns!Application had errors logged: %s(R{R(RRR{((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyR~ms N(R R R!tdisabledRRRR$R/tFalseR@RQRSRURWRKRZR<R}R~(((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyR2s.    5   !         8 RtcBs5eZdZdZdZdZdZRS(cCst|_||_dS(N(Rtcapturedtactual(RR((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyRus cCs$|ii||ii|dS(N(RRxR(Rts((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyRxyscCs|iidS(N(Rtflush(R((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyR}scCs"x|D]}|i|qWdS(N(Rx(RR`titem((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyt writelinesscCs |iiS(N(RRy(R((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyRys(R R RRxRRRy(((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyRtss     t TestResponsecBseZdZdZdZeeddZdZeeddZ e i de i e i BZdZdZddddded Zddddded Zd Zd d Ze i dZdZdZeeddiZdZeeddiZdZdZdZdZ dZ!dZ"ee"de"iZ"dZ#ee#de#iZ#dZ$ee$de$iZ$dZ%ee%de%iZ%dZ&RS(s; Instances of this class are return by ``TestApp`` cCs%|idjo|in|iS(s Returns a dictionary of ``Form`` objects. Indexes are both in order (from zero) and by form id (if the form is given an id). N(t_forms_indexedRt _parse_forms(R((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyt forms__getstdocs| A list of
s found on the page (instances of ``Form``) cCsE|i}|ptdnd|jotdn|dS(Ns*You used response.form, but no forms existis5You used response.form, but more than one form existsi(tformst TypeError(RR((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyt form__gets    s Returns a single ``Form`` instance; it is an error if there are multiple forms on the page. s<(/?)([:a-z0-9_\-]*)(.*?)>c CsZh}|_g}d}x|ii|iD]}|iddj}|idi}|djoq/n|oB|ptd|i|i |i||i !d}q/| ptd|i|i}q/W| ptd|i|xNt |D]@\}}t ||} | ||<| i o| || i unexpected at %ssNested form tags at %ssDanging form: %r(RRt_tag_retfinditerRftgrouptlowertAssertionErrortstartRYtendt enumeratetFormtid( RRt form_textststartedtmatchRttagtittextR((s4/usr/lib/python2.6/site-packages/webtest/__init__.pyRs2         cKs{|idjo|idjptd|i|id}ti|\}}ti|\}}|ii||S(s If this request is a redirect, follow that redirect. It is an error if this is not a redirect response. Returns another response object. i,is/You can only follow redirect responses (not %s)tlocation( RRR4R;R6t splittypet splithostRzR@(RtkwRttypetrestthostR,((s4/usr/lib/python2.6/site-packages/webtest/__init__.pytfollows#  c Csbt}|idddddd d|d|d|d |d |d | \}} } |i| d S(s Click the link as described. Each of ``description``, ``linkid``, and ``url`` are *patterns*, meaning that they are either strings (regular expressions), compiled regular expressions (objects with a ``search`` method), or callables returning true or false. All the given patterns are ANDed together: * ``description`` is a pattern that matches the contents of the anchor (HTML and all -- everything between ```` and ````) * ``linkid`` is a pattern that matches the ``id`` attribute of the anchor. It will receive the empty string if no id is given. * ``href`` is a pattern that matches the ``href`` of the anchor; the literal content of that attribute, not the fully qualified attribute. * ``anchor`` is a pattern that matches the entire anchor, with its contents. If more than one link matches, then the ``index`` link is followed. If ``index`` is not given and more than one link matches, or if no link matches, then ``IndexError`` will be raised. If you give ``verbose`` then messages will be printed about each link, and why it does or doesn't match. If you use ``app.click(verbose=True)`` you'll see a list of all the links. You can use multiple criteria to essentially assert multiple aspects about the link, e.g., where the link's destination is. Rtat href_attrthreft href_extractRnRt href_patternt html_patterntindextverboseturiN(R!t _find_elementRtgoto( Rt descriptiontlinkidRtanchorRRR>t found_htmlt found_desct found_attrs((s4/usr/lib/python2.6/site-packages/webtest/__init__.pytclicks'  c Cskt}|idddddtidd|d|d |d |d |d | \}} } |i| d S(s Like ``.click()``, except looks for link-like buttons. This kind of button should look like ``