Skip to content

Commit

Permalink
improve output and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgstew committed Oct 24, 2021
1 parent 702be5a commit c4ae2d1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
python-version: 3.8
- name: Install requirements
run: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Run Tests - Source
run: python tests/tests.py
- name: Install build tools
run: pip install setuptools wheel build
- name: Run build
Expand All @@ -52,3 +54,5 @@ jobs:
- name: Test python bescli
shell: bash
run: python -m bescli ls logout clear error_count exit
- name: Run Tests - Pip
run: python tests/tests.py --test_pip
12 changes: 6 additions & 6 deletions src/bescli/bescli.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def do_login(self, user=None):
else:
self.perror("Login Error!")

def do_logout(self, arg):
def do_logout(self, arg=None):
"""Logout and clear session"""
if self.bes_conn:
self.bes_conn.logout()
Expand Down Expand Up @@ -270,7 +270,7 @@ def do_ls(self, arg=None):

def do_error_count(self, arg=None):
"""Output the number of errors"""
self.poutput(self.num_errors)
self.poutput(f"Error Count: {self.num_errors}")

def do_exit(self, arg=None):
"""Exit this application"""
Expand All @@ -288,13 +288,13 @@ def do_query(self, statement):
if statement.raw:
# get everything after `query `
rel_text = statement.raw.split(" ", 1)[1]
self.poutput("Q: " + rel_text)
self.poutput(f"Q: {rel_text}")
rel_result = self.bes_conn.session_relevance_string(rel_text)
self.poutput(rel_result)
self.poutput(f"A: {rel_result}")

def do_version(self, statement):
def do_version(self, statement=None):
"""output version of besapi"""
print(__version__)
self.poutput(f"besapi version: {__version__}")

def do_export_site(self, site_path):
"""export site contents to current folder"""
Expand Down
54 changes: 45 additions & 9 deletions tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,55 @@
"""
Test besapi
"""
import argparse
import os
import subprocess
import sys

# set working directory to folder this file is in:
os.chdir(os.path.dirname(os.path.abspath(__file__)))
# check for --test_pip arg
parser = argparse.ArgumentParser()
parser.add_argument(
"--test_pip", help="to test package installed with pip", action="store_true"
)
args = parser.parse_args()

# set working directory to src folder in parent folder
os.chdir("../src")
if not args.test_pip:
# add module folder to import paths for testing local src
sys.path.append(
os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "src")
)
# reverse the order so we make sure to get the local src module
sys.path.reverse()

import besapi
import bescli


print(f"besapi version: {besapi.__version__}")

if os.name == "nt":
subprocess.run(
'CMD /C python -m besapi ls clear ls conf "query number of bes computers" exit',
check=True,
)
bigfix_cli = bescli.bescli.BESCLInterface()

# just make sure these don't throw errors:
bigfix_cli.do_ls()
bigfix_cli.do_clear()
bigfix_cli.do_ls()
bigfix_cli.do_logout()
bigfix_cli.do_error_count()
bigfix_cli.do_version()
bigfix_cli.do_conf()

# this should really only run if the config file is present:
if bigfix_cli.bes_conn:
print(bigfix_cli.bes_conn.session_relevance_string("number of bes computers"))

# set working directory to folder this file is in:
os.chdir(os.path.dirname(os.path.abspath(__file__)))

# set working directory to src folder in parent folder
os.chdir("../src")

if os.name == "nt":
subprocess.run(
'CMD /C python -m besapi ls clear ls conf "query number of bes computers" version error_count exit',
check=True,
)

0 comments on commit c4ae2d1

Please sign in to comment.