Skip to content

Commit

Permalink
🐛fix(profile): Fix the profile decorator and profile settings (#2)
Browse files Browse the repository at this point in the history
* 🐛fix(profile): Fix the profile decorator and profile settings

* 🐛fix(profile): Fix the profile decorator and profile settings
  • Loading branch information
Alonreznik authored Apr 1, 2021
1 parent 234a56e commit 3b91bcc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/run-unitests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ jobs:
name: Setup Python 3.8
with:
python-version: 3.8
- name: cd into tests
run: cd tests
- name: Run Unitests
run: python -m unittest tests/
run: python -m unittest discover .
1 change: 1 addition & 0 deletions rivery_cli/cli/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
def create_auth_file(ctx, **kwargs):
""" Configure new profile and the authentication."""
profile = kwargs.get('profile') or ctx.get('PROFILE') or 'default'
click.secho(f'Configuring profile: {profile}')
region = ctx.get('REGION')
host = ctx.get('HOST')

Expand Down
2 changes: 2 additions & 0 deletions rivery_cli/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
from rivery_cli.globals.global_settings import DEFAULT_MODELS, DEFAULT_SQLS, DEFAULT_MAPPING
from collections import OrderedDict
from rivery_cli.utils import decorators


@click.command('init')
Expand All @@ -12,6 +13,7 @@
@click.option('--models', required=False, type=str, help="The Models (entities) directory", default=DEFAULT_MODELS)
@click.option('--sqls', required=False, type=str, help="The sqls (queries) directory", default=DEFAULT_SQLS)
@click.option('--maps', required=False, type=str, help="The mapping directory", default=DEFAULT_MAPPING)
@decorators.profile_decorator
def init(**kwargs):
""" Make a initiation project.yaml in the current path"""
project_name = kwargs.get('name')
Expand Down
9 changes: 7 additions & 2 deletions rivery_cli/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ def profile_decorator(func):
"""
Profile decorator for adding --profile to every function
"""
@click.option('--profile', help='The profile of the ')
def wrapped(*args, **kwargs):
@click.option('--profile', help='The profile you want to work with, as defined in the auth file.')
@click.pass_context
def wrapped(ctx, *args, **kwargs):
""" Warrped function """
if ctx:
ctx.ensure_object(dict)
ctx.obj['PROFILE'] = kwargs.get('profile') or 'default'
func(*args, **kwargs)

return wrapped

Empty file added tests/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions tests/test_cli_rivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ def setUp(self) -> None:
self.runner = CliRunner(echo_stdin=True)
self.runner.invoke(
cli=base.cli,
args=['init']
args=['init', '--profile=test']
)

def test_import_rivers(self):
""" Tes import rivers """

resp = self.runner.invoke(cli=base.cli,
args=['rivers', 'import', '--riverId=60005bb389f000001ef047aa', '--path=logics/'],
args=['--profile=test', 'rivers', 'import', '--riverId=60005bb389f000001ef047aa', '--path=logics/'],
catch_exceptions=False,
color=True)
print(resp.stdout)
Expand Down

0 comments on commit 3b91bcc

Please sign in to comment.