ó
[łXMc           @   sÚ   d  Z  d d l Z y d d l Z d d l Z Wn e k
 rG d Z n Xd d l m Z d d l m	 Z	 m
 Z
 m Z d d l m Z m Z d d l m Z d d l m Z d e f d	     YZ d
 e f d     YZ d S(   s%   
Tests for L{twisted.scripts.mktap}.
i˙˙˙˙N(   t   TestCase(   t   runt   getidt   loadPlugins(   t   IProcesst   loadApplication(   t   patchUserDatabase(   t
   TwistedFTPt   RunTestsc           B   sS   e  Z d  Z d   Z d   Z d   Z d   Z d   Z e d k rQ d e _
 n  RS(   s1   
    Tests for L{twisted.scripts.mktap.run}.
    c         C   s   t  j |  _ d S(   sj   
        Save the original value of L{sys.argv} so that tests can change it
        as necessary.
        N(   t   syst   argv(   t   self(    (    sC   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_mktap.pyt   setUp   s    c         C   s   |  j  t j  (d S(   s<   
        Restore the original value of L{sys.argv}.
        N(   R
   R	   (   R   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_mktap.pyt   tearDown"   s    c         C   sX   | t  _ t   t d d d  } t |  } |  j | j |  |  j | j |  d S(   s  
        Test that when L{run} is invoked and L{sys.argv} has the given
        value, the resulting application has the specified UID and GID.

        @type argv: C{list} of C{str}
        @param argv: The value to which to set L{sys.argv} before calling L{run}.

        @type uid: C{int}
        @param uid: The expected value for the resulting application's
            L{IProcess.uid}.

        @type gid: C{int}
        @param gid: The expected value for the resulting application's
            L{IProcess.gid}.
        s   ftp.tapt   pickleN(	   R	   R
   R   R   t   NoneR   t   assertEqualt   uidt   gid(   R   R
   R   R   t   appt   process(    (    sC   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_mktap.pyt   _saveConfiguredIDTest)   s    	c         C   sA   d } d } |  j  d d t |  d t |  d g | |  d S(   s   
        L{run} extracts numeric UID and GID information from the command
        line and persists it with the application object.
        iŇ  iá  t   mktaps   --uids   --gidt   ftpN(   R   t   str(   R   R   R   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_mktap.pyt   test_getNumericIDA   s
    !c         C   sZ   d } d } d } d } t  |  j | | | |  |  j d d | d | d g | |  d	 S(
   s   
        L{run} extracts name UID and GID information from the command
        line and persists it with the application object.
        t   fooiŇ  t   bariá  R   s   --uids   --gidR   N(   R   t   patchR   (   R   t   userR   t   groupR   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_mktap.pyt   test_getNameIDM   s    sE   Username/UID Group name/GID translation requires pwd and grp modules.N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   t   pwdR   t   skip(    (    (    sC   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_mktap.pyR      s   					t   HelperTestsc           B   s    e  Z d  Z d   Z d   Z RS(   sE   
    Tests for miscellaneous utility functions related to mktap.
    c         C   s;   d } d } |  j  t t |  t |   | | f  d S(   sy   
        L{getid} returns a two-tuple of integers giving the numeric values of
        the strings it is passed.
        iŇ  iá  N(   R   R   R   (   R   R   R   (    (    sC   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_mktap.pyt
   test_getide   s    c         C   sa   t    } |  j | d  x- | j   D] \ } } |  j | | j  q& W|  j | d t  d S(   sT   
        L{loadPlugins} returns a C{dict} mapping tap names to tap plugins.
        s$   There should be at least one plugin.R   N(   R   t
   assertTruet	   iteritemsR   t   tapnamet   assertIdenticalR   (   R   t   pluginst   kt   v(    (    sC   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_mktap.pyt   test_loadPluginso   s
    	(   R    R!   R"   R&   R.   (    (    (    sC   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_mktap.pyR%   a   s   	
(   R"   R	   R#   t   grpt   ImportErrorR   t   twisted.trial.unittestR    t   twisted.scripts.mktapR   R   R   t   twisted.application.serviceR   R   t   twisted.test.test_twistdR   t   twisted.plugins.twisted_ftpR   R   R%   (    (    (    sC   /usr/lib/python2.7/dist-packages/twisted/scripts/test/test_mktap.pyt   <module>   s   
K