From a605c4e6e59103e78321f67663d725ca33976211 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc" Date: Tue, 19 Jan 2021 15:30:29 -0600 Subject: [PATCH] Pass settings to quote_columns(), they vary by inherited module --- src/pgwui_upload_core/views/upload.py | 5 ++--- tests/views/test_upload.py | 12 ++++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/pgwui_upload_core/views/upload.py b/src/pgwui_upload_core/views/upload.py index 535efca..ddd8622 100644 --- a/src/pgwui_upload_core/views/upload.py +++ b/src/pgwui_upload_core/views/upload.py @@ -149,11 +149,10 @@ class BaseTableUploadHandler(TabularFileUploadHandler): self.cur.execute(sql, (table, schema)) return self.cur.fetchone() is not None - def quote_columns(self): + def quote_columns(self, settings): '''Return boolean -- whether to take column names literally ''' - settings = self.request.registry.settings - quoter_setting = settings['pgwui'].get('literal_column_headings') + quoter_setting = settings.get('literal_column_headings') if quoter_setting == 'on': return True elif quoter_setting == 'ask': diff --git a/tests/views/test_upload.py b/tests/views/test_upload.py index 9335121..a144301 100644 --- a/tests/views/test_upload.py +++ b/tests/views/test_upload.py @@ -152,7 +152,7 @@ def get_quote_columns(neuter_tableuploadhandler): request.registry.settings = settings uh = neuter_tableuploadhandler(uploadform, DummyRequest()) - return uh.quote_columns() + return uh.quote_columns(settings) return run @@ -162,7 +162,7 @@ def test_tableuploadhandler_quote_columns_on(get_quote_columns): True ''' result = get_quote_columns(UPLOAD_FORM_W_LIT_CHECKED, - {'pgwui': {'literal_column_headings': 'on'}}) + {'literal_column_headings': 'on'}) assert result is True @@ -171,7 +171,7 @@ def test_tableuploadhandler_quote_columns_off(get_quote_columns): False ''' result = get_quote_columns(UPLOAD_FORM_W_LIT_CHECKED, - {'pgwui': {'literal_column_headings': 'off'}}) + {'literal_column_headings': 'off'}) assert result is False @@ -179,7 +179,7 @@ def test_tableuploadhandler_quote_columns_default(get_quote_columns): '''When the settings literal_column_headings is not present return False (as default) ''' - result = get_quote_columns(UPLOAD_FORM_W_LIT_CHECKED, {'pgwui': {}}) + result = get_quote_columns(UPLOAD_FORM_W_LIT_CHECKED, {}) assert result is False @@ -187,7 +187,7 @@ def test_tableuploadhandler_quote_columns_ask_on(get_quote_columns): '''When the form asks for literal column headings return True ''' result = get_quote_columns(UPLOAD_FORM_W_LIT_CHECKED, - {'pgwui': {'literal_column_headings': 'ask'}}) + {'literal_column_headings': 'ask'}) assert result is True @@ -195,7 +195,7 @@ def test_tableuploadhandler_quote_columns_ask_off(get_quote_columns): '''When the form does not ask for literal column headings return False ''' result = get_quote_columns({'literal_col_headings': False}, - {'pgwui': {'literal_column_headings': 'ask'}}) + {'literal_column_headings': 'ask'}) assert result is False -- 2.34.1