forked from noirbizarre/flask-fs
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_swift_backend.py
65 lines (51 loc) · 1.73 KB
/
test_swift_backend.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
import swiftclient
from .test_backend_mixin import BackendTestCase
from flask_fs.backends.swift import SwiftBackend
from flask_fs.storage import Config
import pytest
USER = "test:tester"
KEY = "testing"
AUTHURL = "http://127.0.0.1:8085/auth/v1.0"
TENANT_NAME = ""
REGION_NAME = ""
class SwiftBackendTest(BackendTestCase):
hasher = "md5"
@pytest.fixture(autouse=True)
def setup(self):
self.conn = swiftclient.Connection(
user=USER,
key=KEY,
authurl=AUTHURL,
)
self.container = "test"
self.config = Config(
{
"user": USER,
"key": KEY,
"authurl": AUTHURL,
"tenant_name": TENANT_NAME,
"region_name": REGION_NAME,
"auth_version": 1,
"create_container": True,
}
)
self.backend = SwiftBackend(self.container, self.config)
yield
try:
headers, items = self.conn.get_container(self.backend.name)
for i in items:
self.conn.delete_object(self.backend.name, i["name"])
self.conn.delete_container(self.backend.name)
except swiftclient.ClientException as e:
assert False, "Failed to delete container ->" + str(e)
def put_file(self, filename, content):
self.conn.put_object(self.container, filename, contents=content)
def get_file(self, filename):
_, data = self.conn.get_object(self.container, filename)
return data
def file_exists(self, filename):
try:
self.conn.head_object(self.container, filename)
return True
except swiftclient.ClientException:
return False