def test_delete_post(client, post, user_token): rv = client.delete( "/posts/" + post.url + "/", headers={"Authorization": user_token[1].token} ) assert rv.json["success"] == 1 assert Post.select().count() == 0, "Post not deleted"
def test_delete_post_reader(client, post, reader_token): rv = client.delete( "/posts/" + post.url + "/", headers={"Authorization": reader_token[1].token} ) assert rv.json["success"] == 0 assert rv.json["error"]["code"] == 3 assert Post.select().count() == 1, "Post was deleted"
def validate_url(post): new_url = post.url posts_with_url = Post.select().where(Post.url == new_url) for p in posts_with_url: if p.url == new_url and p.id != post.id: return False return True
def test_delete_post_wrong_user(client, post, user_not_in_blog_with_token): rv = client.delete( "/posts/" + post.url + "/", headers={"Authorization": user_not_in_blog_with_token[1].token}, ) assert rv.json["success"] == 0 assert rv.json["error"]["code"] == 3 assert Post.select().count() == 1, "Post was deleted"
def convert(): create_app() for post in Post.select(): if not post.text: continue post.text = process_text(post.text) cut_info = process_cut(post.text) post.has_cut = cut_info["has_cut"] post.cut_text = cut_info["text_before_cut"] post.cut_name = cut_info["cut_name"] post.save()
def convert(): create_app() for p in Post.select(): if not p.text: continue p.text = process_text(p.text) p.save() for c in Comment.select(): if not c.text: continue c.text = process_text(c.text) c.save()
def migration_v1(db, migrator: SchemaMigrator): from src.model.models import Post with db.atomic(): migrate( migrator.add_column("post", "has_cut", BooleanField(default=False)), migrator.add_column("post", "cut_name", CharField(default=None, null=True)), ) query = Post.select() for p in query: p.has_cut = "<cut>" in p.text p.save()
def convert(): create_app() print("Replacing stickers") stickers_set = set() def replace_sticker(text): if text: pattern = r'<img src="\/common\/templates\/skin\/start-kit\/assets\/images\/(.*?)\..*?">' items = re.findall(pattern, text) for i in items: stickers_set.add(i) text = re.sub(pattern, r":\1:", text) pattern = r'<img src="\/common\/templates\/skin\/start-kit\/assets\/images\/(.*?)\..*?" />' items = re.findall(pattern, text) for i in items: stickers_set.add(i) text = re.sub(pattern, r":\1:", text) pattern = r'<img src="http:\/\/k\.faisu\.net\/kreguzda\/images\/smilies\/(.*?)\..*?" />' items = re.findall(pattern, text) for i in items: stickers_set.add(i) return re.sub(pattern, r":\1:", text) return None for p in Post.select(): p.text = replace_sticker(p.text) p.cut_text = replace_sticker(p.cut_text) p.save() for p in Comment.select(): p.text = replace_sticker(p.text) p.save() for p in Message.select(): p.text = replace_sticker(p.text) p.save() for p in User.select(): p.about = replace_sticker(p.about) p.save() print(stickers_set)