Skip to content

Commit

Permalink
Merge pull request #38 from Ostorlab/fix/unit_test
Browse files Browse the repository at this point in the history
Fix failing unit tests.
  • Loading branch information
3asm authored Jan 21, 2024
2 parents 617abfe + 4b5c03c commit 03d249b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 5 additions & 2 deletions agent/tracker_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ def _set_scan_progress(self, progress: str):
"""
with models.Database() as session:
scan = session.query(models.Scan).get(os.getenv("UNIVERSE"))
scan.progress = progress
session.commit()
if scan is not None:
scan.progress = progress
session.commit()
else:
logger.error("Scan for %s does not exist.", os.getenv("UNIVERSE"))


if __name__ == "__main__":
Expand Down
8 changes: 2 additions & 6 deletions tests/agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
from unittest import mock

import pytest
from ostorlab.runtimes.local.models import models

from agent import data_queues
Expand Down Expand Up @@ -36,7 +35,6 @@ def testTrackerAgentCheckQueueNotEmpty_whenQueueIsEmpty_returnFalse():
assert data_queues.is_queue_not_empty(dummy_queue) is False


@pytest.mark.asyncio
@mock.patch(
"ostorlab.runtimes.local.models.models.ENGINE_URL",
"sqlite:////tmp/ostorlab_db1.sqlite",
Expand All @@ -53,7 +51,6 @@ def testTrackerAgentLogic_whenQueuesAreNotEmpty_killProcessesAndSend4Messages(
So, it should timeout, emits a message : post_scan_done_timeout,
and another message : post_scan_done.
"""
# breakpoint()
path = "http://guest:guest@localhost:15672/api/queues/%2F"
requests_mock.get(
path,
Expand All @@ -65,7 +62,7 @@ def testTrackerAgentLogic_whenQueuesAreNotEmpty_killProcessesAndSend4Messages(
mocker.patch("agent.tracker_agent.universe.kill_universe", return_value=None)
mocker.patch.object(data_queues, "SLEEP_SEC", 0.01)

tracker_agent.run()
tracker_agent.start()

assert len(agent_mock) == 4
assert agent_mock[0].selector == "v3.report.event.scan.timeout"
Expand All @@ -79,7 +76,6 @@ def testTrackerAgentLogic_whenQueuesAreNotEmpty_killProcessesAndSend4Messages(
)


@pytest.mark.asyncio
def testTrackerLogic_whenQueuesAreEmpty_send2messages(
mocker, agent_mock, tracker_agent, requests_mock
):
Expand All @@ -99,7 +95,7 @@ def testTrackerLogic_whenQueuesAreEmpty_send2messages(
],
)

tracker_agent.run()
tracker_agent.start()

assert len(agent_mock) == 2
assert agent_mock[0].selector == "v3.report.event.scan.done"
Expand Down

0 comments on commit 03d249b

Please sign in to comment.