Answer the question
In order to leave comments, you need to log in
How to write a test in Django to work with an uploaded file?
The site has a file upload button that is parsed and uploaded to the database.
In the code line:
file = request.FILES['impfile']
file_data = file.readlines()
for line1 in file_data:
line = line1.decode('cp1251')
def test_read_one(self):
with open(self.test_file, 'r+') as file:
mem_file = InMemoryUploadedFile(file, field_name='kfile', name='201810.txt', content_type='text/plain', charset=None, size=os.path.getsize(self.test_file))
print(mem_file)
table = load_file(mem_file)
self.assertTrue(table[0] == self.one_record)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question