Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/python/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyc

ó
ê=Nc@s¹dZyddlZWnek
r/dZnXddlmZddlmZddlm	Z	ddl
mZdd
d„ƒYZd	eefd
„ƒYZ
deefd„ƒYZdS(s&
Tests for L{twisted.python.fakepwd}.
iÿÿÿÿN(tgetitem(tTestCase(tUserDatabase(tsettUserDatabaseTestsMixincBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s^
    L{UserDatabaseTestsMixin} defines tests which apply to any user database
    implementation.  Subclasses should mix it in, implement C{setUp} to create
    C{self.database} bound to a user database instance, and implement
    C{getExistingUserInfo} to return information about a user (such information
    should be unique per test method).
    c
CsÓxÌtdƒD]¾}|jƒ\}}}}}}}|jj|ƒ}	|j|	j|ƒ|j|	j|ƒ|j|	j|ƒ|j|	j|ƒ|j|	j	|ƒ|j|	j
|ƒ|j|	j|ƒq
WdS(sc
        I{getpwuid} accepts a uid and returns the user record associated with
        it.
        iN(trangetgetExistingUserInfotdatabasetgetpwuidtassertEqualtpw_namet	pw_passwdtpw_uidtpw_gidtpw_gecostpw_dirtpw_shell(
tselftitusernametpasswordtuidtgidtgecostdirtshelltentry((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyt
test_getpwuids!cCs|jt|jjdƒdS(su
        I{getpwuid} raises L{KeyError} when passed a uid which does not exist
        in the user database.
        ióÿÿÿN(tassertRaisestKeyErrorRR(R((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyttest_noSuchUID1sc
CsÓxÌtdƒD]¾}|jƒ\}}}}}}}|jj|ƒ}	|j|	j|ƒ|j|	j|ƒ|j|	j|ƒ|j|	j|ƒ|j|	j	|ƒ|j|	j
|ƒ|j|	j|ƒq
WdS(sh
        I{getpwnam} accepts a username and returns the user record associated
        with it.
        iN(RRRtgetpwnamR	R
RRR
RRR(
RRRRRRRRRR((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyt
test_getpwnam9s!cCs|jt|jjdƒdS(sz
        I{getpwnam} raises L{KeyError} when passed a username which does not
        exist in the user database.
        s.nosuchuserexiststhenameistoolongandhasinittooN(RRRR(R((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyttest_noSuchNameMsc
Csz|j}|jƒ\}}}}}}}xI|j|ƒ|j|ƒ|jƒdgD]}	|jt|	ƒtƒqVWdS(sm
        The user record returned by I{getpwuid}, I{getpwnam}, and I{getpwall}
        has a length.
        iN(RRRRtgetpwalltassertIsInstancetlentint(
RtdbRRRRRRRR((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyttest_recordLengthXs	!2c
Cs(|j}|jƒ\}}}}}}}x÷|j|ƒ|j|ƒ|jƒdgD]Ê}	|j|	d|ƒ|j|	d|ƒ|j|	d|ƒ|j|	d|ƒ|j|	d|ƒ|j|	d|ƒ|j|	d|ƒ|jt|	ƒtt|	ƒƒƒ|jt	t
|	dƒqVWd	S(
s:
        The user record returned by I{getpwuid}, I{getpwnam}, and I{getpwall}
        is indexable, with successive indexes starting from 0 corresponding to
        the values of the C{pw_name}, C{pw_passwd}, C{pw_uid}, C{pw_gid},
        C{pw_gecos}, C{pw_dir}, and C{pw_shell} attributes, respectively.
        iiiiiiiiN(RRRRR"R	R$tlistRt
IndexErrorR(
RR&RRRRRRRR((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyttest_recordIndexablecs	!2"(	t__name__t
__module__t__doc__RRR R!R'R*(((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyRs					tUserDatabaseTestscBs)eZdZd„Zd„Zd„ZRS(s$
    Tests for L{UserDatabase}.
    cCstƒ|_d|_dS(sC
        Create a L{UserDatabase} with no user data in it.
        iN(RRt_counter(R((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pytsetUp~sc	Cs¥|jd7_dt|jƒ}d|}d|}|j}|jd}d|}d|}d|}|jj|||||||ƒ|||||||fS(	sP
        Add a new user to C{self.database} and return its information.
        it_RRièRRR(R/tstrRtaddUser(	RtsuffixRRRRRRR((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyR†s

	



"c
Cs˜d}d}d}d}d}d}d}|j}|j|||||||ƒx«|j|ƒ|j|ƒgD]‹}	|j|	j|ƒ|j|	j|ƒ|j|	j|ƒ|j|	j|ƒ|j|	j	|ƒ|j|	j
|ƒ|j|	j|ƒqqW|jƒ\}	|j|	j|ƒ|j|	j|ƒ|j|	j|ƒ|j|	j|ƒ|j|	j	|ƒ|j|	j
|ƒ|j|	j|ƒdS(	s
        L{UserDatabase.addUser} accepts seven arguments, one for each field of
        a L{pwd.struct_passwd}, and makes the new record available via
        L{UserDatabase.getpwuid}, L{UserDatabase.getpwnam}, and
        L{UserDatabase.getpwall}.
        talicetsecr3ti{iÈsAlice,,,s/users/alices/usr/bin/fooshN(
RR3RRR	R
RRR
RRRR"(
RRRRRRthomeRR&R((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyttest_addUser˜s2	%(R+R,R-R0RR8(((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyR.zs		tPwdModuleTestscBs5eZdZedkr!dZnd„Zd„ZRS(sÅ
    L{PwdModuleTests} runs the tests defined by L{UserDatabaseTestsMixin}
    against the built-in C{pwd} module.  This serves to verify that
    L{UserDatabase} is really a fake of that API.
    s2Cannot verify UserDatabase against pwd without pwdcCs1t|_t|jjƒƒ|_tƒ|_dS(N(tpwdRtiterR"t_usersRt_uids(R((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyR0Ès	cCsIxBtrD|jjƒ}|j|jkr|jj|jƒ|SqWdS(sÔ
        Read and return the next record from C{self._users}, filtering out
        any records with previously seen uid values (as these cannot be
        found with C{getpwuid} and only cause trouble).
        N(tTrueR<tnextRR=tadd(RR((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyRÎs
	N(R+R,R-R:tNonetskipR0R(((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyR9¾s
		((R-R:tImportErrorRAtoperatorRttwisted.trial.unittestRttwisted.python.fakepwdRttwisted.python.compatRRR.R9(((sD/usr/lib/python2.7/dist-packages/twisted/python/test/test_fakepwd.pyt<module>s

eD