Pass settings to quote_columns(), they vary by inherited module
authorKarl O. Pinc <kop@karlpinc.com>
Tue, 19 Jan 2021 21:30:29 +0000 (15:30 -0600)
committerKarl O. Pinc <kop@karlpinc.com>
Tue, 19 Jan 2021 21:30:29 +0000 (15:30 -0600)
src/pgwui_upload_core/views/upload.py
tests/views/test_upload.py

index 535efca372808ce6cf07b611861cddf8b1429311..ddd86225e5c2af33d92c0b021cf16447ba9163a3 100644 (file)
@@ -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':
index 9335121b35ccad9f39ad472bb6db632c33cae06f..a14430129da5b53ebf04033e935f61a9d1de10f8 100644 (file)
@@ -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