I am writing a web application while learning, I have written a function which receives a file. now I want to write a test function for it.i am using pytest.
in the test function, i will be required to submit a file, I have already checked requests for doing so but i am not getting it. please show some light so i can create a test function for the following given function.
@app.post('/check/<number>')
def file_upload(number):
u_name = request.forms.get('username') # accepting username
time = datetime.datetime.now()
# type(uploaded) == <class 'bytes'>
uploaded = request.files.get('upload').file.read() # uploaded outputs by user
expected = questions[number].output
expected = expected.strip()
uploaded = uploaded.strip()
ans = (uploaded == expected)
usernames[u_name].append(Submission(question=number, time=time,
output=uploaded, result=ans))
if not ans:
return 'Wrong answer'
else:
return 'Solved! Great Job!'
I want 200
response while running the test file.
Aucun commentaire:
Enregistrer un commentaire