test cases: fix generation of random test files

master
Ferry Boender 4 years ago
parent b348cf9a86
commit 572e0c7407
  1. 26
      test/test.py

@ -8,6 +8,13 @@ import threading
import time import time
import requests import requests
import re import re
import random
def gen_random_file(fname, size=1024):
with open(fname, 'wb') as fh:
for i in range(size):
fh.write(chr(random.randint(0, 255)).encode('utf-8'))
class FormConfigTestCase(unittest.TestCase): class FormConfigTestCase(unittest.TestCase):
@ -360,10 +367,7 @@ class WebAppTest(unittest.TestCase):
"select": "option_a", "select": "option_a",
} }
import random gen_random_file('data.csv')
with open('data.csv', 'w') as fh:
for i in range(1024):
fh.write(chr(random.randint(0, 255)))
with open('data.csv', 'rb') as fh: with open('data.csv', 'rb') as fh:
files = {'file': fh} files = {'file': fh}
@ -395,10 +399,7 @@ class WebAppTest(unittest.TestCase):
"select": "invalidvalue", "select": "invalidvalue",
} }
import random gen_random_file('data.txt')
with open('data.txt', 'w') as fh:
for i in range(1024):
fh.write(chr(random.randint(0, 255)))
with open('data.txt', 'rb') as fh: with open('data.txt', 'rb') as fh:
files = {'file': fh} files = {'file': fh}
@ -435,10 +436,7 @@ class WebAppTest(unittest.TestCase):
"select": "option_b", "select": "option_b",
} }
import random gen_random_file('data.txt')
with open('data.txt', 'w') as fh:
for i in range(1024):
fh.write(chr(random.randint(0, 255)))
with open ('data.txt', 'rb') as fh: with open ('data.txt', 'rb') as fh:
files = {'file': fh} files = {'file': fh}
@ -480,9 +478,7 @@ class WebAppTest(unittest.TestCase):
self.assertIn('string=<foo>', r.text) self.assertIn('string=<foo>', r.text)
def testUpload(self): def testUpload(self):
import random gen_random_file('data.raw')
with open('data.raw', 'w') as fh:
fh.write(chr(random.randint(0, 255)))
data = { data = {
"form_name": "upload" "form_name": "upload"

Loading…
Cancel
Save