Rework the tutorial to be more consistent, and to better explain certain principles that drive Falcon's design. Along the way, polish a few other areas of the docs where someone might land during or immediate after walking through the tutorial.
27 lines
685 B
Python
27 lines
685 B
Python
import os
|
|
|
|
import requests
|
|
|
|
|
|
def test_posted_image_gets_saved():
|
|
file_save_prefix = '/tmp/'
|
|
location_prefix = '/images/'
|
|
fake_image_bytes = b'fake-image-bytes'
|
|
|
|
response = requests.post(
|
|
'http://localhost:8000/images',
|
|
data=fake_image_bytes,
|
|
headers={'content-type': 'image/png'}
|
|
)
|
|
|
|
assert response.status_code == 201
|
|
location = response.headers['location']
|
|
assert location.startswith(location_prefix)
|
|
image_name = location.replace(location_prefix, '')
|
|
|
|
file_path = file_save_prefix + image_name
|
|
with open(file_path, 'rb') as image_file:
|
|
assert image_file.read() == fake_image_bytes
|
|
|
|
os.remove(file_path)
|