This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
forked from bradleyg/django-s3direct
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathruntests.py
125 lines (120 loc) · 3.65 KB
/
runtests.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""Tests for s3direct package."""
import sys
import django
from django.conf import settings
from django.test.utils import get_runner
settings.configure(
DEBUG=True,
DATABASES={'default': {
'ENGINE': 'django.db.backends.sqlite3',
}},
ROOT_URLCONF='s3direct.urls',
INSTALLED_APPS=(
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.messages',
's3direct',
),
MIDDLEWARE=(
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
),
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
"django.contrib.auth.context_processors.auth",
'django.contrib.messages.context_processors.messages',
]
}
},
],
AWS_ACCESS_KEY_ID='123',
AWS_SECRET_ACCESS_KEY='123',
AWS_STORAGE_BUCKET_NAME='test-bucket',
AWS_S3_REGION_NAME='us-east-1',
AWS_S3_ENDPOINT_URL='https://s3.amazonaws.com',
S3DIRECT_DESTINATIONS={
'generic': {
'key': '/'
},
'missing-key': {
'key': None
},
'login-required': {
'key': '/',
'auth': lambda u: u.is_staff
},
'login-not-required': {
'key': '/'
},
'only-images': {
'key': '/',
'allowed': ['image/jpeg', 'image/png']
},
'limited-size': {
'key': '/',
'content_length_range': (1000, 50000)
},
'folder-upload': {
'key': 'uploads/folder'
},
'accidental-leading-slash': {
'key': '/uploads/folder'
},
'accidental-trailing-slash': {
'key': 'uploads/folder/'
},
'function-object-key': {
'key': lambda original_filename: 'images/unique.jpg'
},
'function-object-key-args': {
'key': lambda original_filename, args: args + '/' + 'filename.jpg',
'key_args': 'uploads/folder'
},
'policy-conditions': {
'key': '/',
'auth': lambda user: user.is_authenticated,
'allowed': '*',
'acl': 'authenticated-read',
'bucket': 'astoragebucketname',
'cache_control': 'max-age=2592000',
'content_disposition': 'attachment',
'server_side_encryption': 'AES256'
},
'allow-existence-optimisation': {
'key': 'uploads',
'allow_existence_optimization': True,
},
'disallow-existence-optimisation': {
'key': 'uploads',
'allow_existence_optimization': False,
},
'unset-existence-optimisation': {
'key': 'uploads',
},
'custom-region-bucket': {
'key': 'uploads',
'region': 'cn-north-1',
'endpoint': 'https://s3.cn-north-1.amazonaws.com.cn'
},
'optional-content-disposition-callable': {
'key': '/',
'content_disposition':
lambda x: 'attachment; filename="{}"'.format(x)
},
'optional-cache-control-non-callable': {
'key': '/',
'cache_control': 'public'
}
})
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner()
failures = test_runner.run_tests(['s3direct'])
sys.exit(bool(failures))