
{Jc        .   @   s  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k	 l
 Z
 l Z d  d k l Z y  d  d k Z d  d k l Z Wn e j
 o d Z n Xy d  d k Z Wn e j
 o d Z n Xd  d k l Z l Z l Z l Z l Z l Z d  d k l Z d  d k l Z l Z x e i  d  D] Z! e i" d e! d	 j or xo e! d
 D]_ Z# e# i$ d  oI e i% i& e! d	 e# d  d  Z# e i% i' e#  o e i( e#  qq{q{WqRqRWe i% i' d  o.x e i  d  D] \ Z) Z* Z+ e i% i, e)  Z, e i% i, e i% i- e)   Z- e i% i& e) d  Z. e, d j oM e- d	 e i/ d j o5 e i% i' e.  o" d e) d
 i0 e i" d  Z1 Pq	q	Wd Z1 y e d d d e1  Wq4e j
 o< Z2 d  d k3 Z3 e3 i4 d e2 e5  e d d d d  q4Xn e i6 d  e i7 h h e8 d 6e9 d 6d 6 d d  Z: d   Z; d   Z< d d  Z= d   Z> e8 d   Z? d a@ d! e iA f d"     YZB eB   ZC d#   ZD d$   ZE d%   ZF d&   ZG d'   ZH d(   ZI d) e iJ f d*     YZK d+ eL f d,     YZM d- dW d.     YZN d/ dX d0     YZO d1 dY d2     YZP d3 e iJ f d4     YZQ d5 eQ f d6     YZR d7 eQ f d8     YZS e iT d9  o
 eR ZU n' e iT d:  o
 eS ZU n eV d;   e d<  e>  ZW e d=  e;  ZX d aY e   d>    ZZ e   d?    Z[ e d@  dA dB h  d dC dD dE dF   Z\ e\ Z] dG   Z^ e dH  dI    Z_ e dH  dJ    Z` d+ dK d7 d5 dL d- d) dM dN dO dP dQ dR dS dT dU dV g Za d S(Z   iN(   t   Requestt   Response(   t   TestApp(   t   InheritableSQLObject(   t   configt   controllerst   databaset   startupt   update_configt
   validators(   t   current_provider(   t	   get_modelt
   deprecatedt   .i    i   s   .kidit   pycs   test.cfgs   __init__.pyR   t   _s   %s.appt
   configfilet
   modulenames.   Could not import configuration from module: %ss   sqlite:///:memory:s   autoreload.ons   tg.new_style_loggingt   globalt   /c         C   s4   | d j o |  t  _ n t  i i |  |  t   S(   s:   Mount a controller at a path.  Returns a wsgi application.R   (   t   cherrypyt   roott   treet   mountt   make_wsgiapp(   t
   controllert   path(    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR   H   s    c           C   s   d t _ h  t i _ d S(   s5   Remove an application from the object traversal tree.N(   t   NoneR   R   R   t   mount_points(    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   unmountP   s    	c          C   s   t  i i }  |  S(   s6   Return a WSGI application from cherrypy's root object.(   R   t   _cpwsgit   wsgiApp(   t   wsgiapp(    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR   Y   s    c         C   s0   |  o t  |    d  } n
 t   } t |  S(   s   Return a WebTest.TestApp instance from Cherrypy.

    If a Controller object is provided, it will be mounted at the root level.
    If not, it'll look for an already mounted root.

    R   (   R   R   R   (   R   R    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   make_app^   s    	c           C   sw   t  i d  p1 t i i d d d t  t  i h t d 6 n t  i d  p" t i	   t  i h t d 6 n d S(   s-   Start the server if it's not already started.t
   cp_startedt   serverClasst   initOnlyt   server_startedN(
   R   t   getR   t   servert   startR   t   Truet   updateR   t   startTurboGears(    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   start_serverk   s    
c         C   sz   t    t i d  o- |  o% t i i   t i h t d 6 n t i d  o" t i	   t i h t d 6 n d S(   sx   Stop the server and unmount the application.

    Use tg_only = True to leave CherryPy running (for faster tests).

    R"   R%   N(
   R   R   R&   R   R'   t   stopR*   t   FalseR   t   stopTurboGears(   t   tg_only(    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   stop_serveru   s    
t   MemoryListHandlerc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   s&   t  i i |  d t  i g  |  _ d  S(   Nt   level(   t   loggingt   Handlert   __init__t   DEBUGt   log(   t   self(    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR6      s    c         C   s8   d | GHd |  i  |  GH|  i i |  i  |   d  S(   Ns   Got record: %ss   formatted as: %s(   t   formatR8   t   append(   R9   t   record(    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   emit   s    	c         C   s   d i  |  i  GHg  |  _ d  S(   Ns   
(   t   joinR8   (   R9   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt	   print_log   s    c         C   s   |  i  } g  |  _  | S(   N(   R8   (   R9   R8   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   get_log   s    		(   t   __name__t
   __module__R6   R=   R?   R@   (    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR2      s   			c         C   sd   y |  i  |  } Wn> t i j
 o/ } y | i   } WqZ t j
 o qZ Xn Xh  } | | f S(   s:   Catch and unpack validation errors (for testing purposes).(   t   validateR	   t   Invalidt   unpack_errorst   AttributeError(   t   widgett   valuet   errors(    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   catch_validation_errors   s    
c         C   s   t  p
 t d  t |  t  o t |  t  o |  g }  n |  a  x: |  D]2 } t i |  } | i t i  | i	 t
  qN Wd S(   s   Capture log for one category.

    The category can either be a single category (a string like 'foo.bar')
    or a list of them. You *must* call print_log() to reset when you're done.

    s/   _currentcat not cleared.  Use get_log to reset.N(   t   _currentcatt   AssertionErrort
   isinstancet   listt   tupleR4   t	   getLoggert   setLevelR7   t
   addHandlert   _memhandler(   t   categoryt   catR8   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   capture_log   s    " c          C   sC   t  p d Sx* t  D]" }  t i |   } | i t  q Wd a  d S(   s$   Manage the resetting of the loggers.N(   RK   R4   RP   t   removeHandlerRS   R   (   RU   R8   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   _reset_logging   s     c           C   s   t    t i   d S(   sv   Print the log captured by capture_log to stdout.

    Resets that log and resets the temporarily added handlers.

    N(   RX   RS   R?   (    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR?      s    c           C   s   t    t i   S(   s~   Return the list of log messages captured by capture_log.

    Resets that log and resets the temporarily added handlers.

    (   RX   RS   R@   (    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR@      s    c           C   so   t  i i   y t  i i   Wn4 t j
 o( t  i i o t  i i i   qU n Xd  t  _ t i	 i
   d  S(   N(   R   t   metadatat   cleart   disposeRF   t   bindR   t   _enginet
   sqlalchemyt   ormt   clear_mappers(    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   sqlalchemy_cleanup   s    	t   TGTestc           B   sA   e  Z d  Z d Z d Z e Z d Z d   Z	 d   Z
 d   Z RS(   s   A WebTest enabled unit testing class.

    To use, subclass & set root to your controller object, or set app to a
    webtest.TestApp instance.

    In your tests, use self.app to make WebTest calls.

    c         C   sf   |  i  p |  i p
 t d  |  i p t |  i   |  _ n |  i p t i   |  _ n t   d S(   s.  Set up the WebTest by starting the server.

        You should override this and make sure you have properly
        mounted a root for your server before calling super,
        or simply pass a root controller to super.
        Otherwise the Cherrypy filters for TurboGears will not be used.

        s(   Either self.root or self.app must be setN(   R   t   appRL   R!   R   t   copyR,   (   R9   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   setUp   s    	

c         C   s$   t  d |  i  t i |  i  d S(   s-   Tear down the WebTest by stopping the server.R0   N(   R1   t   stop_tg_onlyR   R*   (   R9   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   tearDown  s    c      	   C   s;   |  i  i t i d  t d | i d | i d d   d S(   s,   Log a specified user object into the system.s   identity.failure_urlt	   user_namet   passwordt   logint   LoginN(   Rc   t   postR   R&   t   dictRh   Ri   (   R9   t   user(    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt
   login_user	  s    N(   RA   RB   t   __doc__R   R   Rc   R.   Rf   R   Re   Rg   Ro   (    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyRb      s   		t   BrowsingSessionc           B   s   e  Z d    Z d   Z RS(   c         C   s:   d  |  _ d \ |  _ |  _ t i   |  _ t   |  _ d  S(   N(   NN(	   R   t   visitt   responset   statust   Cookiet   SimpleCookiet   cookieR!   Rc   (   R9   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR6     s    	c   	      O   s   |  i  o# | i d h   } |  i | d <n |  i i | |   } | i d i d  } xQ | d D]E } | i   i d  \ } } y | i i	 |  |  _
 PWqc qc Xqc W| i |  _ | |  _ | i |  _ | i |  _  | i i d d  |  _ d  S(	   Nt   headersRu   s   Content-Typet   ;i   t   =s
   Set-Cookiet    (   Rw   t
   setdefaultt   cookie_encodedRc   R&   Rx   t   splitt   stript   bodyt   decodet   unicode_responseRs   t   full_responseRt   t   cookies_set(	   R9   t   argst   kwargsRx   Rs   t   ctype_partst	   parametert	   attributeRH   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   goto  s$    
 	(   RA   RB   R6   R   (    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyRq     s   	t   DummySessionc           B   s   e  Z d  Z e Z d Z RS(   s   A very simple dummy session.N(   RA   RB   Rp   Rm   t   session_storageR   t   to_be_loaded(    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR   1  s   t   DummyRequestc           B   s/   e  Z d  Z d Z d d d d  Z d   Z RS(   s   A very simple dummy request.s	   127.0.0.1t   GETR   c         C   sP   | p h  |  _  | |  _ | |  _ d |  _ t   |  _ t i d d  |  _ d  S(   NR{   s   tg.defaultviewt   kid(	   Rx   t   methodR   t   baseR   t   _sessionR   R&   t   tg_template_enginename(   R9   R   R   Rx   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR6   =  s    			c         C   s   d  S(   N(    (   R9   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   purge__E  s    N(   RA   RB   Rp   t   remote_hostR   R6   R   (    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR   8  s   t   DummyResponsec           B   s   e  Z d  Z h  Z RS(   s   A very simple dummy response.(   RA   RB   Rp   Rx   (    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR   I  s   t   AbstractDBTestc           B   s&   e  Z d  Z d Z d   Z d   Z RS(   s   A database enabled unit testing class.

    Creates and destroys your database before and after each unit test.
    You must set the model attribute in order for this class to
    function correctly.

    c         C   s   t     d  S(   N(   t   NotImplementedError(   R9   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyRe   Y  s    c         C   s   t     d  S(   N(   R   (   R9   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyRg   \  s    N(   RA   RB   Rp   R   t   modelRe   Rg   (    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR   O  s   	t   DBTestSOc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   sZ   y3 g  } |  i  i D] } | |  i  i | q ~ SWn  t j
 o |  i  i i   SXd  S(   N(   R   t	   soClassest   __dict__RF   t   values(   R9   t   _[1]t   x(    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   _get_soClassesb  s    3c         C   s   |  i  p* t   |  _  |  i  p t d   q4 n t   } x |  i   D]} } t | t i  od t | t	 i
  oQ | t	 i
 j oA | t j o4 | i d t d t  } | o | i |  q qJ qJ Wx | D] } | i i |  q Wd  S(   Ns,   Unable to run database tests without a modelt   ifNotExistst   applyConstraints(   R   R   t	   ExceptionRN   R   RM   t   typest   TypeTypet
   issubclasst	   sqlobjectt	   SQLObjectR   t   createTableR)   R.   t   extendt   _connectiont   query(   R9   t   constraintst   itemt   collected_constraintst   postponed_constraint(    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyRe   h  s"    

	 	 c         C   s   t  i   xw t |  i    D]c } t | t i  oJ t | t i	  o7 | t i	 j o' | t
 j o | i d t d t  q q Wd  S(   Nt   ifExistst   cascade(   R   t   rollback_allt   reversedR   RM   R   R   R   R   R   R   t	   dropTableR)   (   R9   R   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyRg     s    
 (   RA   RB   R   Re   Rg   (    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR   `  s   		t   DBTestSAc           B   s   e  Z d    Z d   Z RS(   c         C   s   t  i   t  i i   d  S(   N(   R   t
   get_engineRY   t
   create_all(   R9   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyRe     s    
c         C   s   t  i i   d  S(   N(   R   RY   t   drop_all(   R9   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyRg     s    (   RA   RB   Re   Rg   (    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR     s   	s   sqlobject.dburis   sqlalchemy.dburis,   Unable to find sqlalchemy or sqlobject dburis&   start_cp is superceded by start_servers(   reset_cp has been superceded by unmount.c         C   s
   |  a  d S(   s0   Setup a user for configuring request's identity.N(   t	   test_user(   Rn   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   set_identity_user  s    c         C   sA   t  i d t  o* t o t i t  p
 t i   |  _ n d  S(   Ns   identity.on(   R   R&   R.   R   R
   t   authenticated_identityt   anonymous_identityt   identity(   t   req(    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   attach_identity  s    s?   create_request is deprecated.  See TestMigration on the TG WikiR   s   HTTP/1.1s	   127.0.0.1t	   localhostt   httpc         C   s  t    | p t i d  } n t |  t j o
 | } n4 g  }	 | i   D] \ }
 } |	 |
 | f qO ~	 } | i d  t t i d  p t	 i
   t t i _ n t | d | |  } | t i _ t |  t   t i _ | i d i | |  | f  | |  t i i S(   NR{   t   HostR   t   startediP   t    (   s   Hosts	   localhost(   R,   t   StringIOt   typeRm   t   itemsR;   t   hasattrR   R   R   R+   R)   R   R    t   servingt   requestR   R   Rs   t   runR>   (   R   R   t   protocolRx   t   rfilet   clientAddresst
   remoteHostt   schemet
   headerListR   t   keyRH   R   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   create_request  s     
3

%c         G   s   |  S(   N(    (   t   outputR   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   _return_directly  s    s1   Please see the TestMigration page in the TG wiki.c         O   s)   t    t |  t   | |  \ } } | S(   N(   R,   t   call_with_requestR   (   R   R   t   kwR   Rs   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   call  s    c         O   s   t  i } t t  _ t   t i _ | t i _ t | d  p t	 |  n d } z |  | |   } Wd t i ` | t  _ Xt i i } | | f S(   sX   More fine-grained version of call method.

    This allows using request/response.

    R   N(   R   t   _process_outputR   R   R   R   Rs   R   R   R   R   (   R   R   R   R   t   orig_proc_outputR   Rs   (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyR     s    			
t   DBTestt   DummyRequestDumyResponseRV   R!   R   R   R?   R@   Ra   R,   R1   R   (    (    (    (b   Ru   t	   cStringIOR   t   osR   R4   t   stringt   unittestR   t   cherrypy._cphttptoolsR    R   t   webtestR   R   t   sqlobject.inheritanceR   t   ImportErrorR   R^   t
   turbogearsR   R   R   R   R   R	   t   turbogears.identityR
   t   turbogears.utilR   R   t   walkt   wt   sept   ft   endswithR   R>   t   existst   removet   dirpatht   dirst   dummy2t   basenamet   dirnamet   init_pyt   ascii_letterst   replaceR   t   exct   warningst   warnt   RuntimeWarningt
   set_db_uriR*   R.   R)   R   R   R   R!   R,   R1   RK   R5   R2   RS   RJ   RV   RX   R?   R@   Ra   t   TestCaseRb   t   objectRq   R   R   R   R   R   R   R&   R   R   t   start_cpt   reset_cpR   R   R   R   t   createRequestR   R   R   t   __all__(    (    (    sq   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.6/site-packages/TurboGears-1.1rc1-py2.6.egg/turbogears/testutil.pyt   <module>   s   .  !! %						
				
					*"-

			