Set the "updated" timestamps correctly.

master
Pacman Ghost 4 years ago
parent 2b97ec75d2
commit 662b2e0ea3
  1. 2
      asl_articles/articles.py
  2. 2
      asl_articles/publications.py
  3. 2
      asl_articles/publishers.py
  4. 30
      asl_articles/tests/test_articles.py
  5. 30
      asl_articles/tests/test_publications.py
  6. 30
      asl_articles/tests/test_publishers.py
  7. 31
      asl_articles/tests/utils.py

@ -215,11 +215,11 @@ def update_article():
article = Article.query.get( article_id )
if not article:
abort( 404 )
vals[ "time_updated" ] = datetime.datetime.now()
apply_attrs( article, vals )
_save_authors( article, updated )
_save_scenarios( article, updated )
_save_image( article, updated )
vals[ "time_updated" ] = datetime.datetime.now()
db.session.commit()
search.add_or_update_article( None, article )

@ -146,9 +146,9 @@ def update_publication():
pub = Publication.query.get( pub_id )
if not pub:
abort( 404 )
vals[ "time_updated" ] = datetime.datetime.now()
apply_attrs( pub, vals )
_save_image( pub, updated )
vals[ "time_updated" ] = datetime.datetime.now()
db.session.commit()
search.add_or_update_publication( None, pub )

@ -136,8 +136,8 @@ def update_publisher():
if not publ:
abort( 404 )
_save_image( publ, updated )
apply_attrs( publ, vals )
vals[ "time_updated" ] = datetime.datetime.now()
apply_attrs( publ, vals )
db.session.commit()
search.add_or_update_publisher( None, publ )

@ -11,7 +11,7 @@ from asl_articles.tests.utils import init_tests, select_main_menu_option, select
do_search, get_search_results, find_search_result, get_search_result_names, check_search_result, \
wait_for, wait_for_elem, wait_for_not_elem, find_child, find_children, \
set_elem_text, set_toast_marker, check_toast, send_upload_data, check_ask_dialog, check_error_msg, \
change_image
change_image, get_article_row
from asl_articles.tests.react_select import ReactSelect
# ---------------------------------------------------------------------
@ -328,6 +328,34 @@ def test_clean_html( webdriver, flask_app, dbconn ):
# ---------------------------------------------------------------------
def test_timestamps( webdriver, flask_app, dbconn ):
"""Test setting of timestamps."""
# initialize
init_tests( webdriver, flask_app, dbconn )
# create an article
create_article( { "title": "My Article" } )
results = get_search_results()
assert len(results) == 1
article_sr = results[0]
article_id = article_sr.get_attribute( "testing--article_id" )
# check its timestamps
row = get_article_row( dbconn, article_id, ["time_created","time_updated"] )
assert row[0]
assert row[1] is None
# update the article
edit_article( article_sr, { "title": "My Article (updated)" } )
# check its timestamps
row2 = get_article_row( dbconn, article_id, ["time_created","time_updated"] )
assert row2[0] == row[0]
assert row2[1] > row2[0]
# ---------------------------------------------------------------------
def create_article( vals, toast_type="info" ):
"""Create a new article."""

@ -14,7 +14,7 @@ from asl_articles.tests.utils import init_tests, load_fixtures, select_main_menu
do_search, get_search_results, get_search_result_names, check_search_result, \
wait_for, wait_for_elem, wait_for_not_elem, find_child, find_children, find_search_result, set_elem_text, \
set_toast_marker, check_toast, send_upload_data, check_ask_dialog, check_error_msg, \
change_image
change_image, get_publication_row
from asl_articles.tests.react_select import ReactSelect
# ---------------------------------------------------------------------
@ -374,6 +374,34 @@ def test_clean_html( webdriver, flask_app, dbconn ):
# ---------------------------------------------------------------------
def test_timestamps( webdriver, flask_app, dbconn ):
"""Test setting of timestamps."""
# initialize
init_tests( webdriver, flask_app, dbconn )
# create a publication
create_publication( { "name": "My Publication" } )
results = get_search_results()
assert len(results) == 1
pub_sr = results[0]
pub_id = pub_sr.get_attribute( "testing--pub_id" )
# check its timestamps
row = get_publication_row( dbconn, pub_id, ["time_created","time_updated"] )
assert row[0]
assert row[1] is None
# update the publication
edit_publication( pub_sr, { "name": "My Publication (updated)" } )
# check its timestamps
row2 = get_publication_row( dbconn, pub_id, ["time_created","time_updated"] )
assert row2[0] == row[0]
assert row2[1] > row2[0]
# ---------------------------------------------------------------------
def create_publication( vals, toast_type="info" ):
"""Create a new publication."""

@ -12,7 +12,7 @@ from asl_articles.tests.utils import init_tests, load_fixtures, select_main_menu
do_search, get_search_results, get_search_result_names, check_search_result, \
wait_for, wait_for_elem, wait_for_not_elem, find_child, find_search_result, set_elem_text, \
set_toast_marker, check_toast, send_upload_data, check_ask_dialog, check_error_msg, \
change_image
change_image, get_publisher_row
# ---------------------------------------------------------------------
@ -350,6 +350,34 @@ def test_clean_html( webdriver, flask_app, dbconn ):
# ---------------------------------------------------------------------
def test_timestamps( webdriver, flask_app, dbconn ):
"""Test setting of timestamps."""
# initialize
init_tests( webdriver, flask_app, dbconn )
# create a publisher
create_publisher( { "name": "Joe Publisher" } )
results = get_search_results()
assert len(results) == 1
publ_sr = results[0]
publ_id = publ_sr.get_attribute( "testing--publ_id" )
# check its timestamps
row = get_publisher_row( dbconn, publ_id, ["time_created","time_updated"] )
assert row[0]
assert row[1] is None
# update the publisher
edit_publisher( publ_sr, { "name": "Joe Publisher (updated)" } )
# check its timestamps
row2 = get_publisher_row( dbconn, publ_id, ["time_created","time_updated"] )
assert row2[0] == row[0]
assert row2[1] > row2[0]
# ---------------------------------------------------------------------
def create_publisher( vals, toast_type="info" ):
"""Create a new publisher."""

@ -304,6 +304,37 @@ def _do_select_menu_option( menu, sel ):
# ---------------------------------------------------------------------
# FUDGE! We can't use prepared statements here, since the syntax is different for SQLite and Postgres :-/
def get_publisher_row( dbconn, publ_id, fields ):
"""Get a row from the publisher table."""
assert publ_id
return dbconn.execute(
"SELECT {} FROM publisher WHERE publ_id={}".format(
",".join(fields), publ_id
)
).fetchone()
def get_publication_row( dbconn, pub_id, fields ):
"""Get a row from the publication table."""
assert pub_id
return dbconn.execute(
"SELECT {} FROM publication WHERE pub_id={}".format(
",".join(fields), pub_id
)
).fetchone()
def get_article_row( dbconn, article_id, fields ):
"""Get a row from the article table."""
assert article_id
return dbconn.execute(
"SELECT {} FROM article WHERE article_id={}".format(
",".join(fields), article_id
)
).fetchone()
# ---------------------------------------------------------------------
def change_image( elem, image_data ):
"""Click on an image to change it."""
# NOTE: This is a bit tricky since we started overlaying the image with the "remove image" icon :-/

Loading…
Cancel
Save