Skip to content

Commit

Permalink
extracted configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
magc committed Sep 7, 2020
1 parent 875aa58 commit 3f95a4f
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 124 deletions.
24 changes: 24 additions & 0 deletions cs3api_test_ext/app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[io]
# Size used for buffered reads [bytes]
chunksize = 4194304

[cs3]
reva_host = localhost:19000
secure_channel = false
client_cert =
client_key =
ca_cert =
login_type = basic
auth_token_validity = 3600
user_id = einstein
client_id = einstein
client_secret = relativity
receiver_id = f7fbf8c8-139b-4376-b307-cf0a8c2d0d9c
receiver_idp = cesnet.cz
receiver_role = viewer
receiver_grantee_type = user
receiver_username = marie
receiver_secret = radioactivity
file_path = /test.txt
endpoint = /
home_dir = /home
34 changes: 34 additions & 0 deletions cs3api_test_ext/config/config_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import configparser


class ConfigManager:
config = {}

def __init__(self, file_name):
config_parser = configparser.ConfigParser()
try:
with open(file_name) as fdconf:
config_parser.read_file(fdconf)
self.config = {
"reva_host": config_parser.get('cs3', 'reva_host'),
"auth_token_validity": config_parser.get('cs3', 'auth_token_validity'),
"user_id": config_parser.get('cs3', 'user_id'),
"endpoint": config_parser.get('cs3', 'endpoint'),
"secure_channel": config_parser.getboolean('cs3', 'secure_channel'),
"client_cert": config_parser.get('cs3', 'client_cert'),
"client_key": config_parser.get('cs3', 'client_key'),
"ca_cert": config_parser.get('cs3', 'ca_cert'),
"chunksize": config_parser.get('io', 'chunksize'),
"client_id": config_parser.get('cs3', 'client_id'),
"client_secret": config_parser.get('cs3', 'client_secret'),
"home_dir": config_parser.get('cs3', 'home_dir'),
"login_type": config_parser.get('cs3', 'login_type'),
"file_path": config_parser.get('cs3', 'file_path'),
"receiver_id": config_parser.get('cs3', 'receiver_id'),
"receiver_idp": config_parser.get('cs3', 'receiver_idp'),
"receiver_role": config_parser.get('cs3', 'receiver_role'),
"receiver_grantee_type": config_parser.get('cs3', 'receiver_grantee_type')
}
except (KeyError, configparser.NoOptionError):
print("Missing option or missing configuration, check the test.conf file")
raise
9 changes: 5 additions & 4 deletions cs3api_test_ext/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from cs3api_test_ext.api.cs3apismanager import CS3APIsManager
from cs3api_test_ext.api.cs3_share_api import Cs3ShareApi
from cs3api_test_ext.config.config_manager import ConfigManager


class HelloWorldHandle(APIHandler):
Expand Down Expand Up @@ -152,7 +153,7 @@ def _finish_model(self, model, location=True):
class ShareHandle(APIHandler):
@property
def share_api(self):
return Cs3ShareApi()
return Cs3ShareApi(ConfigManager('cs3api_test_ext/app.conf').config)

def data_received(self, chunk: bytes) -> Optional[Awaitable[None]]:
pass
Expand Down Expand Up @@ -183,7 +184,7 @@ def put(self):
class ListSharesHandler(APIHandler):
@property
def share_api(self):
return Cs3ShareApi()
return Cs3ShareApi(ConfigManager('cs3api_test_ext/app.conf').config)

@web.authenticated
@gen.coroutine
Expand All @@ -194,7 +195,7 @@ def get(self):
class ListReceivedSharesHandler(APIHandler):
@property
def share_api(self):
return Cs3ShareApi()
return Cs3ShareApi(ConfigManager('cs3api_test_ext/app.conf').config)

@web.authenticated
@gen.coroutine
Expand All @@ -212,7 +213,7 @@ def put(self):
class ListSharesForFile(APIHandler):
@property
def share_api(self):
return Cs3ShareApi()
return Cs3ShareApi(ConfigManager('cs3api_test_ext/app.conf').config)

@web.authenticated
@gen.coroutine
Expand Down
40 changes: 8 additions & 32 deletions cs3api_test_ext/tests/test_cs3_file_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import unittest
import logging
import configparser
from unittest import TestCase

