Skip to content

Commit

Permalink
✅ [#4993] Fix existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Jan 7, 2025
1 parent 80b9f97 commit dbb75e3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_it_performs_simple_get(self, m):
)
)

result = perform_service_fetch(var, {})
result = perform_service_fetch(var.service_fetch_configuration, {})
value = result.value

self.assertEqual(value["url"], "https://httpbin.org/get")
Expand All @@ -75,7 +75,7 @@ def test_it_can_construct_service_endpoint_path_parameters_from_a_well_behaved_u

with requests_mock.Mocker() as m:
m.get(requests_mock.ANY, json={})
perform_service_fetch(var, context)
perform_service_fetch(var.service_fetch_configuration, context)
request = m.last_request

self.assertEqual(request.url, "https://httpbin.org/delay/6")
Expand All @@ -93,7 +93,7 @@ def test_substitutions_all_happen_at_once(self):

with requests_mock.Mocker() as m:
m.get(requests_mock.ANY, json={})
perform_service_fetch(var, context)
perform_service_fetch(var.service_fetch_configuration, context)
request = m.last_request

self.assertEqual(request.url, "https://httpbin.org/delay/6.5")
Expand All @@ -103,7 +103,7 @@ def test_substitutions_all_happen_at_once(self):

with requests_mock.Mocker() as m:
m.get(requests_mock.ANY, json={})
perform_service_fetch(var, context)
perform_service_fetch(var.service_fetch_configuration, context)
request = m.last_request

self.assertEqual(request.url, "https://httpbin.org/delay/6.%7B%7Bseconds%7D%7D")
Expand All @@ -127,7 +127,7 @@ def test_it_can_construct_simple_path_parameters_from_any_input(self, field_valu

with requests_mock.Mocker() as m:
m.get(requests_mock.ANY, json={})
_ = perform_service_fetch(var, context)
_ = perform_service_fetch(var.service_fetch_configuration, context)
request = m.last_request

expected_stem_length = len("https://httpbin.org/delay/")
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_raises_suspicious_operation_on_double_dot_input(self):
)

with self.assertRaises(SuspiciousOperation):
perform_service_fetch(var, context)
perform_service_fetch(var.service_fetch_configuration, context)

# TODO
@tag("gh-2745")
Expand Down Expand Up @@ -204,7 +204,7 @@ def test_it_can_construct_simple_query_parameters(self, field_value):
.url,
json={},
)
_ = perform_service_fetch(var, context)
_ = perform_service_fetch(var.service_fetch_configuration, context)
request = m.last_request

# it shouldn't change other parts of the request
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_it_can_construct_multiple_simple_query_parameters(
.url,
json={},
)
_ = perform_service_fetch(var, context)
_ = perform_service_fetch(var.service_fetch_configuration, context)
request = m.last_request

# it shouldn't change other parts of the request
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_it_sends_request_headers(self, m):
)
)

_ = perform_service_fetch(var, {})
_ = perform_service_fetch(var.service_fetch_configuration, {})
request_headers = m.last_request.headers

self.assertIn(("X-Brony-Identity", "Jumper"), request_headers.items())
Expand All @@ -295,7 +295,7 @@ def test_it_can_construct_simple_header_parameters(self):
)
with requests_mock.Mocker(case_sensitive=True) as m:
m.get("https://httpbin.org/cache", json={})
_ = perform_service_fetch(var, context)
_ = perform_service_fetch(var.service_fetch_configuration, context)
request = m.last_request

self.assertIn(("If-None-Match", "x"), request.headers.items())
Expand All @@ -318,7 +318,7 @@ def test_it_never_sends_bad_headers_regardless_of_what_people_submit(
m.get("https://httpbin.org/cache", json={})
try:
# when we bind
_ = perform_service_fetch(var, context)
_ = perform_service_fetch(var.service_fetch_configuration, context)
except Exception: # XXX unclear what exception to expect
# either raise an exception
return
Expand Down Expand Up @@ -352,7 +352,7 @@ def test_it_sends_the_body_as_json(self, m):
)
)

_ = perform_service_fetch(var, {})
_ = perform_service_fetch(var.service_fetch_configuration, {})
request = m.last_request

self.assertIn(("Content-Type", "application/json"), request.headers.items())
Expand All @@ -371,7 +371,7 @@ def test_it_applies_jsonlogic_on_response(self, m):
)
)

result = perform_service_fetch(var, {})
result = perform_service_fetch(var.service_fetch_configuration, {})
value = result.value

self.assertEqual(value, "https://httpbin.org/get")
Expand All @@ -389,7 +389,7 @@ def test_it_applies_jq_on_response(self, m):
)
)

result = perform_service_fetch(var, {})
result = perform_service_fetch(var.service_fetch_configuration, {})
value = result.value

self.assertEqual(value, "https://httpbin.org/get")
Expand All @@ -409,13 +409,7 @@ def test_it_does_not_hang_on_infinite_jq_recursion(self, m):
)
)

result = perform_service_fetch(var, {})
result = perform_service_fetch(var.service_fetch_configuration, {})
value = result.value

self.assertEqual(value, "https://httpbin.org/get")

def test_it_raises_value_errors(self):
var = FormVariableFactory.build()

with self.assertRaises(ValueError):
perform_service_fetch(var, {})
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,35 @@ def test_requests_cache_timeout(self, m):

self.assertEqual(len(m.request_history), 2)
self.assertEqual(m.request_history[-1].url, "https://httpbin.org/get")

def test_it_logs_value_error_if_no_service_fetch_config(self):
submission = SubmissionFactory.from_components([])
FormVariableFactory.create(
key="someVariable",
form=submission.form,
service_fetch_configuration=None,
)

logic_rule = FormLogicFactory.create(
form=submission.form,
json_logic_trigger=True,
actions=[
{
"variable": "someVariable",
"action": {
"name": "Fetch some field from some server",
"type": LogicActionTypes.fetch_from_service,
},
}
],
)

with self.assertLogs(
"openforms.submissions.logic.log_utils", level="ERROR"
) as cm:
evaluate_form_logic(
submission, submission.submissionstep_set.first(), submission.data
)
self.assertIn(
f"Error in rule {logic_rule.pk}: evaluation of {{}} failed.", cm.output[0]
)

0 comments on commit dbb75e3

Please sign in to comment.