From 39196ba49781a12a1c3a207f70f5a9e641f7adeb Mon Sep 17 00:00:00 2001 From: Thijs Cobben Date: Mon, 21 Aug 2017 15:10:34 +0200 Subject: [PATCH 1/4] Fixed - not fully tested - addition of community workflow (works) Didn't test if I can publish something under this workflow. --- b2share/modules/communities/cli.py | 32 ++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/b2share/modules/communities/cli.py b/b2share/modules/communities/cli.py index 31f9c89c82..66c6bcf2a9 100644 --- a/b2share/modules/communities/cli.py +++ b/b2share/modules/communities/cli.py @@ -41,7 +41,8 @@ def communities(): """communities management commands.""" -def _validate_community_parameters(name=None, description=None, logo=None): +def _validate_community_parameters(name=None, description=None, + logo=None, workflow=None): """Validate community parameters and update them if needed.""" if name is not None and len(name) > 255: raise click.BadParameter(""""NAME parameter is longer than the 255 @@ -60,7 +61,11 @@ def _validate_community_parameters(name=None, description=None, logo=None): image file existing in the B2SHARE_UI_PATH/img/communities/ directory.""") logo = '/' + os.path.relpath(logo, webui_path) - return (name, description, logo) + if workflow is not None: + if not workflow in ('direct_publish', 'review_and_publish'): + raise click.BadParameter("""WORKFLOW should be either + direct_publish or review_and_publish""") + return (name, description, logo, workflow) @communities.command() @@ -96,7 +101,7 @@ def list(verbose): """List all communities in this instances' database""" communities = Community.get_all() for c in communities: - click.echo("%s\t%s\t%s\t%s" % (c.name[0:15], c.id, c.description[0:31], c.logo)) + click.echo("%s\t%s\t%s\t%s\t%s" % (c.name[0:15], c.id, c.description[0:31], c.logo, c.publication_workflow)) @communities.command() @@ -105,21 +110,22 @@ def list(verbose): @click.option('--name') @click.option('--description') @click.option('--logo') +@click.option('--workflow', help='direct_publish or review_and_publish') @click.option('--clear_fields', is_flag=True, default=False, help='if set edit nullifies unspecified value options') @click.argument('id') -def edit(verbose, id, name, description, logo, clear_fields): +def edit(verbose, id, name, description, logo, workflow, clear_fields): """Edit data of the specified community.""" try: community = Community.get(id=id) except: raise click.BadParameter("No community with id %s" % id) - if not(name or description or logo): - raise click.ClickException("""At least one of name, description or - id must be specified""") + if not(name or description or logo or workflow): + raise click.ClickException("""At least one of name, description, + logo or workflow must be specified""") - name, description, logo = _validate_community_parameters(name, description, - logo) + name, description, logo, workflow = _validate_community_parameters( + name, description, logo, workflow) data = {} if name: if name != community.name: @@ -135,11 +141,15 @@ def edit(verbose, id, name, description, logo, clear_fields): data['description'] = description if logo: data['logo'] = logo + if workflow: + data['publication_workflow'] = workflow updated_community = community.update(data, clear_fields) db.session.commit() - click.echo("Community %s updated: name= %s description=%s logo=%s" % + click.echo("""Community %s updated: name= %s description=%s + logo=%s workflow=%s""" % (updated_community.id, updated_community.name, - updated_community.description, updated_community.logo)) + updated_community.description, updated_community.logo, + updated_community.publication_workflow)) @communities.command() From ea8428fbc0710b89695ee8c65920a87ef6a5a20c Mon Sep 17 00:00:00 2001 From: Thijs Cobben Date: Tue, 22 Aug 2017 15:32:04 +0200 Subject: [PATCH 2/4] Debug in cli create comm --- b2share/modules/communities/cli.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/b2share/modules/communities/cli.py b/b2share/modules/communities/cli.py index 66c6bcf2a9..532a9c5dcb 100644 --- a/b2share/modules/communities/cli.py +++ b/b2share/modules/communities/cli.py @@ -79,8 +79,10 @@ def create(verbose, name, description, logo): Description is a text of maximally 1024 characters enclosed in parentheses. The logo parameter should be a valid path to a logo file relative to B2SHARE_UI_PATH/img/communities directory """ - name, description, logo = _validate_community_parameters(name, description, - logo) + name, description, logo, workflow = _validate_community_parameters( + name, + description, + logo, None) try: Community.get(name=name) #if it does not yield the CommunityDoesNotExistError then: From e263d6d73fcea30f0d207090947d15933ebace4b Mon Sep 17 00:00:00 2001 From: Thijs Cobben Date: Tue, 5 Sep 2017 09:35:24 +0200 Subject: [PATCH 3/4] Towards unit test for community workflow --- .../cli_tests/test_communities_cli.py | 13 +++++++++++++ tests/conftest.py | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/b2share_functional_tests/cli_tests/test_communities_cli.py b/tests/b2share_functional_tests/cli_tests/test_communities_cli.py index ad74093fe7..9d078ee764 100644 --- a/tests/b2share_functional_tests/cli_tests/test_communities_cli.py +++ b/tests/b2share_functional_tests/cli_tests/test_communities_cli.py @@ -99,3 +99,16 @@ def test_edit_community2(app, test_communities): obj=script_info) assert result.exit_code != 0 +def test_community_workflow(app, test_communities): + with app.app_context(): + runner = CliRunner() + script_info = ScriptInfo(create_app=lambda info:app) + result = runner.invoke( + communities_cmd, + ["edit", + "cccccccc-1111-1111-1111-111111111111", + "publication_workflow", + "review_and_publish"], + obj=script_info) + + diff --git a/tests/conftest.py b/tests/conftest.py index ca392e4570..eccf8ac1a8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -86,7 +86,9 @@ def base_app(): DEBUG_TB_ENABLED=False, SQLALCHEMY_DATABASE_URI=os.environ.get( 'SQLALCHEMY_DATABASE_URI', - 'postgresql+psycopg2://postgres@localhost:5432/b2sharedb'), + #'postgresql+psycopg2://postgres@localhost:5432/b2sharedb'), + 'sqlite://'), + FLASK_DEBUG=0, LOGIN_DISABLED=False, WTF_CSRF_ENABLED=False, SECRET_KEY="CHANGE_ME", From 8e617ac34908a12618e8ac35f40aeead85ba6a2b Mon Sep 17 00:00:00 2001 From: Thijs Cobben Date: Mon, 23 Oct 2017 11:02:41 +0200 Subject: [PATCH 4/4] Removed my own test settings --- tests/conftest.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index eccf8ac1a8..ca392e4570 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -86,9 +86,7 @@ def base_app(): DEBUG_TB_ENABLED=False, SQLALCHEMY_DATABASE_URI=os.environ.get( 'SQLALCHEMY_DATABASE_URI', - #'postgresql+psycopg2://postgres@localhost:5432/b2sharedb'), - 'sqlite://'), - FLASK_DEBUG=0, + 'postgresql+psycopg2://postgres@localhost:5432/b2sharedb'), LOGIN_DISABLED=False, WTF_CSRF_ENABLED=False, SECRET_KEY="CHANGE_ME",