@@ -58,3 +58,59 @@ def test_game__hidden_games_visible_to_moderators(client_moderator, create_cnc_g
5858 assert response .status_code == status .HTTP_200_OK
5959
6060 assert str (invisible .id ) in [r ["id" ] for r in response .data ["results" ]]
61+
62+
63+ def test_game__cannot_be_deleted (client_god , create_cnc_game ):
64+ """C&C games don't change much these days, so there's no real reason to expose deletions to the API.
65+
66+ If you are a future person and are adding more capabilities to the game endpoints, you can just alter this test
67+ to use the ``client_user`` fixture to test that user's can't delete games.
68+ """
69+ my_game = create_cnc_game ()
70+
71+ response = client_god .delete (f"/games/{ my_game .id } /" , data_type = ui_objects .ResultResponseData )
72+
73+ assert response .status_code == status .HTTP_405_METHOD_NOT_ALLOWED
74+
75+
76+ def test_game__cannot_be_edited_by_non_admins (client_moderator , create_cnc_game ):
77+ """C&C games don't change much so we'll only allow admins to edit them via the API.
78+
79+ Maybe in the future we can allow mod authors to edit their own mod entries."""
80+ my_game = create_cnc_game ()
81+
82+ response = client_moderator .post (f"/games/{ my_game .id } /" , data_type = ui_objects .ResultResponseData )
83+
84+ assert response .status_code == status .HTTP_403_FORBIDDEN
85+
86+
87+ def test_game__admins_can_edit (client_admin , create_cnc_game ):
88+ """Admins should be able to edit a few non-structural things for games via the API."""
89+ my_game = create_cnc_game ()
90+ new_full_name = f"{ my_game .full_name } (Steam version)"
91+ new_visibility = not my_game .is_visible
92+ new_allow_public_uploads = not my_game .allow_public_uploads
93+ new_compatible_with_parent_maps = not my_game .compatible_with_parent_maps
94+ original_is_mod = my_game .is_mod
95+ original_slug = my_game .slug
96+
97+ data = {
98+ "full_name" : new_full_name ,
99+ "is_visible" : new_visibility ,
100+ "allow_public_uploads" : new_allow_public_uploads ,
101+ "compatible_with_parent_maps" : new_compatible_with_parent_maps ,
102+ "is_mod" : not original_is_mod , # should not change, not editable via API.
103+ "slug" : "wontwork" , # should not change, not editable via API.
104+ }
105+
106+ response = client_admin .patch (f"/games/{ my_game .id } /" , data = data , data_type = ui_objects .ResultResponseData )
107+
108+ assert response .status_code == status .HTTP_200_OK
109+ my_game .refresh_from_db ()
110+
111+ assert my_game .full_name == new_full_name
112+ assert my_game .is_visible == new_visibility
113+ assert my_game .allow_public_uploads == new_allow_public_uploads
114+ assert my_game .compatible_with_parent_maps == new_compatible_with_parent_maps
115+ assert my_game .is_mod == original_is_mod , "should not be changeable via the API."
116+ assert my_game .slug == original_slug , "should not be changeable via the API."
0 commit comments