Skip to content

Commit

Permalink
added test case and increased coverage (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
naesheim committed Apr 12, 2021
1 parent b876206 commit 8a0954f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
6 changes: 3 additions & 3 deletions functionhub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ def upload_function(global_config, zip_file):
else:
click.secho("Size limitation, consider a paid subscription",fg='red')

except Error as ke:
click.secho(f"{ke}",fg='red')
except configparser.NoOptionError as noe:
click.secho(f"{noe}",fg='red')

@fuhub.command(name='create')
@click.argument('package_name', type=click.Path(exists=False))
@click.argument('desired_dir', required=False, default=os.getcwd(), type=click.Path(exists=True,resolve_path=True, writable=True))
@click.pass_obj
def create_function(global_config, package_name, desired_dir):
target_dir=os.path.join(desired_dir,package_name)
try:
target_dir=os.path.join(desired_dir,package_name)
os.mkdir(target_dir)
config_file_path = os.path.join(os.path.dirname(__file__), global_config.configfile)
config_file = open(config_file_path, 'r')
Expand Down
4 changes: 2 additions & 2 deletions test/.coverage-badge.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 17 additions & 3 deletions test/test_main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import Match
from functionhub.main import fuhub
from click.testing import CliRunner
from click.exceptions import ClickException
import pytest
import os
import shutil

Expand Down Expand Up @@ -43,6 +41,7 @@ def test_upload_package():
assert result.output == f"upload function hello-world to repository my-public-functions\nauthentication error\n"
#CLEANUP
os.remove(f"{test_folder}.zip")


def test_upload_nonexisting_package():
runner = CliRunner()
Expand All @@ -56,4 +55,19 @@ def test_upload_package_with_missing_config_file():
result = runner.invoke(fuhub, ['upload',f"{test_folder}.zip"])
assert result.output == "Error: Config file could not be found\n"
#CLEANUP
os.remove(f"{test_folder}.zip")
os.remove(f"{test_folder}.zip")

def test_upload_package_wrong_config():
missing_option = 'runtime'
runner = CliRunner()
runner.invoke(fuhub, ['package',test_folder])
with open('example/config.ini','r') as org_conf:
with open('example/config2.ini','w') as new_conf:
for line in org_conf.readlines():
if missing_option not in line:
new_conf.write(line)
result = runner.invoke(fuhub, ['-f', 'example/config2.ini', 'upload',f"{test_folder}.zip"])

assert result.output == f"No option '{missing_option}' in section: 'RUNTIME'\n"
#CLEANUP
os.remove("example/config2.ini")

0 comments on commit 8a0954f

Please sign in to comment.