DcTJddlmZddlmZddlmZmZmZmZddlm Z m Z GddeZ GddeZ Gd d eZ y ) )datetime)ResourcedTestCase) FakeLaunchpad FakeResourceFakeRootIntegrityError)FakeLaunchpadResourceget_applicationceZdZdZy) FakeRootTestchtt}|jt|tyN)rr assertTrue isinstancer)self root_resources K/usr/lib/python3/dist-packages/launchpadlib/testing/tests/test_launchpad.pytest_create_root_resourcez&FakeRootTest.test_create_root_resource$s" !23   =,?@N)__name__ __module__ __qualname__rrrr r #sArr c8eZdZdefgZdZdZdZdZy)FakeResourceTest launchpadct}t|g|j_t|jj\}|j dt t |zt|y)z3A custom C{__repr__} is provided for L{FakeEntry}s.entrieszNdictrbugslist assertEqualhexidreprrbugs rtest_repr_entryz FakeResourceTest.test_repr_entry-sVf"C51T^^(()  *SC\ 949 rctdtfd|j_|jjjgt t }|j d|zty)z8A custom C{__repr__} is provided for L{FakeCollection}s. test-branch total_sizecSrrstatusesbranchess rz7FakeResourceTest.test_repr_collection..9hr getBranchesz2N)r!rmer6r%r&r$r')robj_idr2s @rtest_repr_collectionz%FakeResourceTest.test_repr_collection6sd=1 -FG>>$$004R\"  @6 I N rctd|j_|jj}|jdt t |zt |y)z If the fake has a C{name} property it's included in the repr string to make it easier to figure out what it is. foonamezN)r!rr7r$r%r&r'rpersons rtest_repr_with_namez$FakeResourceTest.test_repr_with_nameAsH !e,""  *SF_ Nr r(s rtest_repr_with_idz"FakeResourceTest.test_repr_with_idLs[ c*"C51T^^(() 2SC\A49MrN) rrrr resourcesr*r9r@rFrrrrr)s(4678I     NrrceZdZdefgZdZdZdZdZdZ dZ dZ d Z d Z d Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"d Z#d!Z$d"Z%d#Z&d$Z'd%Z(d&Z)d'Z*d(Z+d)Z,d*Z-d+Z.y,)-FakeLaunchpadTestrct}t|}|j||j|jt |j y)zy The builtin WADL definition is used if the C{application} is not provided during instantiation. N)objectrr$ credentialsr _applicationrrLrs r'test_wb_instantiate_without_applicationz9FakeLaunchpadTest.test_wb_instantiate_without_application[sD h !+.  i&;&;< *I,B,BCrc t}t|ddddt}|j||jy)z L{FakeLaunchpad} takes the same parameters as L{Launchpad} during instantiation, with the addition of an C{application} parameter. The optional parameters are discarded when the object is instantiated. N) service_rootcachetimeout proxy_info applicationrKrr r$rLrNs r test_instantiate_with_everythingz2FakeLaunchpadTest.test_instantiate_with_everythingesB h ! ')   i&;&;>3D3DfMrctd|j_|jd|jjjy)z Sample data can be created by setting L{FakeLaunchpad} attributes with dicts that represent objects. Plain string values can be represented as C{str} values. r;r<Nr!rr7r$r=r\s rtest_string_propertyz&FakeLaunchpadTest.test_string_propertys5 !e,  1 1 6 67rctd|j_|jd|jjjy)z Sample data can be created by setting L{FakeLaunchpad} attributes with dicts that represent objects. Plain string values can be represented as C{unicode} strings. r;r<Nrjr\s rtest_unicode_propertyz'FakeLaunchpadTest.test_unicode_propertys5 !f- !2!2!7!78rctj}t||j_|j ||jjj y)zU Attributes that represent dates are set with C{datetime} instances.  date_createdN)rutcnowr!rr7r$rp)rnows rtest_datetime_propertyz(FakeLaunchpadTest.test_datetime_propertysAoo c2 dnn//<<=rc f|jtt|jdt dy)z Only C{datetime} values can be set on L{FakeLaunchpad} instances for attributes that represent dates. r7rrroNr`rrarr!r\s rtest_invalid_datetime_propertyz0FakeLaunchpadTest.test_invalid_datetime_propertys*    NN  e $  rctdd|j_|jd|jjj|jd|jjj y)z~ Sample data can be created by setting L{FakeLaunchpad} attributes with dicts that represent objects. r;rd)r=reN)r!rr7r$r=rer\s rtest_multiple_string_propertiesz1FakeLaunchpadTest.test_multiple_string_propertiessW !e%@  1 1 6 67  1 1 > >?rc f|jtt|jdt dy)z Sample data set on a L{FakeLaunchpad} instance is validated against the WADL definition. If a key is defined on a resource that doesn't match a related parameter, an L{IntegrityError} is raised. r7r_r;Nrur\s rtest_invalid_property_namez,FakeLaunchpadTest.test_invalid_property_names%  GT^^T4E? rc f|jtt|jdt dy)z The types of sample data values set on L{FakeLaunchpad} instances are validated against types defined in the WADL definition. r7fr<Nrur\s rtest_invalid_property_valuez-FakeLaunchpadTest.test_invalid_property_values%  GT^^T4S> rctdtfd|j_|jd|jjj gy)z A callable set on a L{FakeLaunchpad} instance is validated against the WADL definition, to make sure a matching method exists. r,r-cSrrr0s rr3z1FakeLaunchpadTest.test_callable..r4rr5N)r!rr7assertNotEqualr6rr2s @r test_callablezFakeLaunchpadTest.test_callablesF =1 -FG D$.."3"3"?"?"CDrc h|jtt|jdt dy)z An L{IntegrityError} is raised if a method is defined on a resource that doesn't match a method defined in the WADL definition. r7cyrrrrrr3z>FakeLaunchpadTest.test_invalid_callable_name..rrzNrur\s rtest_invalid_callable_namez,FakeLaunchpadTest.test_invalid_callable_names*    NN  \ "  rctdtfd|j_|jjjg|j t t |jdjy)z The result of a fake method is a L{FakeResource}, automatically created from the object used to define the return object. 8r-cSrrr0s rr3zDFakeLaunchpadTest.test_callable_object_return_type..r4rr5N) r!rr7r6rrrr$r.rs @r test_callable_object_return_typez2FakeLaunchpadTest.test_callable_object_return_typesd 3' -FG>>$$004  8\:; h112rctdtfd|j_|jt|jjj gy)zW An L{IntegrityError} is raised if a method returns an invalid result. r-cSrrr0s rr3zLFakeLaunchpadTest.test_invalid_callable_object_return_type..r4rr5N)r!rr7r`rr6rs @r(test_invalid_callable_object_return_typez:FakeLaunchpadTest.test_invalid_callable_object_return_typesC1% -FG .$..*;*;*G*GLrctd|j_|j|jjj dy)z} A fake method passes through a return value of None rather than trying to create a L{FakeResource}. cyrrr<s rr3zDFakeLaunchpadTest.test_callable_object_return_None..rrgetByUniqueNamer;N)r!rr2r[rr\s r test_callable_object_return_Nonez2FakeLaunchpadTest.test_callable_object_return_Nones9 #'7H"I $..11AA%HIrctdtfd|j_|jjjd|j j y)z If the WADL definition of a method does not include a response representation, then fake versions of that method just pass through the return value. cy)NTrrrrr3zSFakeLaunchpadTest.test_callable_object_no_response_representation..rr) canBeDeletedcSrrr=branchs rr3zSFakeLaunchpadTest.test_callable_object_no_response_representation..Frrr;N)r!rr2rrrrrs @r/test_callable_object_no_response_representationzAFakeLaunchpadTest.test_callable_object_no_response_representationsP <0"&7J"K((88? ++-.rcttd}t|g|j_|jjd}|jd|jj y)zx Attributes that represent links to other objects are set using a dict representing the object. z test-personr<ownerrrN)r!rr"r$rr=r(s rtest_entry_propertyz%FakeLaunchpadTest.test_entry_propertysR =12"C51nn!!!$  7rc ttd}|jtt|jdt|gy)z> Sample data for linked entries is validated. r_rzrr"rNr!r`rrarr(s rtest_invalid_entry_propertyz-FakeLaunchpadTest.test_invalid_entry_propertys:%)    NN  #   rctdtfd|j_|jjjd|j dj y)z Sample top-level collections can be set on L{FakeLaunchpad} instances. They are validated the same way other sample data is validated. r;r<cSrrrs rr3zFFakeLaunchpadTest.test_top_level_collection_property..1rrrN)r!rr2rr$r=rs @r"test_top_level_collection_propertyz4FakeLaunchpadTest.test_top_level_collection_property*sO 5!"&7J"K((88?  ,rc8td}tt|gtfd|j_|jjjdt j \}|j d|jy) z Attributes that represent links to collections of other objects are set using a dict representing the collection. rB)r&r linked_bugscSrrrs rr3z.<rrrr;N)r!rr2rr#rr$r&rr)rs @rtest_collection_propertyz*FakeLaunchpadTest.test_collection_property5sq cl$u"56"&7J"K((88?V''( cff%rcDtdd}t|g|j_t|jj}|j dt ||d}|j d|j |j d|jy)z Data for a sample collection set on a L{FakeLaunchpad} instance can be iterated over if an C{entries} key is defined. rBrCrDrrN)r!rr"r#r$lenr&rE)rr)r"s rtest_iterate_collectionz)FakeLaunchpadTest.test_iterate_collectionAs| c*"C51DNN''( CI&1g cff% 399-rc td}|jtt|jdt|gy)z Sample data for each entry in a collection is validated when it's set on a L{FakeLaunchpad} instance. r_rzr"rNrr(s r.test_top_level_collection_with_invalid_entriesz@FakeLaunchpadTest.test_top_level_collection_with_invalid_entriesNs5 uo    NN  #   rctd}tt|gtfd|j_|jt|jjj dy) z Sample data for each entry in a collection is validated when it's set on an attribute representing a link to a collection of objects. r_rzrrcSrrrs rr3zHFakeLaunchpadTest.test_collection_with_invalid_entries..crrrr;N)r!rr2r`rrrs @r$test_collection_with_invalid_entriesz6FakeLaunchpadTest.test_collection_with_invalid_entries\sX uo$u"56"&7J"K   NN # # 3 3  rcrtdd}tdd}tdd}t|||g|j_|jjd d }|jd t ||jd|d j |jd|d j y )z Data for a sample collection set on a L{FakeLaunchpad} instance can be sliced if an C{entries} key is defined. rBrCrD2Bug #23zBug #3rrrN)r!rr"r$rr&)rbug1bug2bug3r"s rtest_slice_collectionz'FakeLaunchpadTest.test_slice_collectionjs s(+s(+s(+"D$+=>~~""1Q' CI& d1gjj) d1gjj)rctdd}tdd}t||gj_jtfdjtfdy ) z A C{ValueError} is raised if a negative start value is used when slicing a sample collection set on a L{FakeLaunchpad} instance. rBrCrDrrrc6jjddSNrr"r\srr3zMFakeLaunchpadTest.test_slice_collection_with_negative_start..sdnn.A.A"#.Frc6jjddS)Nrrrr\srr3zMFakeLaunchpadTest.test_slice_collection_with_negative_start..sdnn.A.A"Q.GrNr!rr"r` ValueErrorrrrs` r)test_slice_collection_with_negative_startz;FakeLaunchpadTest.test_slice_collection_with_negative_startxT s(+s(+"D$<8 *&FG *&GHrctdd}tdd}t||gj_jtfdjtfdy ) z A C{ValueError} is raised if a negative stop value is used when slicing a sample collection set on a L{FakeLaunchpad} instance. rBrCrDrrrc6jjddSrrr\srr3zLFakeLaunchpadTest.test_slice_collection_with_negative_stop..sdnn.A.A#2.Frc6jjddS)Nrrrr\srr3zLFakeLaunchpadTest.test_slice_collection_with_negative_stop..sdnn.A.A!B.GrNrrs` r(test_slice_collection_with_negative_stopz:FakeLaunchpadTest.test_slice_collection_with_negative_stoprrctdd}t|gj_jtfdy)z An C{IndexError} is raised if an invalid index is used when retrieving data from a sample collection. rBrCrDrc6jjdS)Nrrr\srr3zHFakeLaunchpadTest.test_subscript_operator_out_of_range..sdnn.A.A!.DrN)r!rr"r` IndexError)rrs` r$test_subscript_operator_out_of_rangez6FakeLaunchpadTest.test_subscript_operator_out_of_ranges5 s(+"D62 *&DErcDtd|j_|jj}|jd|jd|_|jd|j|jd|jjjy)zs rtest_replace_propertyz'FakeLaunchpadTest.test_replace_propertysq e,""  ,   ,  1 1 6 67rc6tddtddtfd|j_fd|jj_|jjjd}|j d|j y) z=Methods already set on fake resource objects can be replaced.r;zlp:~user/project/branch1)r= bzr_identityzlp:~user/project/branch2cSrr)r=branch1s rr3z7FakeLaunchpadTest.test_replace_method..sGrrcSrr)r=branch2s rr3z7FakeLaunchpadTest.test_replace_method..swrN)r!rr2rr$r)rrrrs @@rtest_replace_methodz%FakeLaunchpadTest.test_replace_methodsrE0JKE0JK"&7K"L2F/((88? 3V5H5HIrctd|j_|jj}|jtt |ddy)z2Values set on fake resource objects are validated.r;r<r=rN)r!rr7r`rrar>s r(test_replace_property_with_invalid_valuez:FakeLaunchpadTest.test_replace_property_with_invalid_values8 e,"" .'661Erc0td|j_|jd|jjjtd|j_|jd|jjjy)z:Resources already set on L{FakeLaunchpad} can be replaced.r;r<r_Nrjr\s rtest_replace_resourcez'FakeLaunchpadTest.test_replace_resourcesd e,  1 1 6 67 e,  1 1 6 67rctd|j_|jj}d|_|j d|j |j d|j|j d|jjj |j d|jjjy)z?Sample data set on a L{FakeLaunchpad} instance can be added to.r;r<rdN)r!rr7rer$r=r>s rtest_add_propertyz#FakeLaunchpadTest.test_add_propertys e,""#  ,  3 34  1 1 6 67  1 1 > >?rc,t|j_|jtt |jjdd|jj_|jd|jjj y)z6An empty object can be used when creating sample data.r=r;N)r!rr7r`rfrgr=r$r\s r!test_add_property_to_empty_objectz3FakeLaunchpadTest.test_add_property_to_empty_objects` F .'4>>3D3DfM!&  1 1 6 67rcptjddd}|jt|ty)z L{FakeLaunchpad.login} ignores all parameters and returns a new instance using the builtin WADL definition. r=tokensecretN)rloginrrrrs r test_loginzFakeLaunchpadTest.test_logins+ "''B   9m<=rcltjd}|jt|ty)z L{FakeLaunchpad.get_token_and_login} ignores all parameters and returns a new instance using the builtin WADL definition. r=N)rget_token_and_loginrrrs rtest_get_token_and_loginz*FakeLaunchpadTest.test_get_token_and_logins' "55f=   9m<=rcltjd}|jt|ty)z L{FakeLaunchpad.login_with} ignores all parameters and returns a new instance using the builtin WADL definition. r=N)r login_withrrrs rtest_login_withz!FakeLaunchpadTest.test_login_withs' ",,V4   9m<=rctd|j_|j|jjj y)zU Sample object have an C{lp_save} method that is a no-op by default. r;r<N)r!rr7rlp_saver\s r test_lp_savezFakeLaunchpadTest.test_lp_saves4!e, ))1134rctdd|j_|jd|jjj y)z;A custom C{lp_save} method can be set on a L{FakeResource}.r;cyNcustomrrrrr3z7FakeLaunchpadTest.test_custom_lp_save..rr)r=rrN)r!rr7r$rr\s rtest_custom_lp_savez%FakeLaunchpadTest.test_custom_lp_saves9 e5EF 4>>#4#4#<#<#>?rctd|j_d|jj_|j d|jjjy)zl A custom C{lp_save} method can be set on a L{FakeResource} after its been created. r;r<cyrrrrrr3z;FakeLaunchpadTest.test_set_custom_lp_save..rrrN)r!rr7rr$r\s rtest_set_custom_lp_savez)FakeLaunchpadTest.test_set_custom_lp_savesJ !e,$4! 4>>#4#4#<#<#>?rN)/rrrr rGrOrWrYr]rbrhrkrmrsrvrxr{r~rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrIrIWs4678ID="= 6 N89>  @  E   3MJ /8   - & .     * I IF8JF 8@8>>>5@ @rrIN)r testresourcesrlaunchpadlib.testing.launchpadrrrrlaunchpadlib.testing.resourcesr r r rrIrrrrsL&+  A$A +N(+N\[@)[@r