Completed
Pull Request — master (#71)
by Johannes
01:13
created

test_none_default_storage()   A

Complexity

Conditions 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 2
1
import os
2
import time
3
4
import pytest
5
from django.core.management import call_command
6
7
from tests.models import ManualVariationsModel, MyStorageModel, ThumbnailModel
8
9
10
@pytest.mark.django_db
11
class TestRenderVariations(object):
12
    def test_no_options(self, image_upload_file):
13
        obj = ManualVariationsModel.customer_manager.create(
14
            image=image_upload_file
15
        )
16
        file_path = obj.image.thumbnail.path
17
        call_command(
18
            'rendervariations',
19
            'tests.ManualVariationsModel.image'
20
        )
21
        assert os.path.exists(file_path)
22
23
    def test_multiprocessing(self, image_upload_file):
24
        file_names = [
25
            ManualVariationsModel.customer_manager.create(
26
                image=image_upload_file
27
            ).image.thumbnail.path
28
            for _ in range(100)
29
        ]
30
        assert not any([os.path.exists(f) for f in file_names])
31
        call_command(
32
            'rendervariations',
33
            'tests.ManualVariationsModel.image'
34
        )
35
        assert any([os.path.exists(f) for f in file_names])
36
37
    def test_no_replace(self, image_upload_file):
38
        obj = ThumbnailModel.objects.create(image=image_upload_file)
39
        file_path = obj.image.thumbnail.path
40
        assert os.path.exists(file_path)
41
        before = os.path.getmtime(file_path)
42
        time.sleep(1)
43
        call_command(
44
            'rendervariations',
45
            'tests.ThumbnailModel.image',
46
        )
47
        assert os.path.exists(file_path)
48
        after = os.path.getmtime(file_path)
49
        assert before == after
50
51
    def test_replace(self, image_upload_file):
52
        obj = ThumbnailModel.objects.create(image=image_upload_file)
53
        file_path = obj.image.thumbnail.path
54
        assert os.path.exists(file_path)
55
        before = os.path.getmtime(file_path)
56
        time.sleep(1)
57
        call_command(
58
            'rendervariations',
59
            'tests.ThumbnailModel.image',
60
            replace=True
61
        )
62
        assert os.path.exists(file_path)
63
        after = os.path.getmtime(file_path)
64
        assert before != after
65
66
    def test_none_default_storage(self, image_upload_file):
67
        obj = MyStorageModel.customer_manager.create(
68
            image=image_upload_file
69
        )
70
        file_path = obj.image.thumbnail.path
71
        call_command(
72
            'rendervariations',
73
            'tests.MyStorageModel.image'
74
        )
75
        assert os.path.exists(file_path)
76