-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest_invenio_s3.py
55 lines (44 loc) · 1.79 KB
/
test_invenio_s3.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
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018, 2019 Esteban J. G. Gabancho.
# Copyright (C) 2024 KTH Royal Institute of Technology.
#
# Invenio-S3 is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
"""Module tests."""
from invenio_s3 import InvenioS3
def test_version():
"""Test version import."""
from invenio_s3 import __version__
assert __version__
def test_init(appctx):
"""Test extension initialization."""
assert "invenio-s3" in appctx.extensions
appctx.config["S3_ENDPOINT_URL"] = "https://example.com:1234"
appctx.config["S3_REGION_NAME"] = "eu-west-1"
s3_connection_info = appctx.extensions["invenio-s3"].init_s3fs_info
assert (
s3_connection_info["client_kwargs"]["endpoint_url"]
== "https://example.com:1234"
)
assert s3_connection_info["client_kwargs"]["region_name"] == "eu-west-1"
def test_access_key(appctx):
"""Test correct access key works together with flawed one."""
appctx.config["S3_ACCCESS_KEY_ID"] = "secret"
try:
# Delete the cached value in case it's there already
del appctx.extensions["invenio-s3"].__dict__["init_s3fs_info"]
except KeyError:
pass
s3_connection_info = appctx.extensions["invenio-s3"].init_s3fs_info
assert s3_connection_info["key"] == "secret"
def test_secret_key(appctx):
"""Test correct secret key works together with flawed one."""
appctx.config["S3_SECRECT_ACCESS_KEY"] = "secret"
try:
# Delete the cached value in case it's there already
del appctx.extensions["invenio-s3"].__dict__["init_s3fs_info"]
except KeyError:
pass
s3_connection_info = appctx.extensions["invenio-s3"].init_s3fs_info
assert s3_connection_info["secret"] == "secret"