def article_delete(article_id): try: old_article = Article.get_by_id(article_id) old_article.remove_from_db() return jsonify({"message": "Done"}), 200 except NoSuchArticleExistException: abort(404)
def remove_from_db(self): if self._feed: news = [article for article in Database.find("articles", {"page_id" : uuid.UUID('{00000000-0000-0000-0000-000000000000}')})] for article in news: article = Article.get_by_id(article['_id']) article.remove_from_db() Database.remove(self.COLLECTION, {'_id': self._id})
def article_get(article_id): try: old_article = Article.get_by_id(article_id) return render_template('items/article.html', article=old_article.to_json()) except NoSuchArticleExistException: abort(404)
def test_save_to_db(self): article = Article("Test", "lk", datetime.now(), uuid.uuid4()) article.save_to_db() try: test_result = Article.get_by_id(article.get_id()) except NoSuchArticleExistException: self.fail() article.remove_from_db() self.assertEqual(test_result, article, "Saved and retrieved article is not the same")
def test_sync_to_db(self): article = Article("Test", "lk", datetime.now(), uuid.uuid4()) article.save_to_db() article.set_title("TestUpdated") article.sync_to_db() try: test_result = Article.get_by_id(article.get_id()) except NoSuchArticleExistException: self.fail() article.remove_from_db() self.assertEqual(test_result, article, "Sync event with database failed")