Skip to content

Commit

Permalink
add python script test
Browse files Browse the repository at this point in the history
  • Loading branch information
bitkarrot committed Sep 15, 2023
1 parent 86c0831 commit 63d02b3
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tests/cron_handler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
sys.path.insert(0,'..')
from cron_handler import CronHandler
from utils import get_env_data_as_dict
import os

## TODO make this a legit pytest
## UNIT TEST ALL THE THINGS!!
Expand All @@ -20,7 +21,7 @@ async def main():
env_vars = {'SHELL': '/usr/bin/bash', 'API_URL': 'http://localhost:8000'}

# unique job id number to be placed in comment
comment = "cron now ls"
comment = "cron python script"
echo_comment = "cron now echo"

now = dt.datetime.now()
Expand All @@ -29,17 +30,17 @@ async def main():
ch = CronHandler(username)

# regular cron job with comment
response = await ch.new_job("ls", "* * * * *", comment=comment)
response = await ch.new_job("ls", "15 * * * *", comment=comment)
print(response)

# regular cron job with aliase
response = await ch.new_job("ls", "@hourly", comment=comment)
# regular cron job with alias
dir_path = os.path.dirname(os.path.realpath(__file__))
response = await ch.new_job(f"/usr/bin/python3 {dir_path}/../log_handler.py", "* * * * *", comment=comment)
print(response)


# cron job with env vars
response = await ch.new_job_with_env("echo", "* * * * *", comment=echo_comment, env=env_vars)
print(response)
# response = await ch.new_job_with_env("echo", "@hourly", comment=echo_comment, env=env_vars)
# print(response)

# enable job
print("Enable Job by Comment")
Expand Down Expand Up @@ -71,12 +72,11 @@ async def main():
# validate cron string is valid
cron_string = '@reboot'
is_valid = await ch.validate_cron_string(cron_string)
print(f'cron string {cron_string} is valid: {is_valid}')

print(f'cron string {cron_string} is valid: {is_valid}')

# set env vars
print("set env vars")
await ch.set_env_vars(env_vars)
#print("set env vars")
#await ch.set_env_vars(env_vars)

# print environment variables
print("get env vars")
Expand Down

0 comments on commit 63d02b3

Please sign in to comment.