from cs3api_test_ext.config.config_manager import ConfigManager
from cs3api_test_ext.api.cs3_file_api import Cs3FileApi


Expand All @@ -15,36 +14,13 @@ def setUp(self):
log = logging.getLogger('cs3api.test')
log.setLevel(logging.DEBUG)

config_parser = configparser.ConfigParser()

try:
with open('test.conf') as fdconf:
config_parser.read_file(fdconf)

self.user_id = config_parser.get('cs3', 'user_id')
self.endpoint = config_parser.get('cs3', 'endpoint')

config = {
"reva_host": config_parser.get('cs3', 'reva_host'),
"auth_token_validity": config_parser.get('cs3', 'auth_token_validity'),
"user_id": config_parser.get('cs3', 'user_id'),
"endpoint": config_parser.get('cs3', 'endpoint'),
"secure_channel": config_parser.getboolean('cs3', 'secure_channel'),
"client_cert": config_parser.get('cs3', 'client_cert'),
"client_key": config_parser.get('cs3', 'client_key'),
"ca_cert": config_parser.get('cs3', 'ca_cert'),
"chunksize": config_parser.get('io', 'chunksize'),
"client_id": config_parser.get('cs3', 'client_id'),
"client_secret": config_parser.get('cs3', 'client_secret'),
"home_dir": config_parser.get('cs3', 'home_dir'),
"login_type": config_parser.get('cs3', 'login_type')
}

self.storage = Cs3FileApi(config, log)

except (KeyError, configparser.NoOptionError):
print("Missing option or missing configuration, check the test.conf file")
raise
config = ConfigManager('test.conf').config

self.user_id = config['user_id']
self.endpoint = config['endpoint']
self.storage = Cs3FileApi(config, log)



def test_stat(self):

Expand Down
30 changes: 2 additions & 28 deletions cs3api_test_ext/tests/test_cs3_share_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from unittest import TestCase
from unittest import skip
from cs3api_test_ext.api.cs3_share_api import Cs3ShareApi
import configparser
from cs3api_test_ext.api.cs3_file_api import Cs3FileApi
import logging
from cs3api_test_ext.config.config_manager import ConfigManager


class TestCs3ShareApi(TestCase):
Expand All @@ -16,33 +16,7 @@ def setUpClass(cls):
# todo logger
log = logging.getLogger('cs3api.test')
log.setLevel(logging.DEBUG)
config_parser = configparser.ConfigParser()
try:
with open('test.conf') as fdconf:
config_parser.read_file(fdconf)
cls.config = {
"secure_channel": config_parser.getboolean('cs3', 'secure_channel'),
"client_cert": config_parser.get('cs3', 'client_cert'),
"client_key": config_parser.get('cs3', 'client_key'),
"ca_cert": config_parser.get('cs3', 'ca_cert'),
"chunksize": config_parser.get('io', 'chunksize'),
"reva_host": config_parser.get('cs3', 'reva_host'),
"auth_token_validity": config_parser.get('cs3', 'auth_token_validity'),
"client_id": config_parser.get('cs3', 'client_id'),
"client_secret": config_parser.get('cs3', 'client_secret'),
"file_path": config_parser.get('cs3', 'file_path'),
"receiver_id": config_parser.get('cs3', 'receiver_id'),
"receiver_idp": config_parser.get('cs3', 'receiver_idp'),
"receiver_role": config_parser.get('cs3', 'receiver_role'),
"receiver_grantee_type": config_parser.get('cs3', 'receiver_grantee_type'),
"endpoint": config_parser.get('cs3', 'endpoint'),
"home_dir": config_parser.get('cs3', 'home_dir'),
"login_type": config_parser.get('cs3', 'login_type'),
"user_id": config_parser.get('cs3', 'user_id')
}
except (KeyError, configparser.NoOptionError):
print("Missing option or missing configuration, check the test.conf file")
raise
cls.config = ConfigManager('test.conf').config
cls.storage = Cs3FileApi(cls.config, log)
cls.api = Cs3ShareApi(cls.config)

Expand Down
Loading

0 comments on commit 3f95a4f

Please sign in to comment.