Skip to content

Commit 329085e

Browse files
authored
Update test (#202)
1 parent 240a752 commit 329085e

1 file changed

Lines changed: 15 additions & 40 deletions

File tree

tests/core/test_challenge.py

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,8 @@ def test_exits_if_updated_files_do_not_exist(self, mock_api_constructor: MagicMo
853853
mock_api.post.assert_not_called()
854854
mock_api.delete.assert_not_called()
855855

856-
@mock.patch("ctfcli.core.challenge.Challenge.load_installed_challenges", return_value=installed_challenges)
857856
@mock.patch("ctfcli.core.challenge.API")
858-
def test_updates_hints(self, mock_api_constructor: MagicMock, *args, **kwargs):
857+
def test_updates_hints(self, mock_api_constructor: MagicMock):
859858
challenge = Challenge(
860859
self.minimal_challenge,
861860
{
@@ -868,18 +867,7 @@ def test_updates_hints(self, mock_api_constructor: MagicMock, *args, **kwargs):
868867
]
869868
},
870869
)
871-
872-
expected_challenge_payload = {
873-
"name": "Test Challenge",
874-
"category": "New Test",
875-
"description": "New Test Description",
876-
"attribution": "New Test Attribution",
877-
"type": "standard",
878-
"value": 150,
879-
"state": "hidden",
880-
"max_attempts": 0,
881-
"connection_info": None,
882-
}
870+
challenge.challenge_id = 1
883871

884872
mock_api: MagicMock = mock_api_constructor.return_value
885873
mock_api.get.return_value.json.return_value = {
@@ -889,41 +877,28 @@ def test_updates_hints(self, mock_api_constructor: MagicMock, *args, **kwargs):
889877
{"challenge_id": 1, "id": 2, "content": "old paid hint", "cost": 50, "challenge": 1},
890878
],
891879
}
880+
mock_api.post.return_value.json.return_value = {"success": True, "data": {"id": 10}}
892881

893-
challenge.sync(ignore=["files"])
894-
895-
mock_api.get.assert_has_calls(
896-
[
897-
call("/api/v1/challenges/1?view=admin"),
898-
call("/api/v1/flags"),
899-
call("/api/v1/challenges/1/topics"),
900-
call("/api/v1/tags"),
901-
call("/api/v1/hints"),
902-
],
903-
any_order=True,
904-
)
882+
challenge._delete_existing_hints()
883+
challenge._create_hints()
905884

906-
mock_api.patch.assert_has_calls(
907-
[call("/api/v1/challenges/1", json=expected_challenge_payload), call().raise_for_status()]
885+
self.assertEqual(
886+
mock_api.delete.call_args_list,
887+
[call("/api/v1/hints/1"), call("/api/v1/hints/2")],
908888
)
889+
self.assertEqual(mock_api.delete.return_value.raise_for_status.call_count, 2)
909890

910-
mock_api.post.assert_has_calls(
891+
self.assertEqual(
892+
mock_api.post.call_args_list,
911893
[
912894
call("/api/v1/hints", json={"content": "free hint", "title": "", "cost": 0, "challenge_id": 1}),
913-
call().raise_for_status(),
914895
call("/api/v1/hints", json={"content": "paid hint", "title": "", "cost": 100, "challenge_id": 1}),
915-
call().raise_for_status(),
916-
]
896+
],
917897
)
898+
self.assertEqual(mock_api.post.return_value.raise_for_status.call_count, 2)
918899

919-
mock_api.delete.assert_has_calls(
920-
[
921-
call("/api/v1/hints/1"),
922-
call().raise_for_status(),
923-
call("/api/v1/hints/2"),
924-
call().raise_for_status(),
925-
]
926-
)
900+
# no requirements — no PATCH calls expected
901+
mock_api.patch.assert_not_called()
927902

928903
@mock.patch("ctfcli.core.challenge.Challenge.load_installed_challenges", return_value=installed_challenges)
929904
@mock.patch("ctfcli.core.challenge.API")

0 commit comments

Comments
 (0)