Skip to content

Commit 40acc1c

Browse files
test(storage): cases for admin and user based
1 parent c825c16 commit 40acc1c

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

tests/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def password():
4242

4343
@pytest.fixture(scope='session')
4444
def storage():
45-
# To make it easier to test, we keep the test restricted to firebase_tests
46-
# Because of the current mutations on calls, we return it as a function.
45+
return make_storage()
46+
47+
48+
@pytest.fixture(scope='session')
49+
def storage_admin():
4750
return make_storage(service_account=True)

tests/test_setup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ def test_setup_db():
3737

3838

3939
def test_setup_storage():
40+
storage = make_storage()
41+
42+
with pytest.raises(AttributeError) as exc_info:
43+
storage.list_files()
44+
assert 'bucket' in str(exc_info.value)
45+
46+
47+
def test_setup_storage_admin():
4048
storage = make_storage(True)
4149

4250
assert storage.list_files()

tests/test_storage.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,56 @@
99

1010
class TestStorage:
1111

12+
test_user = None
13+
14+
def test_user_for_storage(self, auth):
15+
self.__class__.test_user = auth.sign_in_anonymous()
16+
assert self.__class__.test_user is not None
17+
1218
def test_child(self, storage):
1319
assert storage.child('firebase-test-001')
1420

1521
def test_put(self, storage):
16-
assert storage.child('uploaded-file.txt').put("tests/static/test-file.txt") is None
22+
assert storage.child('uploaded-file.txt').put("tests/static/test-file.txt", self.__class__.test_user.get('idToken'))
1723

1824
def test_get_url(self, storage):
19-
assert storage.child('firebase-test-001').child('uploaded-file.txt').get_url(None)
25+
assert storage.child('firebase-test-001').child('uploaded-file.txt').get_url(self.__class__.test_user.get('idToken'))
2026

2127
def test_download(self, storage):
22-
assert storage.child('firebase-test-001').child('uploaded-file.txt').download('tests/static/downloaded.txt') is None
28+
assert storage.child('firebase-test-001').child('uploaded-file.txt').download('tests/static/downloaded.txt', self.__class__.test_user.get('idToken')) is None
2329
assert os.path.exists('tests/static/downloaded.txt')
2430

2531
def test_delete(self, storage):
2632
os.remove('tests/static/downloaded.txt')
27-
assert storage.child('firebase-test-001/uploaded-file.txt').delete() is None
33+
assert storage.child('firebase-test-001/uploaded-file.txt').delete(self.__class__.test_user.get('idToken')) is None
2834

2935
def test_list_of_files(self, storage):
30-
assert storage.list_files()
36+
with pytest.raises(AttributeError) as exc_info:
37+
storage.list_files()
38+
assert 'bucket' in str(exc_info.value)
39+
40+
def test_clean_user(self, auth):
41+
assert auth.delete_user_account(self.__class__.test_user.get('idToken'))
42+
43+
44+
class TestStorageAdmin:
45+
46+
def test_child(self, storage_admin):
47+
assert storage_admin.child('firebase-test-001')
48+
49+
def test_put(self, storage_admin):
50+
assert storage_admin.child('uploaded-file.txt').put("tests/static/test-file.txt") is None
51+
52+
def test_get_url(self, storage_admin):
53+
assert storage_admin.child('firebase-test-001').child('uploaded-file.txt').get_url(None)
54+
55+
def test_download(self, storage_admin):
56+
assert storage_admin.child('firebase-test-001').child('uploaded-file.txt').download('tests/static/downloaded.txt') is None
57+
assert os.path.exists('tests/static/downloaded.txt')
58+
59+
def test_delete(self, storage_admin):
60+
os.remove('tests/static/downloaded.txt')
61+
assert storage_admin.child('firebase-test-001/uploaded-file.txt').delete() is None
62+
63+
def test_list_of_files(self, storage_admin):
64+
assert storage_admin.list_files()

0 commit comments

Comments
 (0)