o Ʋa?@stddlmZddlmZddlmZmZmZmZddlm Z m Z GdddeZ GdddeZ Gd d d eZ d S) )datetime)ResourcedTestCase) FakeLaunchpad FakeResourceFakeRootIntegrityError)FakeLaunchpadResourceget_applicationc@seZdZddZdS) FakeRootTestcCstt}|t|tdSN)rr assertTrue isinstancer)self root_resourcerK/usr/lib/python3/dist-packages/launchpadlib/testing/tests/test_launchpad.pytest_create_root_resource$s z&FakeRootTest.test_create_root_resourceN)__name__ __module__ __qualname__rrrrrr #s r c@s0eZdZdefgZddZddZddZdS) FakeResourceTest launchpadcsRtddtfddd|j_|jjgtt}|d|tdS)z6A custom C{__repr__} is provided for L{FakeResource}s. test-branch total_sizecSr rstatusesbranchesrr0z,FakeResourceTest.test_repr.. getBranchesz0N)dictrmer#hexid assertEqualrepr)robj_idrrr test_repr-s  zFakeResourceTest.test_reprcCs6tdd|j_|jj}|dtt|t|dS)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$rr%r(r&r'r)rpersonrrrtest_repr_with_name8s z$FakeResourceTest.test_repr_with_namecCsJtddd}t|gd|j_t|jj\}|dtt|t|dS)z If the fake has an C{id} property it's included in the repr string to make it easier to figure out what it is. 1Bug #1r'titleentrieszN)r$rbugslistr(r&r'r)rbugrrrtest_repr_with_idCs z"FakeResourceTest.test_repr_with_idN)rrrr resourcesr+r1r<rrrrr)s   rc@s8eZdZdefgZddZddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Z d:d;Z!dd?Z#d@dAZ$dBdCZ%dDdEZ&dFdGZ'dHdIZ(dJS)KFakeLaunchpadTestrcCs0t}t|}|||j|t|jdS)zy The builtin WADL definition is used if the C{application} is not provided during instantiation. N)objectrr( credentialsr _applicationrr@rrrr'test_wb_instantiate_without_applicationTsz9FakeLaunchpadTest.test_wb_instantiate_without_applicationcCs.t}t|ddddtd}|||jdS)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 applicationr?rr r(r@rBrrr test_instantiate_with_everything^sz2FakeLaunchpadTest.test_instantiate_with_everythingcCs&t}t|td}|||jdS)z8A L{FakeLaunchpad} can be instantiated with credentials.)rHNrIrBrrr!test_instantiate_with_credentialsosz3FakeLaunchpadTest.test_instantiate_with_credentialscCs||jjdS)z~ A L{FakeLaunchpad} instantiated without credentials has its C{credentials} attribute set to C{None}. N) assertIsNonerr@rrrr$test_instantiate_without_credentialsusz6FakeLaunchpadTest.test_instantiate_without_credentialscCs|tt|jdddS)z An L{IntegrityError} is raised if an attribute is set on a L{FakeLaunchpad} instance that isn't present in the WADL definition. r,barN) assertRaisesrsetattrrrMrrrtest_set_undefined_property|s z-FakeLaunchpadTest.test_set_undefined_propertycCs&tdd|j_|tt|jjddS)z An L{AttributeError} is raised if an attribute is accessed on a L{FakeLaunchpad} instance that doesn't exist. Foo) display_namer.N)r$rr%rPAttributeErrorgetattrrMrrrtest_get_undefined_resourcesz-FakeLaunchpadTest.test_get_undefined_resourcecC$tdd|j_|d|jjjdS)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$rr%r(r.rMrrrtest_string_propertyz&FakeLaunchpadTest.test_string_propertycCrX)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-NrYrMrrrtest_unicode_propertyr[z'FakeLaunchpadTest.test_unicode_propertycCs,t}t|d|j_|||jjjdS)zU Attributes that represent dates are set with C{datetime} instances.  date_createdN)rutcnowr$rr%r(r^)rnowrrrtest_datetime_propertysz(FakeLaunchpadTest.test_datetime_propertyc C|tt|jdtdddS)z Only C{datetime} values can be set on L{FakeLaunchpad} instances for attributes that represent dates. r%r`r]NrPrrQrr$rMrrrtest_invalid_datetime_propertysz0FakeLaunchpadTest.test_invalid_datetime_propertycCs8tddd|j_|d|jjj|d|jjjdS)z~ Sample data can be created by setting L{FakeLaunchpad} attributes with dicts that represent objects. r,rS)r.rTN)r$rr%r(r.rTrMrrrtest_multiple_string_propertiessz1FakeLaunchpadTest.test_multiple_string_propertiesc Crb)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. r%rOr,NrcrMrrrtest_invalid_property_namesz,FakeLaunchpadTest.test_invalid_property_namec Crb)z The types of sample data values set on L{FakeLaunchpad} instances are validated against types defined in the WADL definition. r%fr-NrcrMrrrtest_invalid_property_valuesz-FakeLaunchpadTest.test_invalid_property_valuecs:tddtfddd|j_|d|jjgdS)z A callable set on a L{FakeLaunchpad} instance is validated against the WADL definition, to make sure a matching method exists. rrcrr rrrrrr r!z1FakeLaunchpadTest.test_callable..r"N)r$rr%assertNotEqualr#rMrrr test_callables zFakeLaunchpadTest.test_callablec Cs"|tt|jdtddddS)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. r%cSsdSr rrrrrr r!z>FakeLaunchpadTest.test_invalid_callable_name..rfNrcrMrrrtest_invalid_callable_names z,FakeLaunchpadTest.test_invalid_callable_namecsPtddtfddd|j_|jjg|tt|djdS)z The result of a fake method is a L{FakeResource}, automatically created from the object used to define the return object. 8rcrr rrrrrr r!zDFakeLaunchpadTest.test_callable_object_return_type..r"N) r$rr%r#r r rr(rrMrrr test_callable_object_return_types z2FakeLaunchpadTest.test_callable_object_return_typecs8tddtfddd|j_|t|jjjgdS)zW An L{IntegrityError} is raised if a method returns an invalid result. rcrr rrrrrr r!zLFakeLaunchpadTest.test_invalid_callable_object_return_type..r"N)r$rr%rPrr#rMrrr(test_invalid_callable_object_return_types z:FakeLaunchpadTest.test_invalid_callable_object_return_typecs@tddtfddd|j_|jjd|djdS)z Sample collections can be set on L{FakeLaunchpad} instances. They are validated the same way other sample data is validated. r,r-crr rr-branchrrr r!z.getByUniqueNameN)r$rrrtr(r.rMrrqrtest_collection_propertys z*FakeLaunchpadTest.test_collection_propertycCs`tddd}t|gd|j_t|jj}|dt||d}|d|j|d|jdS)z Data for a sample collection set on a L{FakeLaunchpad} instance can be iterated over if an C{entries} key is defined. r2r3r4r6rN)r$rr8r9r(lenr'r5)rr;r8rrrtest_iterate_collections  z)FakeLaunchpadTest.test_iterate_collectionc Cs*tdd}|tt|jdt|gddS)z Sample data for each entry in a collection is validated when it's set on a L{FakeLaunchpad} instance. rOrfr8r6N)r$rPrrQrr:rrr$test_collection_with_invalid_entriess  z6FakeLaunchpadTest.test_collection_with_invalid_entriescCstddd}tddd}tddd}t|||gd|j_|jjd d }|d t||d|d j|d|d jd S)z Data for a sample collection set on a L{FakeLaunchpad} instance can be sliced if an C{entries} key is defined. r2r3r42Bug #23zBug #3r6rvrN)r$rr8r(rwr')rbug1bug2bug3r8rrrtest_slice_collections   z'FakeLaunchpadTest.test_slice_collectioncVtddd}tddd}t||gdj_tfddtfd dd S) z A C{ValueError} is raised if a negative start value is used when slicing a sample collection set on a L{FakeLaunchpad} instance. r2r3r4rzr{r6csjjddSNrr8rrMrrr 4zMFakeLaunchpadTest.test_slice_collection_with_negative_start..cjjddS)Nrr~rrrMrrr 5rNr$rr8rP ValueErrorrrrrrMr)test_slice_collection_with_negative_start,  z;FakeLaunchpadTest.test_slice_collection_with_negative_startcr) z A C{ValueError} is raised if a negative stop value is used when slicing a sample collection set on a L{FakeLaunchpad} instance. r2r3r4rzr{r6csjjddSrrrrMrrr ?rzLFakeLaunchpadTest.test_slice_collection_with_negative_stop..cr)NrrrrrMrrr @rNrrrrMr(test_slice_collection_with_negative_stop7rz:FakeLaunchpadTest.test_slice_collection_with_negative_stopcs4tddd}t|gdj_tfdddS)z An C{IndexError} is raised if an invalid index is used when retrieving data from a sample collection. r2r3r4r6cs jjdS)Nr~rrrMrrr Is zHFakeLaunchpadTest.test_subscript_operator_out_of_range..N)r$rr8rP IndexError)rrrrMr$test_subscript_operator_out_of_rangeBs z6FakeLaunchpadTest.test_subscript_operator_out_of_rangecCsNtdd|j_|jj}|d|jd|_|d|j|d|jjjdS)z.rscrr rr-)branch2rrr Yr!N)r$rrrtr(r)rrrr)rrrtest_replace_methodTs  z%FakeLaunchpadTest.test_replace_methodcCs,tdd|j_|jj}|tt|dddS)z2Values set on fake resource objects are validated.r,r-r.rvN)r$rr%rPrrQr/rrr(test_replace_property_with_invalid_value]sz:FakeLaunchpadTest.test_replace_property_with_invalid_valuecCsDtdd|j_|d|jjjtdd|j_|d|jjjdS)z:Resources already set on L{FakeLaunchpad} can be replaced.r,r-rONrYrMrrrtest_replace_resourcecsz'FakeLaunchpadTest.test_replace_resourcecCs`tdd|j_|jj}d|_|d|j|d|j|d|jjj|d|jjjdS)z?Sample data set on a L{FakeLaunchpad} instance can be added to.r,r-rSN)r$rr%rTr(r.r/rrrtest_add_propertyjsz#FakeLaunchpadTest.test_add_propertycCs>t|j_|tt|jjdd|jj_|d|jjjdS)z6An empty object can be used when creating sample data.r.r,N)r$rr%rPrUrVr.r(rMrrr!test_add_property_to_empty_objectts  z3FakeLaunchpadTest.test_add_property_to_empty_objectcCs"tddd}|t|tdS)z L{FakeLaunchpad.login} ignores all parameters and returns a new instance using the builtin WADL definition. r.tokensecretN)rloginr r rrrrr test_login{szFakeLaunchpadTest.test_logincCtd}|t|tdS)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_loginr r rrrrtest_get_token_and_login z*FakeLaunchpadTest.test_get_token_and_logincCr)z L{FakeLaunchpad.login_with} ignores all parameters and returns a new instance using the builtin WADL definition. r.N)r login_withr r rrrrtest_login_withrz!FakeLaunchpadTest.test_login_withcCs$tdd|j_||jjdS)zU Sample object have an C{lp_save} method that is a no-op by default. r,r-N)r$rr%r lp_saverMrrr test_lp_saveszFakeLaunchpadTest.test_lp_savecCs,tdddd|j_|d|jjdS)z;A custom C{lp_save} method can be set on a L{FakeResource}.r,cSdSNcustomrrrrrr r!z7FakeLaunchpadTest.test_custom_lp_save..)r.rrN)r$rr%r(rrMrrrtest_custom_lp_savesz%FakeLaunchpadTest.test_custom_lp_savecCs4tdd|j_dd|jj_|d|jjdS)zl A custom C{lp_save} method can be set on a L{FakeResource} after its been created. r,r-cSrrrrrrrr r!z;FakeLaunchpadTest.test_set_custom_lp_save..rN)r$rr%rr(rMrrrtest_set_custom_lp_savesz)FakeLaunchpadTest.test_set_custom_lp_saveN))rrrrr=rCrJrKrNrRrWrZr\rardrergrirkrlrnrprurxryrrrrrrrrrrrrrrrrrrrrr>PsL                     r>N)r testresourcesrlaunchpadlib.testing.launchpadrrrrlaunchpadlib.testing.resourcesrr r rr>rrrrs  '