How to use _content method in locust

Best Python code snippet using locust

Article.py

Source:Article.py Github

copy

Full Screen

12__all__ = (3 'Article',4)56from . import bili78class Article(object):9 "B站专栏类,用于发表B站专栏"10 createArticle = bili.createArticle11 deleteArticle = bili.deleteArticle12 getArticle = bili.getArticle13 articleUpcover = bili.articleUpcover14 articleCreateVote = bili.articleCreateVote15 articleCardsBvid = bili.articleCardsBvid16 articleCardsCvid = bili.articleCardsCvid17 articleMangas = bili.articleMangas1819 #本类只继承bili中与Article有关的方法20 class Content(object):21 "文本类用来处理B站奇葩的专栏提交格式"22 def __init__(self):23 self._content = ""24 def add(self, text):25 "添加内容"26 self._content = f'{self._content}{text}'27 return self28 def startH(self):29 "开始一个标题"30 self._content = f'{self._content}<h1>'31 return self32 def endH(self):33 "结束一个标题"34 self._content = f'{self._content}</h1>'35 return self36 def startP(self, align=""):37 "开始一段正文"38 if align == "":39 self._content = f'{self._content}<p>'40 elif align == "left":41 self._content = f'{self._content}<p style="text-align: left;">'42 elif align == "center":43 self._content = f'{self._content}<p style="text-align: center;">'44 elif align == "right":45 self._content = f'{self._content}<p style="text-align: right;">'46 else:47 self._content = f'{self._content}<p>'48 return self49 def endP(self):50 "结束一段正文"51 self._content = f'{self._content}</p>'52 return self53 def startD(self):54 "开始一段带删除线的文字"55 self._content = f'{self._content}<span style="text-decoration: line-through;">'56 return self57 def endD(self):58 "结束一段带删除线的文字"59 self._content = f'{self._content}</span>'60 return self61 def startS(self, size=16):62 "开始一段大小为size的文字"63 self._content = f'{self._content}<span class="font-size-{size}">'64 return self65 def endS(self):66 "结束一段特定大小的文字"67 self._content = f'{self._content}</span>'68 return self69 def startB(self):70 "开始一段加粗的文字"71 self._content = f'{self._content}<strong>'72 return self73 def endB(self):74 "结束一段加粗的文字"75 self._content = f'{self._content}</strong>'76 return self77 def startY(self):78 "开始一段引用"79 self._content = f'{self._content}<blockquote>'80 return self81 def endY(self):82 "结束一段引用"83 self._content = f'{self._content}</blockquote>'84 return self85 def br(self):86 "插入换行,不用结束,一般新段默认换行"87 self._content = f'{self._content}<p><br/></p>'88 return self89 def line(self,type=0):90 "插入一段分割线,不用结束"91 ll = ('<figure class="img-box" contenteditable="false"><img src="//i0.hdslb.com/bfs/article/0117cbba35e51b0bce5f8c2f6a838e8a087e8ee7.png" class="cut-off-1"/></figure>',92 '<figure class="img-box" contenteditable="false"><img src="//i0.hdslb.com/bfs/article/4aa545dccf7de8d4a93c2b2b8e3265ac0a26d216.png" class="cut-off-2"/></figure>',93 '<figure class="img-box" contenteditable="false"><img src="//i0.hdslb.com/bfs/article/71bf2cd56882a2e97f8b3477c9256f8b09f361d3.png" class="cut-off-3"/></figure>',94 '<figure class="img-box" contenteditable="false"><img src="//i0.hdslb.com/bfs/article/db75225feabec8d8b64ee7d3c7165cd639554cbc.png" class="cut-off-4"/></figure>',95 '<figure class="img-box" contenteditable="false"><img src="//i0.hdslb.com/bfs/article/4adb9255ada5b97061e610b682b8636764fe50ed.png" class="cut-off-5"/></figure>',96 '<figure class="img-box" contenteditable="false"><img src="//i0.hdslb.com/bfs/article/02db465212d3c374a43c60fa2625cc1caeaab796.png" class="cut-off-6"/></figure>')97 self._content = f'{self._content}{ll[type]}'98 return self99 def startU(self):100 "开始一段无序列表"101 self._content = f'{self._content}<ul class=" list-paddingleft-2">'102 return self103 def endU(self):104 "结束一段无序列表"105 self._content = f'{self._content}</ul>'106 return self107 def startO(self):108 "开始一段有序列表"109 self._content = f'{self._content}<ol class=" list-paddingleft-2">'110 return self111 def endO(self):112 "结束一段有序列表"113 self._content = f'{self._content}</ol>'114 return self115 def startL(self):116 "开始列表中的一列"117 self._content = f'{self._content}<li>'118 return self119 def endL(self):120 "结束列表中的一列"121 self._content = f'{self._content}</li>'122 return self123 def startA(self, url=""):124 "插入站内链接,链接说明文字请用add方法添加"125 self._content = f'{self._content}<a href="{url}">'126 return self127 def endA(self):128 "结束插入站内链接"129 self._content = f'{self._content}</a>'130 return self131 def picUrl(self, url="", text="", width="", height=""):132 "插入站内图片链接,添加图片说明,指定图片长宽,比如15px,25%"133 self._content = f'{self._content}<figure contenteditable="false" class="img-box"><img src="{url}" '134 if width:135 self._content = f'{self._content}width="{width}" '136 if height:137 self._content = f'{self._content}height="{height}" '138 self._content = f'{self._content}/><figcaption class="caption" contenteditable="">{text}</figcaption></figure>'139 return self140 def picFile(self, article: "Article类的实例", file: "本地图片文件或图片Bytes", text="", width="", height=""):141 "插入本地图片文件或Bytes,添加图片说明,指定图片长宽,比如15px,25%"142 ret = article.articleUpcover(file)143 picurl = ret["data"]["url"]144 picurl = picurl.replace("http", "https")145 return self.picUrl(picurl, text, width, height)146 def vote(self, article: "Article类的实例", vote: "vote投票结构体字典"):147 "插入站内投票"148 id = article.articleCreateVote(vote)["data"]["vote_id"]149 self._content = f'{self._content}<figure class="img-box" contenteditable="false"><img src="//i0.hdslb.com/bfs/article/a9fb8e570e9683912de228446e606745cce62aa6.png" class="vote-display" data-vote-id="{id}"/><figcaption class="vote-title web-vote" contenteditable="">{vote["title"]}</figcaption></figure>'150 return self151 def card(self, Article: "Article类的实例", id: "根据type类型填写id", type: "video:视频标签 str,article:专栏标签,fanju:番剧标签,music:音乐标签,shop:会员购标签,caricature:漫画标签 int,live:直播标签 str"):152 "插入引用标签"153 def video():154 ret = Article.articleCardsBvid(id)155 picurl = ret["data"][id]["pic"]156 picurl = picurl.replace("http", "https")157 aid = ret["data"][id]["aid"]158 return f'<figure class="img-box" contenteditable="false"><img src="{picurl}" aid="{aid}" class="video-card nomal" type="nomal"/></figure>'159 def article():160 ret = Article.articleCardsCvid(id)161 picurl = ret["data"]["banner_url"]162 picurl = picurl.replace("http", "https")163 aid = ret["data"]["id"]164 return f'<figure class="img-box" contenteditable="false"><img src="{picurl}" aid="{aid}" class="article-card" type="normal"/></figure>'165 def fanju():166 ret = Article.articleCardsCvid(id)167 picurl = ret["data"]["cover"]168 picurl = picurl.replace("http", "https")169 return f'<figure class="img-box" contenteditable="false"><img src="{picurl}" aid="{id}" class="fanju-card" type="normal"/></figure>'170 def music():171 ret = Article.articleCardsCvid(id)172 picurl = ret["data"]["cover_url"]173 picurl = picurl.replace("http", "https")174 return f'<figure class="img-box" contenteditable="false"><img src="{picurl}" aid="{id}" class="music-card" type="normal"/></figure>'175 def shop():176 ret = Article.articleCardsCvid(id)177 picurl = ret["data"]["performance_image"]178 picurl = picurl.replace("http", "https")179 return f'<figure class="img-box" contenteditable="false"><img src="{picurl}" aid="{id}" class="shop-card" type="normal"/></figure>'180 def caricature():181 ret = Article.articleMangas(id)182 picurl = ret["data"][id]["vertical_cover"]183 picurl = picurl.replace("http", "https")184 return f'<figure class="img-box" contenteditable="false"><img src="{picurl}" aid="{id}" class="caricature-card nomal" type="nomal"/></figure>'185 def live():186 ret = Article.articleCardsCvid(id)187 picurl = ret["data"]["cover"]188 picurl = picurl.replace("http", "https")189 aid = ret["data"]["room_id"]190 return f'<figure class="img-box" contenteditable="false"><img src="{picurl}" aid="{aid}" class="live-card" type="normal"/></figure>'191192 index = {193 "video": video,194 "article": article,195 "fanju": fanju,196 "music": music,197 "shop": shop,198 "caricature": caricature,199 "live": live,200 }201 if type in index:202 self._content = f'{self._content}{index[type]()}'203 return self204 def output(self):205 "输出,用于Article类提交content"206 return self._content207208 def __init__(self, cookieData, tilte="", content="", aid=0, category=0, list_id=0, tid=4, original=1, image_urls="", origin_image_urls=""):209 "创建一个B站专栏草稿"210 bili.__init__(self)211 bili.login_by_cookie(self, cookieData)212 self._tilte = tilte213 self._content = content214 self._category = category215 self._list_id = list_id216 self._tid = tid217 self._original = original218 self._image_urls = image_urls219 self._origin_image_urls = origin_image_urls220 if(aid == 0):221 ret = self.createArticle(tilte, content, aid, category, list_id, tid, original, image_urls, origin_image_urls)222 self._aid = ret["data"]["aid"]223 else:224 self._aid = aid225226 def setTilte(self, tilte=0):227 "设置专栏标题"228 self._tilte = tilte229 def setCategory(self, category=0):230 "设置专栏分类"231 self._category = category232 def setListId(self, list_id=0):233 "设置文集编号"234 self._list_id = list_id235 def setTid(self, tid=4):236 "设置专栏封面类型"237 self._tid = tid238 def setOriginal(self, original=1):239 "设置专栏是否为原创,原创为1,非原创为0"240 self._original = original241 def setImage(self, origin_image_urls: str, image_urls=""):242 "设置专栏缩略图,image_urls为缩略图网址,origin_image_urls为缩略图原图在文章中的网址"243 self._origin_image_urls = origin_image_urls244 if image_urls:245 self._image_urls = image_urls246 else:247 self._image_urls = origin_image_urls248 def setContent(self, content: Content):249 "设置文章内容"250 self._content = content.output()251252 def getAid(self, url=False):253 "返回创建文章的aid或url,可通过url在网页上修改此文章"254 if url:255 return f'https://member.bilibili.com/v2#/upload/text/edit?aid={self._aid}'256 else:257 return self._aid258259 def refresh(self):260 "如果在本程序外(例如网页上)修改了本文章,执行此函数同步"261 ret = self.getArticle(self._aid)262 self._tilte = ret["data"]["tilte"]263 self._content = ret["data"]["content"]264 self._category = ret["data"]["category"]["id"]265 if(ret["data"]["list"] != None):266 self._list_id = ret["data"]["list"]["id"]267 self._tid = ret["data"]["template_id"]268 self._original = ret["data"]["original"]269 self._image_urls = ret["data"]["image_urls"][0]270 self._origin_image_urls = ret["data"]["origin_image_urls"][0] #这里可能有丢失封面的问题271272 def save(self):273 "保存至B站上草稿箱,不发布,网页上可编辑"274 return self.createArticle(self._tilte, self._content, self._aid, self._category, self._list_id, self._tid, self._original, self._image_urls, self._origin_image_urls)275276 def submit(self):277 "发布至B站上"278 return self.createArticle(self._tilte, self._content, self._aid, self._category, self._list_id, self._tid, self._original, self._image_urls, self._origin_image_urls, True)279280 def delself(self):281 '''删除当前文章草稿'''282 self.deleteArticle(self._aid)283284 def __del__(self): ...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from allauth.socialaccount.tests import OAuthTestsMixin3from allauth.tests import MockedResponse, TestCase4from .provider import FlickrProvider5class FlickrTests(OAuthTestsMixin, TestCase):6 provider_id = FlickrProvider.id7 def get_mocked_response(self):8 #9 return [10 MockedResponse(11 200,12 r"""13 {"stat": "ok",14 "user": {15 "username": {16 "_content": "pennersr"},17 "id": "12345678@N00"}}18""",19 ), # noqa20 MockedResponse(21 200,22 r"""23{"person": {"username": {"_content": "pennersr"}, "photosurl": {"_content":24 "http://www.flickr.com/photos/12345678@N00/"},25 "nsid": "12345678@N00",26 "path_alias": null, "photos": {"count": {"_content": 0},27 "firstdatetaken": {"_content": null}, "views": {"_content": "28"},28 "firstdate": {"_content": null}}, "iconserver": "0",29 "description": {"_content": ""}, "mobileurl": {"_content":30 "http://m.flickr.com/photostream.gne?id=6294613"},31 "profileurl": {32 "_content": "http://www.flickr.com/people/12345678@N00/"},33 "mbox_sha1sum": {"_content":34 "5e5b359c123e54f95236209c8808d607a5cdd21e"},35 "ispro": 0, "location": {"_content": ""},36 "id": "12345678@N00",37 "realname": {"_content": "raymond penners"},38 "iconfarm": 0}, "stat": "ok"}39""",40 ),41 ] # noqa42 def test_login(self):43 account = super(FlickrTests, self).test_login()44 f_account = account.get_provider_account()45 self.assertEqual(account.user.first_name, "raymond")46 self.assertEqual(account.user.last_name, "penners")47 self.assertEqual(48 f_account.get_profile_url(),49 "http://www.flickr.com/people/12345678@N00/",50 )51 self.assertEqual(f_account.to_str(), "raymond penners")52class FlickrWithoutRealNameTests(OAuthTestsMixin, TestCase):53 """Separate test for Flickr accounts without real names"""54 provider_id = FlickrProvider.id55 def get_mocked_response(self):56 #57 return [58 MockedResponse(59 200,60 r"""61 {"stat": "ok",62 "user": {63 "username": {64 "_content": "pennersr"},65 "id": "12345678@N00"}}66""",67 ), # noqa68 MockedResponse(69 200,70 r"""71{"person": {"username": {"_content": "pennersr"}, "photosurl": {"_content":72 "http://www.flickr.com/photos/12345678@N00/"},73 "nsid": "12345678@N00",74 "path_alias": null, "photos": {"count": {"_content": 0},75 "firstdatetaken": {"_content": null}, "views": {"_content": "28"},76 "firstdate": {"_content": null}}, "iconserver": "0",77 "description": {"_content": ""}, "mobileurl": {"_content":78 "http://m.flickr.com/photostream.gne?id=6294613"},79 "profileurl": {80 "_content": "http://www.flickr.com/people/12345678@N00/"},81 "mbox_sha1sum": {"_content":82 "5e5b359c123e54f95236209c8808d607a5cdd21e"},83 "ispro": 0, "location": {"_content": ""},84 "id": "12345678@N00",85 "realname": {"_content": ""},86 "iconfarm": 0}, "stat": "ok"}87""",88 ),89 ] # noqa90 def test_login(self):91 account = super(FlickrWithoutRealNameTests, self).test_login()92 f_account = account.get_provider_account()93 self.assertEqual(account.user.first_name, "")94 self.assertEqual(account.user.last_name, "")95 self.assertEqual(96 f_account.get_profile_url(),97 "http://www.flickr.com/people/12345678@N00/",98 )...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run locust automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful