一个虚伪的客户。单元测试之类的。

fakespotip的Python项目详细描述


假药

一个假的spotipy客户。单元测试之类的。

安装

pip install fakespotipy

用法

# Initialize the client>>>fromfakespotipyimportFakeSpotify>>>client=FakeSpotify()# 1. Example of a mock object response# First, set up a mock response>>>response={...'expires_in':60,...'access_token':'BQDdKdI1eLRl2ErhCRC0jHdfr_DYEm_ecUuUPq2-dW_txQZeCrA32lNSYOZO7v7rEPXqC846nHlgSeg4m0c3-y05W9ISJRluCXdco4igf8eMhgLojXZb4RbE0vmlH4a06T3TX7Jg-uN1ClYFEkXnCGCA0NBNqkiFYDKlvMWqZExQom-XF-8pr6gV_PpzNJ2eKRRR6_ORp1ABUhtJ_aD8f5W4GexLq1mzpWQLkKE_Fq_LuwE1JhpxxNxRI-FLtzz46Jc',...'token_type':'Bearer',...'refresh_token':'AQDDNE-U4IElufFWfNjlwy7rOn-Kyt2PeIN1Nze2I5rVi7c9Etcx9blVkHVe5liSoKRMbJzS3etlA3sQ-0UqMKxRJ-HN08jrO_1IoDgciSZOaAUaQUiSkBOgtgnmO_tEHCU',...'scope':'user-top-read',...}# Prep the client with that response>>>client.add_response('refresh_access_token',response)# And trigger it>>>client.refresh_access_token('refresh_token_str_here'){'access_token':'BQDdKdI1eLRl2ErhCRC0jHdfr_DYEm_ecUuUPq2-dW_txQZeCrA32lNSYOZO7v7rEPXqC846nHlgSeg4m0c3-y05W9ISJRluCXdco4igf8eMhgLojXZb4RbE0vmlH4a06T3TX7Jg-uN1ClYFEkXnCGCA0NBNqkiFYDKlvMWqZExQom-XF-8pr6gV_PpzNJ2eKRRR6_ORp1ABUhtJ_aD8f5W4GexLq1mzpWQLkKE_Fq_LuwE1JhpxxNxRI-FLtzz46Jc','token_type':'Bearer','expires_in':60,'refresh_token':'AQDDNE-U4IElufFWfNjlwy7rOn-Kyt2PeIN1Nze2I5rVi7c9Etcx9blVkHVe5liSoKRMbJzS3etlA3sQ-0UqMKxRJ-HN08jrO_1IoDgciSZOaAUaQUiSkBOgtgnmO_tEHCU','scope':'user-top-read'}# If we try again, we get a NotImplementedError>>>client.refresh_access_token('refresh_token_str_here')Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"fakespotipy.py",line37,inmethodraiseNotImplementedErrorNotImplementedError# 2. Example of a mock function response# First set up the mock function>>>defrefresh_response(refresh_token_str):...print"i'm refreshing!"...ifrefresh_token_str=='foo':...raiseException("Foo! Oh noes!")...return{'foo':'bar'}...# Add it a couple of times (so we can call it twice)>>>client.add_response('refresh_access_token',refresh_response)>>>client.add_response('refresh_access_token',refresh_response)# Trigger it>>>client.refresh_access_token('refresh_token_str_here')i'm refreshing!{'foo':'bar'}# Trigger again, using anticipated input to trigger custom Exception>>>client.refresh_access_token('foo')i'm refreshing!Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"fakespotipy.py",line40,inmethodreturnresponse(*args,**kwargs)File"<stdin>",line4,inrefresh_responseException:Foo!Ohnoes!# Try one more time, get NotImplementedError>>>client.refresh_access_token('foo')Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"fakespotipy.py",line37,inmethodraiseNotImplementedErrorNotImplementedError

测试

python setup.py test

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android使用两个后台服务错误   解压缩HTTPInputStream时,java GZIPInputStream过早关闭   javax和javax的区别是什么。网ssl。密钥库和服务器。ssl。为SpringBoot应用程序指定密钥库时的密钥库属性   java生成两个JPanel,而我只需要一个   java深度链接从play store安装应用程序时获取数据   java 安卓应用程序在退出时未正确释放蓝牙   java正确使用setCellValueFactory   java开放JdbcTemplate连接处于只读模式?   使用Spring MVC创建服务时发生java错误   JavaFX获取安装在计算机中的特定应用程序的版本   SecureRandom的安全问题:PRNG在java 1.5中不一致   windows我可以创建一个独立的。带Inno设置的Java应用程序的exe安装程序?   如何使用JavaServlet下载csv文件?   java从生成的缓冲图像中添加图像作为jasper中的数据记录?   java日期和时间解析