+
    TŎi;                        R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI	H
t
 ^RIHt ^RIHt ^RIHt ^RIHt ^RIHt ^ R	IHtHtHtHtHtHt ^ R
IHt  ! R R]P4                  4      t ! R R]P4                  4      t ! R R]P4                  4      t ! R R]P4                  4      t ! R R]P4                  4      t ! R R]P4                  4      t  ! R R]P4                  4      t! ! R R]P4                  4      t" ! R R]P4                  4      t# ! R R]P4                  4      t$ ! R R ]P4                  4      t%]&R!8X  d   ]PN                  ! 4        R# R# )"zi
Unit tests for the Python Facebook Business SDK.

How to run:
    python -m facebook_business.test.unit
N)urllib)version_info)api)specs)
exceptions)session)utils)abstractcrudobjectad	adaccount
adcreativecustomaudienceproductcatalog)versionc                   >   a  ] tR t^2t o R tR tR tR tR tRt	V t
R# )CustomAudienceTestCasec                .   \         P                  P                  \         P                  P                  P                  . RO4      pRpVR,          R,          pV^ ,          V8X  g   Q hV^,          V^ ,          8X  g   Q hV^,          V^,          8X  g   Q hR# )  test  @9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08payloaddataN)r   test..test..)r   CustomAudienceformat_paramsSchema
email_hash)selfr   	test_hashuserss   &   j/Users/ahmad/.openclaw/workspace/scripts/.venv/lib/python3.14/site-packages/facebook_business/test/unit.pytest_format_params)CustomAudienceTestCase.test_format_params4   s     //==))00;;,
 O 		"6*Qx9$$$Qx58###Qx58###    c                L    R  pV P                  \        P                  V4       R# )c                      \         P                  P                  \         P                  P                  P                  R .4       R# )123123N)r   r   r   r   uid r#   r    uid_payloadECustomAudienceTestCase.test_fail_when_no_app_ids.<locals>.uid_payloadB   s0    ))77--4488
r#   N)assertRaisesr   FacebookBadObjectError)r   r)   s   & r    test_fail_when_no_app_ids0CustomAudienceTestCase.test_fail_when_no_app_idsA   s#    	
 	--	
r#   c                :   R p\         P                  ! VP                  R4      4      P                  4       p\        P
                  P                  \        P
                  P                  P                  V.RR7      pVR,          R,          pV^ ,          V8X  g   Q hR# )r   utf8T)
pre_hashedr   r   N)	hashlibsha256encode	hexdigestr   r   r   r   r   )r   userr   r   r   s   &    r    test_format_params_pre_hashed4CustomAudienceTestCase.test_format_params_pre_hashedL   s    ^^DKK$78BBD	 //==))00;;K > 
 	"6*Qx9$$$r#   c                   \         P                  P                  P                  P                  \         P                  P                  P                  P
                  \         P                  P                  P                  P                  \         P                  P                  P                  P                  .p\         P                  P                  V. RO.RR7      p. ROpVR,          R,          pV^ ,          V8X  g   Q hR# )	abc123defTis_rawr   r   N)r:   z  TEST r   r   )r:   r   r   r   )	r   r   r   MultiKeySchema	extern_idfnemaillnr   )r   schemar   
test_hash1r   s   &    r    test_multi_key_params,CustomAudienceTestCase.test_multi_key_paramsY   s    ))00??II))00??BB))00??EE))00??BB	
 !//==@A > 


 	"6*Qx:%%%r#   c                    \         P                  P                  P                  P                  .p\         P                  P                  VR .R.R.R..RR7      pR .R.R.R..pVR,          R,          pWC8X  g   Q hR# )	r:   	abc234def	abc345def	abc456defTr;   r   r   N)r   r   r   r=   r>   r   )r   rB   r   expectedactuals   &    r    test_extern_id_key_single0CustomAudienceTestCase.test_extern_id_key_singleq   s     ))00??II
 !//==}{mk]  > 
 MK=;-+ #F+!!!r#   r(   N)__name__
