Skip to content

Commit

Permalink
added testign
Browse files Browse the repository at this point in the history
  • Loading branch information
naesheim committed Feb 26, 2021
1 parent e68d5a1 commit cc5f58c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
14 changes: 3 additions & 11 deletions functionhub/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ def upload_function(global_config, zip_file):
else:
click.secho("Size limitation, consider a paid subscription",fg='red')

except KeyError as ke:
except Error as ke:
click.secho(f"{ke}",fg='red')
except NoOptionError as noe:
click.secho(f"{noe}",fg='red')
except requests.exceptions.RequestException as re:
click.secho(f"{re.message}",fg='red')

@fuhub.command(name='create')
@click.argument('package_name', type=click.Path(exists=False))
Expand All @@ -107,12 +103,8 @@ def create_function(global_config, package_name, desired_dir):
raise click.ClickException("Project already exist")
else:
os.rmdir(target_dir)
raise click.ClickException(err)

@fuhub.command(name='package')
@click.argument('package_dir', type=click.Path(exists=True, resolve_path=True,))
@click.argument('package_dir', type=click.Path(exists=True, resolve_path=True))
def package_function(package_dir):
if os.path.isdir(package_dir):
shutil.make_archive(package_dir, 'zip', package_dir)
else:
raise click.ClickException(f"folder {package_dir} cannot be found")
shutil.make_archive(package_dir, 'zip', package_dir)
Binary file modified test/.coverage
Binary file not shown.
29 changes: 23 additions & 6 deletions test/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
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

test_folder = 'example'

Expand All @@ -8,6 +13,8 @@ def test_create_folder():
result = runner.invoke(fuhub, ['create','test'])

assert result.output == f"project test successfully created\n"
#CLEANUP
shutil.rmtree('test')

def test_create_existing_folder():
runner = CliRunner()
Expand All @@ -20,21 +27,31 @@ def test_create_package():
result = runner.invoke(fuhub, ['package',test_folder])

assert result.exit_code == 0
#CLEANUP
os.remove(f"{test_folder}.zip")

def test_create_nonexisting_package():
runner = CliRunner()
result = runner.invoke(fuhub, ['package', 'nofolder'])
assert result.exit_code == 2

def test_upload_package():
runner = CliRunner()
result = runner.invoke(fuhub, ['package', 'nofolder'])
runner.invoke(fuhub, ['package',test_folder])
result = runner.invoke(fuhub, ['-f', 'example/config.ini', 'upload',f"{test_folder}.zip"])

assert result.exception
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_package():
def test_upload_nonexisting_package():
runner = CliRunner()
result = runner.invoke(fuhub, ['-f', 'example/config.ini', 'upload',f"{test_folder}.zip"])

assert result.output == f"upload function hello-world to repository my-public-functions\nSize limitation, consider a paid subscription\n"
assert result.exception

def test_upload_package_with_missing_config_file():
runner = CliRunner()
runner.invoke(fuhub, ['package',test_folder])
result = runner.invoke(fuhub, ['upload',f"{test_folder}.zip"])

assert result.exception
assert result.output == "Error: Config file could not be found\n"

0 comments on commit cc5f58c

Please sign in to comment.