def test_is_synced(self): article = Article("Test", "lk", datetime.now(), uuid.uuid4()) article.save_to_db() article.set_title("TestUpdated") article.sync_to_db() self.assertTrue(article.is_synced(), "article marked un-synced when it is") article.remove_from_db()
def test_remove_from_db(self): article = Article("Test", "lk", datetime.now(), uuid.uuid4()) article.save_to_db() try: article.remove_from_db() except NoSuchArticleExistException: self.fail("Error occurred when tried to delete existing article")
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")
def article_add_post(): try: article_date = datetime.strptime(request.form.get('date'), '%m/%d/%Y %I:%M %p') new_article = None if request.form.get('publication') is "": new_article = Article(request.form.get('title'), request.form.get('summary'), article_date, uuid.UUID(request.form.get('page_id')), ) else: new_article = Article(request.form.get('title'), request.form.get('summary'), article_date, uuid.UUID(request.form.get('page_id')), request.form.get('publication')) if not new_article.is_valid_model(): abort(500) new_article.save_to_db() return jsonify({"message": "Done"}), 200 except ValueError: abort(500)
def article_add_post(): try: article_date = datetime.strptime(request.form.get('date'), '%m/%d/%Y %I:%M %p') new_article = None if request.form.get('publication') is "": new_article = Article( request.form.get('title'), request.form.get('summary'), article_date, uuid.UUID(request.form.get('page_id')), ) else: new_article = Article(request.form.get('title'), request.form.get('summary'), article_date, uuid.UUID(request.form.get('page_id')), request.form.get('publication')) if not new_article.is_valid_model(): abort(500) new_article.save_to_db() return jsonify({"message": "Done"}), 200 except ValueError: abort(500)
def test_not_synced(self): article = Article("Test", "lk", datetime.now(), uuid.uuid4()) article.save_to_db() article.set_title("TestUpdated") self.assertFalse(article.is_synced(),"article marked synced when it is not") article.remove_from_db()