__module____qualname____firstlineno__r!   r-   r7   rD   rL   __static_attributes____classdictcell____classdict__s   @r    r   r   2   s#     $	
%&0" "r#   r   c                   >   a  ] tR t^t o R tR tR tR tR tRt	V t
R# )EdgeIteratorTestCasec                    RRR/RR/./p\         P                  ! \        P                  ! RR7      \        P
                  4      pVP                  V4      p\        V4      ^8X  g   Q hR# )z
Sometimes the response returns an array inside the data
key. This asserts that we successfully build objects using
the objects in that array.
r   id60195796018402123fbidNr   Cursorr   	AdAccountr
   Adbuild_objects_from_responselen)r   responseeiobjss   &   r    test_builds_from_array+EdgeIteratorTestCase.test_builds_from_array   sp     i i
 ZZU+EE
 --h74yA~~r#   c                   RRRRRRR./RRRR	././p\         P                  ! \        P                  ! R
R7      \        P
                  4      pVP                  V4      p\        V4      ^8X  d   V^ ,          R,          R8X  g   Q hR# )z
Sometimes the response returns a single JSON object. This asserts
that we're not looking for the data key and that we correctly build
the object without relying on the data key.
rY   z601957/targetingsentencelinestargetingsentencelinescontentzLocation - Living In:childrenzUnited StateszAge:z18 - 65+r\   r]   Nr_   r   re   rf   objs   &   r    test_builds_from_object,EdgeIteratorTestCase.test_builds_from_object   s     1$2#( 6
'
 ZZU+EE
 ,,X63x1}Q1P!PPP!Pr#   c                    \         P                  ! \        P                  ! R R7      \        P
                  4      pV P                  \        P                  VP                  4       R# r\   r]   N)
