From a9289accb82d1a47e24eac5a6e0cf1537fc95625 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Mon, 31 Aug 2020 15:36:43 -0500 Subject: [PATCH] Move literal_column_headings setting into PGWUI_Upload --- examples/etc/pgwui.ini | 27 +++++++++++------- examples/misc/development.ini | 18 +++++++++++- src/pgwui_server/__init__.py | 14 --------- src/pgwui_server/exceptions.py | 7 ----- tests/test___init__.py | 52 ---------------------------------- 5 files changed, 34 insertions(+), 84 deletions(-) diff --git a/examples/etc/pgwui.ini b/examples/etc/pgwui.ini index 7cb1e4a..bfe5a4e 100644 --- a/examples/etc/pgwui.ini +++ b/examples/etc/pgwui.ini @@ -41,14 +41,6 @@ pgwui.default_db = template1 # Whether or not to change the db content. (required) pgwui.dry_run = False -# Menu presentation - -# The PGWUI_Menu component automaticaly constructs a menu for the -# PGWUI components in use. The display value of the menu items can -# be overridden. -#pgwui.pgwui_upload = -# menu_label = upload -- Upload File Into Database - # Routing # Routes are what call up specific pages. They are the @@ -89,6 +81,20 @@ pgwui.dry_run = False # vulnerabilties. Validation is on by default. # pgwui.validate_hmac = True +# PGWUI Component Settings + +# Menu presentation + +# The PGWUI_Menu component automaticaly constructs a menu for the +# PGWUI components in use. The display value of the menu items can +# be overridden using a "menu_label" setting for each component. +# CAUTION: Do not uncomment the below, instead change the component's +# "menu_label" setting. +#pgwui.pgwui_upload = +# menu_label = upload -- Upload File Into Database + +# pgwui_upload + # Take uploaded column headings literally? # The available choices are: # on The file's column headings, as typed, are the table's column names. @@ -98,8 +104,9 @@ pgwui.dry_run = False # # Caution: Non-ASCII column names, particularly in the Turkish locale, # are not guaranteed to be case-insensitive. -pgwui.literal_column_headings = off - +pgwui.pgwui_upload = + literal_column_headings = off + # menu_label = upload -- Upload File Into Database # # Pyramid configuration diff --git a/examples/misc/development.ini b/examples/misc/development.ini index e80eadc..c613b1b 100644 --- a/examples/misc/development.ini +++ b/examples/misc/development.ini @@ -81,6 +81,20 @@ pgwui.dry_run = False # vulnerabilties. Validation is on by default. pgwui.validate_hmac = False +# PGWUI Component Settings + +# Menu presentation + +# The PGWUI_Menu component automaticaly constructs a menu for the +# PGWUI components in use. The display value of the menu items can +# be overridden using a "menu_label" setting for each component. +# CAUTION: Do not uncomment the below, instead change the component's +# "menu_label" setting. +#pgwui.pgwui_upload = +# menu_label = upload -- Upload File Into Database + +# pgwui_upload + # Take uploaded column headings literally? # The available choices are: # on The file's column headings, as typed, are the table's column names. @@ -90,7 +104,9 @@ pgwui.validate_hmac = False # # Caution: Non-ASCII column names, particularly in the Turkish locale, # are not guaranteed to be case-insensitive. -pgwui.literal_column_headings = off +pgwui.pgwui_upload = + literal_column_headings = off + # menu_label = upload -- Upload File Into Database # diff --git a/src/pgwui_server/__init__.py b/src/pgwui_server/__init__.py index 0b380b3..fe0488b 100644 --- a/src/pgwui_server/__init__.py +++ b/src/pgwui_server/__init__.py @@ -44,7 +44,6 @@ SETTINGS = set( 'routes', 'validate_hmac', 'autoconfigure', - 'literal_column_headings', ]) @@ -106,9 +105,6 @@ def validate_setting_values(errors, settings): # validate_hmac boolean_setting(errors, 'pgwui.validate_hmac', settings) - # literal_column_headings - validate_literal_column_headings(errors, settings) - def do_validate_hmac(settings): '''True unless the user has specificly rejected hmac validation @@ -131,16 +127,6 @@ def validate_hmac(errors, settings): return -def validate_literal_column_headings(errors, settings): - '''Make sure the values are those allowed - ''' - value = settings.get('pgwui.literal_column_headings') - if value is None: - return - if value not in ('on', 'off', 'ask'): - errors.append(server_ex.BadLiteralColumnHeadingsError(value)) - - def parse_assignments(lines): '''Return a list of key/value tuples from the lines of a setting ''' diff --git a/src/pgwui_server/exceptions.py b/src/pgwui_server/exceptions.py index ef82da5..518ac0f 100644 --- a/src/pgwui_server/exceptions.py +++ b/src/pgwui_server/exceptions.py @@ -41,13 +41,6 @@ class BadSettingsAbort(ServerError): super().__init__('Aborting due to bad setting(s)') -class BadLiteralColumnHeadingsError(ServerError): - def __init__(self, value): - super().__init__( - 'The "pgwui.literal_column_headings" PGWUI setting must be' - '"on", "off", "ask", or not present') - - class BadHMACError(ServerError): pass diff --git a/tests/test___init__.py b/tests/test___init__.py index f4cc6c1..da17a2f 100644 --- a/tests/test___init__.py +++ b/tests/test___init__.py @@ -300,58 +300,6 @@ mock_validate_hmac = testing.make_mock_fixture( pgwui_server_init, 'validate_hmac') -# validate_literal_column_headings() - -def test_validate_literal_column_headings_nosetting(): - '''No error is delivered when there's no setting''' - errors = [] - pgwui_server_init.validate_literal_column_headings(errors, {}) - - assert errors == [] - - -def test_validate_literal_column_headings_on(): - '''No error is delivered when the setting is "on"''' - errors = [] - pgwui_server_init.validate_literal_column_headings( - errors, {'pgwui.literal_column_headings': 'on'}) - - assert errors == [] - - -def test_validate_literal_column_headings_off(): - '''No error is delivered when the setting is "off"''' - errors = [] - pgwui_server_init.validate_literal_column_headings( - errors, {'pgwui.literal_column_headings': 'off'}) - - assert errors == [] - - -def test_validate_literal_column_headings_ask(): - '''No error is delivered when the setting is "ask"''' - errors = [] - pgwui_server_init.validate_literal_column_headings( - errors, {'pgwui.literal_column_headings': 'ask'}) - - assert errors == [] - - -def test_validate_literal_column_headings_bad(): - '''delivers an error when given a bad value''' - errors = [] - pgwui_server_init.validate_literal_column_headings( - errors, {'pgwui.literal_column_headings': 'bad'}) - - assert errors - assert isinstance( - errors[0], server_ex.BadLiteralColumnHeadingsError) - - -mock_validate_literal_column_headings = testing.make_mock_fixture( - pgwui_server_init, 'validate_literal_column_headings') - - # parse_assignments() def test_parse_assignments_str(): -- 2.34.1