-
Notifications
You must be signed in to change notification settings - Fork 331
/
Copy pathtest_storage.py
64 lines (51 loc) · 2.11 KB
/
test_storage.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
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Integration tests for firebase_admin.storage module."""
import time
import urllib
from firebase_admin import storage
def test_default_bucket(project_id):
bucket = storage.bucket()
_verify_bucket(bucket, '{0}.appspot.com'.format(project_id))
def test_custom_bucket(project_id):
bucket_name = '{0}.appspot.com'.format(project_id)
bucket = storage.bucket(bucket_name)
_verify_bucket(bucket, bucket_name)
def test_non_existing_bucket():
bucket = storage.bucket('non.existing')
assert bucket.exists() is False
def test_download_url(project_id):
bucket = storage.bucket()
ts = int(time.time())
file_name = 'data_{0}.txt'.format(ts)
enc_file_name = urllib.parse.quote(file_name, safe='')
blob = bucket.blob(file_name)
blob.upload_from_string('Hello World')
url = storage.get_download_url(blob)
parse_result = urllib.parse.urlparse(url)
assert parse_result.netloc == 'firebasestorage.googleapis.com'
assert project_id in parse_result.path
assert enc_file_name in parse_result.path
query_dict = dict(urllib.parse.parse_qs(parse_result.query))
assert 'token' in query_dict
bucket.delete_blob(file_name)
def _verify_bucket(bucket, expected_name):
assert bucket.name == expected_name
file_name = 'data_{0}.txt'.format(int(time.time()))
blob = bucket.blob(file_name)
blob.upload_from_string('Hello World')
blob = bucket.get_blob(file_name)
assert blob.download_as_string().decode() == 'Hello World'
bucket.delete_blob(file_name)
assert not bucket.get_blob(file_name)