r   r`   r   ra   r
   rb   r+   r   $FacebookUnavailablePropertyExceptiontotalr   rf   s   & r    test_total_is_none'EdgeIteratorTestCase.test_total_is_none   sE    ZZU+EE
 	;;RXX	Gr#   c                    \         P                  ! \        P                  ! R R7      \        P
                  4      p^ Vn        V P                  VP                  4       ^ 4       R# rs   )	r   r`   r   ra   r
   rb   _total_countassertEqualru   rv   s   & r    test_total_is_defined*EdgeIteratorTestCase.test_total_is_defined   sD    ZZU+EE
 R(r#   c                    RRRRRRR//p\         P                  ! \        P                  ! R4      \        P
                  4      pVP                  V4      p\        V4      ^8X  d   V^ ,          R,          R8X  g   Q hR	# )
z
Sometimes the response returns a single JSON object - with a "data".
For instance with adcreative. This asserts that we successfully
build the object that is in "data" key.
r   namez	test namestatusACTIVE
account_idact_345r\   N)r   r`   r
   rb   r   
AdCreativerc   rd   rn   s   &   r    %test_builds_from_object_with_data_key:EdgeIteratorTestCase.test_builds_from_object_with_data_key   s|     (i
 ZZEE%L!!
 ,,X63x1}Q!5!BBB!Br#   r(   N)rN   rO   rP   rQ   rh   rp   rw   r|   r   rR   rS   rT   s   @r    rW   rW      s'     (Q6G)C Cr#   rW   c                   2   a  ] tR t^t o R tR tR tRtV tR# )AbstractCrudObjectTestCasec                >   \         P                  \        P                  \        P
                  \        P                  \        P                  3 Fz  p\        P                  ! V4      '       g   K!  \        V\        P                  4      '       g   KC  V\        P                  8w  g   KZ   VP                  P                   pVR 8w  g   Q hK|  	  R#   \"         dD   pT P%                  R\'        T4      ,           R,           \'        T4      ,           4        Rp?K  Rp?ii ; i) zCould not instantiate z
  N)r
   rb   r   ra   r   r   r   r   r   ProductCataloginspectisclass
issubclassr	   AbstractCrudObjectFieldrY   	Exceptionfailstr)r   ro   id_fieldes   &   r    test_all_aco_has_id_field4AbstractCrudObjectTestCase.test_all_aco_has_id_field   s    EE''))"11"11	3C $$3 2 E EFF)<<<U"yy||H#r>)>3 ! UII6SAFJSQRVSTTUs   )CD8DDc                    \         P                  ! 4       pR VR&   \        VP                  4      ^ 8  g   Q hVR \        VP                  4      ^ 8X  g   Q hR# )foor   N)r   ra   rd   _changes)r   accounts   & r    test_delitem_changes_history7AbstractCrudObjectTestCase.test_delitem_changes_history   sR    %%'7##$q(((FO7##$)))r#   c                |    ! R R\         P                  4      p ! R R\         P                  4      pVR/ RR/3VRRR	/RR	RR/3VR
./ RR
/3VR
.RR	/RR	RR
/3V. / / 3V. RR	/RR	/3VR/ / 3VRRR	/RR	/3VR
./ RR
/3VR
.RR	/RR	RR
/3V. / / 3V. RR	/RR	/33 F  w  r4rVVP                  WE4       WV8X  d   K  Q h	  R# )z}
Demonstrates that AbstractCrudObject._assign_fields_to_params()
handles various combinations of params and fields properly.
c                       ] tR t^tRR.tRtR# )=AbstractCrudObjectTestCase.test_fields_to_params.<locals>.FoorY   r   r(   NrN   rO   rP   rQ   _default_read_fieldsrR   r(   r#   r    Foor      s    $(&> r#   r   c                       ] tR t^t. tRtR# )=AbstractCrudObjectTestCase.test_fields_to_params.<locals>.Barr(   Nr   r(   r#   r    Barr      s    #% r#   r   Nfieldszid,nameabx)r	   r   _assign_fields_to_params)r   r   r   adclassr   paramsrJ   s   &      r    test_fields_to_params0AbstractCrudObjectTestCase.test_fields_to_params   s;   
	2$77 	2	&$77 	& $Xy12$c
S#x$CD3%h_-3%#sc3#%>?"b""sCj3*-$B$c
S#J/3%h_-3%#sc3#%>?"b""sCj3*-2
-GV ,,V<%%%2
r#   r(   N)	rN   rO   rP   rQ   r   r   r   rR   rS   rT   s   @r    r   r      s     U$*& &r#   r   c                   D   a  ] tR tRt o R tR tR tR tR tR t	Rt
V tR	# )
AbstractObjectTestCasei  c                    \         P                  ! 4       p/ pR VR &   RVR&   W!R&   RR R RR//pVP                  4       V8X  g   Q hR# )rY   r   r   fromN)r   PagePostDataexport_data)r   ro   obj2rJ   s   &   r    test_export_nested_object0AbstractObjectTestCase.test_export_nested_object  s^      "T
VFd
  H,,,r#   c                x    \         P                  ! 4       pR ^/VR &   R R ^//pVP                  4       V8X  g   Q hR# )	link_dataNr   ObjectStorySpecr   r   ro   rJ   s   &  r    test_export_dict'AbstractObjectTestCase.test_export_dict!  sN    ##%
K Q

  H,,,r#   c                l    \         P                  ! 4       pR VR&   / pVP                  4       V8X  g   Q hR # )Nr   r   r   s   &  r    test_export_none'AbstractObjectTestCase.test_export_none-  s4    ##%K H,,,r#   c                   \         P                  ! 4       p\        P                  ! 4       p\        P                  ! 4       pR VR&   V.VR&   W!R&    \
        P                  ! VP                  4       4       R#    T P                  R4        R# ; i)z$100descriptionchild_attachmentsr   zObjects in crud object exportN)	r   r   r   LinkDataAttachmentDatajsondumpsr   r   )r   ro   r   obj3s   &   r    test_export_list'AbstractObjectTestCase.test_export_list3  su    ##%~~##%$]%)F !K	7JJs()	7II56s   $A6 6Bc                    \         P                  ! 4       p\         P                  ! 4       pR VR&   W!R&    \        P                  ! VP                  4       4       R#    T P                  R4        R# ; i)r   r   
video_datazObjects in object exportN)r   r   	VideoDatar   r   r   r   )r   ro   r   s   &  r    test_export_no_objects-AbstractObjectTestCase.test_export_no_objects@  sZ    ##% #] L	2JJs()	2II01s   $A A1c                    \         P                  ! 4       p/ pRVR&   RVR&   W!R&    VP                  4        R#   \         d$   pT P	                  RT,          4        Rp?R# Rp?ii ; i)zAMust be able to print nested objects without serialization issuesrY   r   r   r   z*Cannot call __repr__ on AbstractObject
 %sN)r   r   __repr__	TypeErrorr   )r   ro   r   r   s   &   r    test_can_print%AbstractObjectTestCase.test_can_printK  sd      "T
VF	ILLN 	IIICaGHH	Is   9 A'A""A'r(   N)rN   rO   rP   rQ   r   r   r   r   r   r   rR   rS   rT   s   @r    r   r     s*     -
--7	2I Ir#   r   c                   ,   a  ] tR tRt o R tR tRtV tR# )SessionTestCaseiY  c                ,   ^ RI p^ RIp\        R8  dA   VP                  \	        V4      \	        V4      VP
                  R7      pVP                  4       # VP                  \	        VR4      \	        VR4      VP
                  R7      pVP                  4       # )    N)msg	digestmodutf-8)   r   )r2   hmacr   newbytesr3   r5   )r   access_token
app_secretr2   r   hs   &&&   r    gen_appsecret_proof#SessionTestCase.gen_appsecret_proof[  s    & j!,'!..  A {{} j'*,0!..  A
 {{}r#   c                    R pRpRp\         P                  ! WV4      pV P                  VP                  V P	                  W24      4       R# ) reikgukrhgfgtcheghjteirdldlrkjbu gdrtejfdghurnhnjghjnertihbknlrvv bekguvjhdvdburldfnrfdguljijenklcN)r   FacebookSessionr{   appsecret_proofr   )r   app_idr   r   
fb_sessions   &    r    test_appsecret_proof$SessionTestCase.test_appsecret_proofm  sH    37
9,,VN
&&$$\>	
r#   r(   N)rN   rO   rP   rQ   r   r   rR   rS   rT   s   @r    r   r   Y  s     $	
 	
r#   r   c                   &   a  ] tR tRt o R tRtV tR# )ProductCatalogTestCaseiy  c                x    R pRp\         P                  ! 4       pV P                  W#P                  V4      4       R# )ID_1zSURfMQ==N)r   r   r{   b64_encoded_id)r   
product_idb64_id_as_strcatalogs   &   r    test_b64_encode_is_correct1ProductCatalogTestCase.test_b64_encode_is_correctz  s3    
" //1(>(>z(JKr#   r(   N)rN   rO   rP   rQ   r   rR   rS   rT   s   @r    r   r   y  s     L Lr#   r   c                   &   a  ] tR tRt o R tRtV tR# )SessionWithoutAppSecretTestCasei  c                     \         P                  ! R R7       R#   \         d-   pT P                  R\	        T4      ,           4        Rp?R# Rp?ii ; i)thisisfakeaccesstoken)r   NzCould not instantiate 
  )r   r   r   r   r   )r   r   s   & r    test_appsecret_proof_absence<SessionWithoutAppSecretTestCase.test_appsecret_proof_absence  sF    	B##4  	BII7#a&@AA	Bs    A!AAr(   N)rN   rO   rP   rQ   r   rR   rS   rT   s   @r    r   r     s     B Br#   r   c                   8   a  ] tR tRt o R tR tR tR tRtV t	R# )UrlsUtilsTestCasei  c                   R pV P                  \        P                  P                  V4      \        P
                  P                  V4      4       \        P                  '       d`   RP                  R4      pV P                  \        P                  P                  V4      \        P
                  P                  V4      4       R# R# )zsome string   some string with ùnicoder   N)
