Skip to content

Commit

Permalink
test(agent): Update tests for updated behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurali27 committed Jan 5, 2025
1 parent 542e3fb commit c7f811e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions press/tests/test_agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2024, Frappe and contributors
# For license information, please see license.txt

from unittest.mock import Mock

import frappe
import requests
import responses
Expand All @@ -13,9 +15,7 @@
from press.press.doctype.server.test_server import create_test_server


def create_test_agent_request_failure(
server, traceback="Traceback", error="Error", failure_count=1
):
def create_test_agent_request_failure(server, traceback="Traceback", error="Error", failure_count=1):
fields = {
"server_type": server.doctype,
"server": server.name,
Expand All @@ -24,9 +24,7 @@ def create_test_agent_request_failure(
"failure_count": failure_count,
}

return frappe.new_doc("Agent Request Failure", **fields).insert(
ignore_permissions=True
)
return frappe.new_doc("Agent Request Failure", **fields).insert(ignore_permissions=True)


class TestAgent(FrappeTestCase):
Expand Down Expand Up @@ -64,7 +62,9 @@ def test_request_failure_creates_failure_record(self):
failures_before = frappe.db.count("Agent Request Failure")

agent = Agent(server.name, server.doctype)
self.assertRaises(requests.ConnectTimeout, agent.request, "GET", "ping")
fake_job = Mock()
fake_job.name = "1234"
self.assertRaises(requests.ConnectTimeout, agent.request, "GET", "ping", agent_job=fake_job)

failures_after = frappe.db.count("Agent Request Failure")
self.assertEqual(failures_after, failures_before + 1)
Expand All @@ -85,7 +85,9 @@ def test_request_skips_after_past_failure(self):
)

agent = Agent(server.name, server.doctype)
self.assertRaises(requests.ConnectTimeout, agent.request, "GET", "ping")
fake_job = Mock()
fake_job.name = "1234"
self.assertRaises(requests.ConnectTimeout, agent.request, "GET", "ping", agent_job=fake_job)
self.assertRaises(AgentRequestSkippedException, agent.request, "GET", "ping")

def test_failure_record_asks_to_skip_requests(self):
Expand Down

0 comments on commit c7f811e

Please sign in to comment.