예제 #1
0
 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()
예제 #2
0
 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")
예제 #3
0
 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")
예제 #4
0
 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")
예제 #5
0
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)
예제 #6
0
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)
예제 #7
0
 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()