File: test_closing_fieldfiles.py

package info (click to toggle)
python-django-imagekit 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 696 kB
  • sloc: python: 2,000; makefile: 133
file content (25 lines) | stat: -rw-r--r-- 804 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from nose.tools import assert_false, assert_true

from .models import Thumbnail
from .utils import create_photo


def test_do_not_leak_open_files():
    instance = create_photo('leak-test.jpg')
    source_file = instance.original_image
    # Ensure the FieldFile is closed before generation
    source_file.close()
    image_generator = Thumbnail(source=source_file)
    image_generator.generate()
    assert_true(source_file.closed)


def test_do_not_close_open_files_after_generate():
    instance = create_photo('do-not-close-test.jpg')
    source_file = instance.original_image
    # Ensure the FieldFile is opened before generation
    source_file.open()
    image_generator = Thumbnail(source=source_file)
    image_generator.generate()
    assert_false(source_file.closed)
    source_file.close()