diff options
Diffstat (limited to 'services/database/db_cms.py')
-rw-r--r-- | services/database/db_cms.py | 75 |
1 files changed, 44 insertions, 31 deletions
diff --git a/services/database/db_cms.py b/services/database/db_cms.py index 3c2b2c6..288121a 100644 --- a/services/database/db_cms.py +++ b/services/database/db_cms.py @@ -1,5 +1,4 @@ - -# ============LICENSE_START========================================== +# ============LICENSE_START========================================== # org.onap.vvp/test-engine # =================================================================== # Copyright © 2017 AT&T Intellectual Property. All rights reserved. @@ -39,17 +38,9 @@ import psycopg2 from wheel.signatures import assertTrue -from services.constants import Constants from services.database.db_general import DBGeneral -from services.frontend.base_actions.click import Click -from services.frontend.base_actions.enter import Enter -from services.frontend.base_actions.wait import Wait -from services.frontend.fe_dashboard import FEDashboard -from services.frontend.fe_general import FEGeneral -from services.frontend.fe_user import FEUser from services.helper import Helper from services.logging_service import LoggingServiceFactory -from services.session import session logger = LoggingServiceFactory.get_logger() @@ -70,7 +61,7 @@ class DBCMS: dbConn.close() logger.debug("Insert query success!") # If failed - count the failure and add the error to list of errors. - except: + except BaseException: raise Exception("Couldn't fetch answer using the given query.") @staticmethod @@ -86,7 +77,7 @@ class DBCMS: dbConn.close() logger.debug("Update query success!") # If failed - count the failure and add the error to list of errors. - except: + except BaseException: raise Exception("Couldn't fetch answer using the given query.") @staticmethod @@ -107,14 +98,14 @@ class DBCMS: logger.debug("Query result: " + str(result)) return result # If failed - count the failure and add the error to list of errors. - except: + except BaseException: raise Exception("Couldn't fetch answer using the given query.") @staticmethod def get_cms_category_id(categoryName): logger.debug("Get DBCMS category id for name: " + categoryName) - queryStr = "SELECT id FROM public.blog_blogcategory WHERE title = '%s' LIMIT 1;" % ( - categoryName) + queryStr = "SELECT id FROM public.blog_blogcategory WHERE " +\ + "title = '%s' LIMIT 1;" % (categoryName) logger.debug("Query : " + queryStr) result = DBCMS.select_query(queryStr) return result @@ -123,9 +114,17 @@ class DBCMS: def insert_cms_new_post(title, description, categoryName): logger.debug("Insert new post : " + title) queryStr = "INSERT INTO public.blog_blogpost" \ - "(comments_count, keywords_string, rating_count, rating_sum, rating_average, title, slug, _meta_title, description, gen_description, created, updated, status, publish_date, expiry_date, short_url, in_sitemap, content, allow_comments, featured_image, site_id, user_id) "\ - "VALUES (0, '', 0, 0, 0, '%s', '%s-slug', '', '%s', true, current_timestamp - interval '1 day', current_timestamp - interval '2 day', 2, current_timestamp - interval '1 day', NULL, '', true, '<p>%s</p>', true, '', 1, 1);" % ( - title, title, description, description) + "(comments_count, keywords_string, rating_count, rating_sum, " +\ + "rating_average, title, slug, _meta_title, description, " +\ + "gen_description, created, updated, status, publish_date, " +\ + "expiry_date, short_url, in_sitemap, content, allow_comments, " +\ + "featured_image, site_id, user_id) "\ + "VALUES (0, '', 0, 0, 0, " +\ + "'%s', '%s-slug', " % (title, title) +\ + "'', '%s', true, " % description +\ + "current_timestamp - interval '1 day', current_timestamp - " +\ + "interval '2 day', 2, current_timestamp - interval '1 day', " +\ + "NULL, '', true, '<p>%s</p>', true, '', 1, 1);" % description logger.debug("Query : " + queryStr) DBCMS.insert_query(queryStr) post_id = DBCMS.get_last_added_post_id() @@ -144,9 +143,9 @@ class DBCMS: @staticmethod def update_days(xdays, title): logger.debug("Get the id of the post inserted") -# queryStr = "select MAX(id) FROM public.blog_blogpost;" - queryStr = "UPDATE public.blog_blogpost SET created=current_timestamp - interval '%s day' WHERE title='%s';" % ( - xdays, title) + queryStr = "UPDATE public.blog_blogpost SET " +\ + "created=current_timestamp - interval '%s day' " % xdays +\ + "WHERE title='%s';" % title logger.debug("Query : " + queryStr) result = DBCMS.update_query(queryStr) return result @@ -154,15 +153,17 @@ class DBCMS: @staticmethod def add_category_to_post(postId, categoryId): logger.debug("bind category into inserted post: " + postId) - queryStr = "INSERT INTO public.blog_blogpost_categories(blogpost_id, blogcategory_id) VALUES (%s, %s);" % ( - postId, categoryId) + queryStr = "INSERT INTO public.blog_blogpost_categories" +\ + "(blogpost_id, blogcategory_id) " +\ + "VALUES (%s, %s);" % (postId, categoryId) logger.debug("Query : " + queryStr) DBCMS.insert_query(queryStr) @staticmethod def get_documentation_page_id(): logger.debug("Retrive id of documentation page: ") - queryStr = "SELECT id FROM public.pages_page WHERE title = 'Documentation' LIMIT 1;" + queryStr = "SELECT id FROM public.pages_page WHERE " +\ + "title = 'Documentation' LIMIT 1;" logger.debug("Query : " + queryStr) result = DBCMS.select_query(queryStr) return result @@ -191,17 +192,27 @@ class DBCMS: if parent_id is None: parent_id = DBCMS.get_documentation_page_id() queryStr = "INSERT INTO public.pages_page(" \ - "keywords_string, title, slug, _meta_title, description, gen_description, created, updated, status, publish_date, expiry_date, short_url, in_sitemap, _order, in_menus, titles, content_model, login_required, parent_id, site_id)" \ - "VALUES ('', '%s', '%s-slug', '', '%s', true, current_timestamp - interval '1 day', current_timestamp - interval '1 day', 2, current_timestamp - interval '1 day', NULL, '', true, 0, '1,2,3', '%s', 'richtextpage', true, %s, 1);" % ( - title, title, content, title, parent_id) + "keywords_string, title, slug, _meta_title, description, " +\ + "gen_description, created, updated, status, publish_date, " +\ + "expiry_date, short_url, in_sitemap, _order, in_menus, titles, " +\ + "content_model, login_required, parent_id, site_id)" \ + "VALUES ('', " +\ + "'%s', '%s-slug'" % (title, title) +\ + ", '', '%s', true, " % content +\ + "current_timestamp - interval '1 day', current_timestamp " +\ + "- interval '1 day', 2, current_timestamp - interval '1 day', " +\ + "NULL, '', true, 0, '1,2,3', " +\ + "'%s', 'richtextpage', " % title +\ + "true, %s, 1);" % parent_id logger.debug("Query : " + queryStr) DBCMS.insert_query(queryStr) createdPageId = DBCMS.get_last_inserted_page_id() logger.debug( "Bind the page with the rich text content related to this page") - queryStr = "INSERT INTO public.pages_richtextpage(page_ptr_id, content) VALUES (%s, '<p>%s</p>');" % ( - createdPageId, content) + queryStr = "INSERT INTO public.pages_richtextpage(page_ptr_id, " +\ + "content) VALUES (%s, '<p>%s</p>');" % ( + createdPageId, content) logger.debug("Query : " + queryStr) DBCMS.insert_query(queryStr) return createdPageId @@ -244,8 +255,10 @@ class DBCMS: @staticmethod def update_X_days_back_post(title, xdays): logger.debug("Get the id of the post inserted") - queryStr = "UPDATE blog_blogpost SET created = current_timestamp - interval '%s day', publish_date=current_timestamp - interval '%s day' WHERE title= '%s' ;" % ( - xdays, xdays, title) + queryStr = "UPDATE blog_blogpost SET created = current_timestamp" +\ + " - interval '%s day', " % xdays +\ + "publish_date=current_timestamp - " +\ + "interval '%s day' WHERE title= '%s' ;" % (xdays, title) logger.debug("Query : " + queryStr) DBCMS.update_query(queryStr) |