Skip to content

Commit

Permalink
Merge pull request #1466 from emanueldima/thijscobben-cli_unit_tests
Browse files Browse the repository at this point in the history
cli unit tests, from Thijs
  • Loading branch information
emanueldima authored Apr 29, 2017
2 parents c53b497 + 6aa093b commit 38fadd8
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
101 changes: 101 additions & 0 deletions tests/b2share_functional_tests/cli_tests/test_communities_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# -*- coding: utf-8 -*-
#
# This file is part of EUDAT B2Share.
# Copyright (C) 2017 SurfSara, University of Tübingen
#
# B2Share is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# B2Share is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with B2Share; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

"""Test B2Share schema cli module."""
from __future__ import absolute_import, print_function

import os
import json
import pytest
from click.testing import CliRunner
from flask_cli import ScriptInfo

from b2share.modules.communities.cli import communities as communities_cmd
from b2share.modules.communities.helpers import get_community_by_name_or_id


def test_communities_group_cli(app, test_communities):
"""Test the `communities` CLI command group."""
with app.app_context():
runner = CliRunner()
script_info = ScriptInfo(create_app=lambda info: app)
# Run 'communities' command
result = runner.invoke(communities_cmd, [], obj=script_info)
assert result.exit_code == 0

def test_communities_list(app, test_communities):
with app.app_context():
runner = CliRunner()
script_info = ScriptInfo(create_app=lambda info: app)
result = runner.invoke(communities_cmd, ["list"], obj=script_info)
assert len(result.output)>0

def test_create_community(app, test_communities):
with app.app_context():
runner = CliRunner()
script_info = ScriptInfo(create_app=lambda info:app)
result = runner.invoke(
communities_cmd,
["create",
"COMM_NAME",
"Description comm",
"bbmri.png"],
obj=script_info)
assert result.exit_code == 0
retrieved_comm = get_community_by_name_or_id("COMM_NAME")
assert retrieved_comm.name=='COMM_NAME'

def test_create_community2(app, test_communities):
with app.app_context():
runner = CliRunner()
script_info = ScriptInfo(create_app=lambda info:app)
result = runner.invoke(
communities_cmd,
["create"],
obj=script_info)
assert result.exit_code != 0

def test_edit_community(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",
"--name",
"NEW_NAME2"],
obj=script_info)
result = runner.invoke(communities_cmd, ["list"], obj=script_info)
retrieved_comm = get_community_by_name_or_id("NEW_NAME2")
assert retrieved_comm.name=='NEW_NAME2'

def test_edit_community2(app, test_communities):
with app.app_context():
runner = CliRunner()
script_info = ScriptInfo(create_app=lambda info:app)
result = runner.invoke(
communities_cmd,
["edit",
"community_does_not_exist",
"--name",
"NEW_NAME2"],
obj=script_info)
assert result.exit_code != 0

Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,43 @@ def test_new_community_set_schema_cmd(app, login_user, tmp_location):
}]),
headers=headers)
assert draft_submit_res.status_code == 200

def test_schemas_group(app, test_communities):
"""Test the `schemas` CLI command group."""
with app.app_context():
runner = CliRunner()
script_info = ScriptInfo(create_app=lambda info: app)
# Run 'schemas' command
result = runner.invoke(schemas_cmd, [], obj=script_info)
assert result.exit_code == 0

def test_block_schema_list(app):
"""Test the b2share schemas block_schema_list command"""
with app.app_context():
runner = CliRunner()
script_info = ScriptInfo(create_app=lambda info: app)
# Run 'schemas' command
result = runner.invoke(schemas_cmd, ["block_schema_list"], obj=script_info)
assert result.exit_code == 0
test_string = result.output[len(result.output)-10:len(result.output)-1]
assert test_string == '#VERSIONS' #no block schemas present empty header

def test_create_block_schema(app, test_communities):
"""Test creation of a block schema"""
#happy flow
with app.app_context():
runner = CliRunner()
script_info = ScriptInfo(create_app=lambda info: app)
result = runner.invoke(schemas_cmd, [
'block_schema_add',
'cccccccc-1111-1111-1111-111111111111',
'Block Schema Name'],
obj=script_info)
assert result.exit_code == 0
result = runner.invoke(schemas_cmd, [
'block_schema_list'
],
obj=script_info)
# search only for "Block Schema Na", as the rest of the string is cut
# by the pretty printer (multiple columns)
assert(result.output.find("Block Schema Na") > 0)

0 comments on commit 38fadd8

Please sign in to comment.