You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/07/29 07:20:58 UTC
[GitHub] [incubator-superset] pengyejun commented on a change in pull request #10429: fix(#9914): Add upload file max size limit
pengyejun commented on a change in pull request #10429:
URL: https://github.com/apache/incubator-superset/pull/10429#discussion_r461360829
##########
File path: tests/core_tests.py
##########
@@ -981,6 +981,43 @@ def test_import_csv(self):
os.remove(f1)
os.remove(f2)
+ def test_import_csv_filesize_limit(self):
+ max_bytes = app.config.get("UPLOAD_MAX_BYTES")
+ if not max_bytes:
+ return
+ self.login(username="admin")
+ table_name = "".join(random.choice(string.ascii_lowercase) for _ in range(5))
+ f1 = "testSize.csv"
+ self.enable_csv_upload(utils.get_example_database())
+ repeat = max_bytes // 4
+ data = "a,b"
+ content = [data for _ in range(repeat)]
+ self.create_sample_csvfile(f1, content)
Review comment:
The single line content of the file is a,b\n.The size is 4byte.
repeat is the number of file lines.
file f1 less than or equal to UPLOAD_MAX_BYTES
##########
File path: tests/core_tests.py
##########
@@ -981,6 +981,43 @@ def test_import_csv(self):
os.remove(f1)
os.remove(f2)
+ def test_import_csv_filesize_limit(self):
+ max_bytes = app.config.get("UPLOAD_MAX_BYTES")
+ if not max_bytes:
+ return
+ self.login(username="admin")
+ table_name = "".join(random.choice(string.ascii_lowercase) for _ in range(5))
+ f1 = "testSize.csv"
+ self.enable_csv_upload(utils.get_example_database())
+ repeat = max_bytes // 4
+ data = "a,b"
+ content = [data for _ in range(repeat)]
+ self.create_sample_csvfile(f1, content)
+ try:
+ success_msg_f1 = f'CSV file "{f1}" uploaded to table "{table_name}"'
+
+ # initial upload with fail mode
+ resp = self.upload_csv(f1, table_name)
+ self.assertIn(success_msg_f1, resp)
Review comment:
So the upload was successful
##########
File path: tests/core_tests.py
##########
@@ -981,6 +981,43 @@ def test_import_csv(self):
os.remove(f1)
os.remove(f2)
+ def test_import_csv_filesize_limit(self):
+ max_bytes = app.config.get("UPLOAD_MAX_BYTES")
+ if not max_bytes:
+ return
+ self.login(username="admin")
+ table_name = "".join(random.choice(string.ascii_lowercase) for _ in range(5))
+ f1 = "testSize.csv"
+ self.enable_csv_upload(utils.get_example_database())
+ repeat = max_bytes // 4
+ data = "a,b"
+ content = [data for _ in range(repeat)]
+ self.create_sample_csvfile(f1, content)
+ try:
+ success_msg_f1 = f'CSV file "{f1}" uploaded to table "{table_name}"'
+
+ # initial upload with fail mode
+ resp = self.upload_csv(f1, table_name)
+ self.assertIn(success_msg_f1, resp)
+
+ # upload again with fail mode; should fail
+ fail_msg = f'Unable to upload CSV file "{f1}" to table "{table_name}"'
+ fail_msg2 = (
Review comment:
beacause content.append(data),file f1 is larger than UPLOAD_MAX_BYTES.
So the upload was fail
##########
File path: tests/core_tests.py
##########
@@ -981,6 +981,43 @@ def test_import_csv(self):
os.remove(f1)
os.remove(f2)
+ def test_import_csv_filesize_limit(self):
+ max_bytes = app.config.get("UPLOAD_MAX_BYTES")
+ if not max_bytes:
+ return
+ self.login(username="admin")
+ table_name = "".join(random.choice(string.ascii_lowercase) for _ in range(5))
+ f1 = "testSize.csv"
+ self.enable_csv_upload(utils.get_example_database())
+ repeat = max_bytes // 4
+ data = "a,b"
+ content = [data for _ in range(repeat)]
+ self.create_sample_csvfile(f1, content)
+ try:
+ success_msg_f1 = f'CSV file "{f1}" uploaded to table "{table_name}"'
+
+ # initial upload with fail mode
+ resp = self.upload_csv(f1, table_name)
+ self.assertIn(success_msg_f1, resp)
+
+ # upload again with fail mode; should fail
+ fail_msg = f'Unable to upload CSV file "{f1}" to table "{table_name}"'
+ fail_msg2 = (
Review comment:
because content.append(data),file f1 is larger than UPLOAD_MAX_BYTES.
So the upload was fail
##########
File path: tests/core_tests.py
##########
@@ -981,6 +981,43 @@ def test_import_csv(self):
os.remove(f1)
os.remove(f2)
+ def test_import_csv_filesize_limit(self):
+ max_bytes = app.config.get("UPLOAD_MAX_BYTES")
+ if not max_bytes:
+ return
+ self.login(username="admin")
+ table_name = "".join(random.choice(string.ascii_lowercase) for _ in range(5))
+ f1 = "testSize.csv"
+ self.enable_csv_upload(utils.get_example_database())
+ repeat = max_bytes // 4
+ data = "a,b"
+ content = [data for _ in range(repeat)]
+ self.create_sample_csvfile(f1, content)
+ try:
+ success_msg_f1 = f'CSV file "{f1}" uploaded to table "{table_name}"'
+
+ # initial upload with fail mode
+ resp = self.upload_csv(f1, table_name)
+ self.assertIn(success_msg_f1, resp)
+
+ # upload again with fail mode; should fail
+ fail_msg = f'Unable to upload CSV file "{f1}" to table "{table_name}"'
+ fail_msg2 = (
+ f"Error message: Exceeded the upload maximum size of {max_bytes} bytes"
+ )
+ content.append(data)
+ self.create_sample_csvfile(f1, content)
+ resp = self.upload_csv(f1, table_name)
+ self.assertIn(fail_msg, resp)
+ self.assertIn(fail_msg2, resp)
+ # make sure that john and empty string are replaced with None
Review comment:
repeat-1 should be equal to the number of lines in the f1 csv file (excluding headers).
The number of rows in table should be equal to repeat-1.
The data form row content should be equal to ("a", "b")
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org