@@ -909,6 +909,48 @@ def test_build_read_and_write_endpoints_for_build_api_token(self):
909
909
resp = client .patch (f"/api/v2/build/{ build .pk } /" )
910
910
self .assertEqual (resp .status_code , 404 )
911
911
912
+ def test_build_commands_duplicated_command (self ):
913
+ """Sending the same request twice should only create one BuildCommandResult."""
914
+ project = get (
915
+ Project ,
916
+ language = "en" ,
917
+ )
918
+ version = project .versions .first ()
919
+ build = Build .objects .create (project = project , version = version )
920
+
921
+ self .assertEqual (BuildCommandResult .objects .count (), 0 )
922
+
923
+ client = APIClient ()
924
+ _ , build_api_key = BuildAPIKey .objects .create_key (project )
925
+ client .credentials (HTTP_AUTHORIZATION = f"Token { build_api_key } " )
926
+
927
+ now = timezone .now ()
928
+ start_time = now - datetime .timedelta (seconds = 5 )
929
+ end_time = now
930
+
931
+ data = {
932
+ "build" : build .pk ,
933
+ "command" : "git status" ,
934
+ "description" : "Git status" ,
935
+ "exit_code" : 0 ,
936
+ "start_time" : start_time ,
937
+ "end_time" : end_time ,
938
+ }
939
+
940
+ response = client .post (
941
+ "/api/v2/command/" ,
942
+ data ,
943
+ format = "json" ,
944
+ )
945
+ self .assertEqual (response .status_code , 201 )
946
+ response = client .post (
947
+ "/api/v2/command/" ,
948
+ data ,
949
+ format = "json" ,
950
+ )
951
+ self .assertEqual (response .status_code , 201 )
952
+ self .assertEqual (BuildCommandResult .objects .count (), 1 )
953
+
912
954
def test_build_commands_read_only_endpoints_for_normal_user (self ):
913
955
user_normal = get (User , is_staff = False )
914
956
user_admin = get (User , is_staff = True )
0 commit comments