r{   r   urlsquote_with_encodingr   parsequotesixPY2r4   r   ss   & r    #test_quote_with_encoding_basestring5UrlsUtilsTestCase.test_quote_with_encoding_basestring  s    JJ**1-LLq!	

 777,33G<A

..q1""1% r#   c                    R pV P                  \        P                  P                  V4      \        P
                  P                  VP                  R4      4      4       R# )r  r   N)r{   r   r  r  r   r  r  r4   r  s   & r     test_quote_with_encoding_unicode2UrlsUtilsTestCase.test_quote_with_encoding_unicode  sB    (JJ**1-LLqxx01	
r#   c                    R pV P                  \        P                  P                  V4      \        P
                  P                  R4      4       R# )i  1234N)r{   r   r  r  r   r  r  r  s   & r     test_quote_with_encoding_integer2UrlsUtilsTestCase.test_quote_with_encoding_integer  s9    JJ**1-LLv&	
r#   c                l    ^^.pV P                  \        \        P                  P                  V4       R# )   N)r+   
ValueErrorr   r  r  r  s   & r    6test_quote_with_encoding_other_than_string_and_integerHUrlsUtilsTestCase.test_quote_with_encoding_other_than_string_and_integer  s+    FJJ**A	
r#   r(   N)
rN   rO   rP   rQ   r  r  r  r  rR   rS   rT   s   @r    r  r    s     


 
r#   r  c                   &   a  ] tR tRt o R tRtV tR# )FacebookAdsApiBatchTestCasei  c           
     f   \         P                  P                  4       p\         P                  ! V4      pVP	                  R RRR/R7       V P                  \        V4      ^4       V P                  VP                  ^ ,          RR RR\        P                  P                  R4      ,           /4       R# )	GETz	some/pathkeyu   vàlué)r   methodrelative_urlNzsome/path?key=)r   FacebookAdsApiget_default_apiFacebookAdsApiBatchaddr{   rd   _batchr   r  r  )r   default_api	batch_apis   &  r    test_add_works_with_utf84FacebookAdsApiBatchTestCase.test_add_works_with_utf8  s    ((88:++K8	e[%1DEY+))!,e/%**2P2PQ[2\\/
 	r#   r(   N)rN   rO   rP   rQ   r)  rR   rS   rT   s   @r    r  r    s      r#   r  c                   &   a  ] tR tRt o R tRtV tR# )VersionUtilsTestCasei  c                    \         P                  P                  4       p\        P                  ! R V4      '       g   Q hR# )z[0-9]+\.[0-9]+\.[0-9]N)r   r   get_versionresearch)r   version_values   & r    test_api_version_is_pulled/VersionUtilsTestCase.test_api_version_is_pulled  s,    113yy0-@@@@r#   r(   N)rN   rO   rP   rQ   r2  rR   rS   rT   s   @r    r,  r,    s     A Ar#   r,  c                   ,   a  ] tR tRt o R tR tRtV tR# )FacebookResponseTestCasei  c                r    \         P                  ! ^R7      pV P                  VP                  4       4       R# )   )http_statusN)r   FacebookResponse
assertTrue
is_successr   resps   & r    test_is_success_200,FacebookResponseTestCase.test_is_success_200  s%    ##4)*r#   c                t    \         P                  ! R ^R7      pV P                  VP                  4       4       R# )zService Unavailable)bodyr8  N)r   r9  assertFalser;  r<  s   & r    #test_is_success_service_unavailable<FacebookResponseTestCase.test_is_success_service_unavailable  s*    ##)>CP*+r#   r(   N)rN   rO   rP   rQ   r>  rC  rR   rS   rT   s   @r    r5  r5    s     +, ,r#   r5  __main__)(__doc__unittestr   r   r	  r/  r2   	six.movesr   sysr   r   r   r   r   r   r   facebook_business.adobjectsr	   r
   r   r   r   r   facebook_business.utilsr   TestCaser   rW   r   r   r   r   r   r  r  r,  r5  rN   mainr(   r#   r    <module>rN     s6  *    
 	        3 3 ,Q"X.. Q"hSC8,, SCj4&!2!2 4&nDIX.. DIN
h'' 
@LX.. LBh&7&7 B#
)) #
L
("3"3 
A8,, A,x00 , zMMO r#   