Skip to content

Commit

Permalink
python boolean parsing and environment config loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
fundthmcalculus committed Nov 5, 2021
1 parent 26f310d commit b06742e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions python/samples/provider_demo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import asyncio

from tests.test_utilities import get_test_server_config
from trinsic.proto.services.provider.v1 import ParticipantType
from trinsic.services import ProviderService
from trinsic.services import ProviderService, get_test_server_config


async def provider_demo():
Expand Down
3 changes: 1 addition & 2 deletions python/samples/vaccine_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import json
from os.path import abspath, join, dirname

from tests.test_utilities import get_test_server_config
from trinsic.proto.services.universalwallet.v1 import WalletProfile
from trinsic.services import WalletService
from trinsic.services import WalletService, get_test_server_config


def _base_data_path() -> str:
Expand Down
3 changes: 1 addition & 2 deletions python/tests/test_trinsic_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

from samples.provider_demo import provider_demo
from samples.vaccine_demo import vaccine_demo
from tests.test_utilities import get_test_server_config
from trinsic.services import WalletService
from trinsic.services import WalletService, get_test_server_config


class TestServices(unittest.IsolatedAsyncioTestCase):
Expand Down
9 changes: 0 additions & 9 deletions python/tests/test_utilities.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
import os
import unittest

from trinsic.proto.services.common.v1 import ServerConfig
from trinsic.services import create_channel


def get_test_server_config() -> ServerConfig:
endpoint = os.getenv('TEST_SERVER_ENDPOINT')
port = os.getenv('TEST_SERVER_PORT', 443)
use_tls = os.getenv('TEST_SERVER_USE_TLS', True)
return ServerConfig(endpoint=endpoint, port=port, use_tls=use_tls)


# noinspection PyBroadException
class TestUtilities(unittest.IsolatedAsyncioTestCase):
url_params = [
Expand Down
9 changes: 9 additions & 0 deletions python/trinsic/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import datetime
import json
import urllib.parse
from distutils.util import strtobool
from os import getenv
from typing import Mapping, Dict, List, Union

from betterproto import Message
Expand All @@ -19,6 +21,13 @@
from trinsic.proto.services.verifiablecredentials.v1 import CredentialStub


def get_test_server_config() -> ServerConfig:
endpoint = getenv('TEST_SERVER_ENDPOINT')
port = int(getenv('TEST_SERVER_PORT', 443))
use_tls = bool(strtobool(getenv('TEST_SERVER_USE_TLS', 'true')))
return ServerConfig(endpoint=endpoint, port=port, use_tls=use_tls)


def create_channel(config: Union[ServerConfig, str, Channel]) -> Channel:
"""
Create the channel from the provided URL
Expand Down

0 comments on commit b06742e

Please sign in to comment.