Skip to content

Commit

Permalink
Merge pull request #36 from hhslepicka/feat/add-is_online-flag
Browse files Browse the repository at this point in the history
ENH: Add is_online property to easily determine whether we are online or not
  • Loading branch information
hhslepicka authored Mar 18, 2024
2 parents c0b8961 + 13cdfba commit 2eb0d24
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
6 changes: 6 additions & 0 deletions botcity/maestro/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,18 @@ def version(self):

@property
def timeout(self):
"""The timeout for the requests"""
return self._timeout

@timeout.setter
def timeout(self, value):
self._timeout = value

@property
def is_online(self):
"""Whether or not the object is connected to the BotCity Orchestrator portal"""
return self.access_token is not None and self.access_token != ""

def login(self, server: Optional[str] = None, login: Optional[str] = None, key: Optional[str] = None):
"""
Obtain an access token with the configured BotMaestro portal.
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ def test_login_error_in_key_none(maestro_test_to_login: BotMaestroSDK):
def test_login_success(maestro_test_to_login: BotMaestroSDK):
maestro_test_to_login.login(server=conftest.SERVER, login=conftest.LOGIN, key=conftest.KEY)
assert maestro_test_to_login.access_token
assert maestro_test_to_login.is_online
56 changes: 30 additions & 26 deletions tests/integration/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ def test_create_task(maestro: BotMaestroSDK):
"integer_to_test": 123,
"double_to_test": 1.0
}

task = maestro.create_task(activity_label="TestCI", parameters=parameters,
min_execution_date=datetime.datetime.now() + datetime.timedelta(hours=1),
priority=randint(0, 10))
min_execution_date=datetime.datetime.now() + datetime.timedelta(hours=1),
priority=randint(0, 10))
assert task


Expand All @@ -30,33 +31,36 @@ def test_interrupting_task(maestro: BotMaestroSDK, task: AutomationTask):


def test_finish_task_to_success(maestro: BotMaestroSDK, task: AutomationTask):
maestro.finish_task(
task_id=str(task.id),
message="Task Finished with Success.",
status=AutomationTaskFinishStatus.SUCCESS
)
task = maestro.get_task(task_id=str(task.id))
assert task.finish_status == AutomationTaskFinishStatus.SUCCESS
with pytest.warns(UserWarning):
maestro.finish_task(
task_id=str(task.id),
message="Task Finished with Success.",
status=AutomationTaskFinishStatus.SUCCESS
)
task = maestro.get_task(task_id=str(task.id))
assert task.finish_status == AutomationTaskFinishStatus.SUCCESS


def test_finish_task_to_partially_completed(maestro: BotMaestroSDK, task: AutomationTask):
maestro.finish_task(
task_id=str(task.id),
message="Task Finished with partially completed.",
status=AutomationTaskFinishStatus.PARTIALLY_COMPLETED
)
task = maestro.get_task(task_id=str(task.id))
assert task.finish_status == AutomationTaskFinishStatus.PARTIALLY_COMPLETED
with pytest.warns(UserWarning):
maestro.finish_task(
task_id=str(task.id),
message="Task Finished with partially completed.",
status=AutomationTaskFinishStatus.PARTIALLY_COMPLETED
)
task = maestro.get_task(task_id=str(task.id))
assert task.finish_status == AutomationTaskFinishStatus.PARTIALLY_COMPLETED


def test_finish_task_to_failed(maestro: BotMaestroSDK, task: AutomationTask):
maestro.finish_task(
task_id=str(task.id),
message="Task Finished with failed.",
status=AutomationTaskFinishStatus.FAILED
)
task = maestro.get_task(task_id=str(task.id))
assert task.finish_status == AutomationTaskFinishStatus.FAILED
with pytest.warns(UserWarning):
maestro.finish_task(
task_id=str(task.id),
message="Task Finished with failed.",
status=AutomationTaskFinishStatus.FAILED
)
task = maestro.get_task(task_id=str(task.id))
assert task.finish_status == AutomationTaskFinishStatus.FAILED

def test_finish_task_report_no_items(maestro: BotMaestroSDK, task: AutomationTask):
with pytest.warns(UserWarning, match="this task is not reporting items"):
Expand All @@ -67,9 +71,9 @@ def test_finish_task_report_no_items(maestro: BotMaestroSDK, task: AutomationTas
)
task = maestro.get_task(task_id=str(task.id))
assert task.finish_status == AutomationTaskFinishStatus.SUCCESS
assert task.total_items == 0
assert task.processed_items == 0
assert task.failed_items == 0
assert task.total_items is None
assert task.processed_items is None
assert task.failed_items is None

def test_finish_task_report_items(maestro: BotMaestroSDK, task: AutomationTask):
maestro.finish_task(
Expand Down

0 comments on commit 2eb0d24

Please sign in to comment.