@@ -93,6 +93,19 @@ def test_post_create_with_illegal_parent(self):
93
93
self .assertFalse ("object" in self .last_response .context )
94
94
self .assertFalse (Folder .objects .filter (name = folder_name ))
95
95
96
+ def test_post_create_with_duplicate_name (self ):
97
+ """
98
+ Ensure POST does not create a folder with duplicate name
99
+ """
100
+ folder_name = "Spindle"
101
+ Folder .objects .create (name = folder_name , author = self .user , modified_by = self .user )
102
+ post_args = {"name" : folder_name }
103
+ with self .login (self .user ):
104
+ response = self .post (self .create_urlname , data = post_args , follow = True )
105
+ self .response_200 (response )
106
+ self .assertTrue ("{} already exists." .format (folder_name ) in str (response .context ["form" ].errors ))
107
+ self .assertFalse ("object" in self .last_response .context )
108
+
96
109
def test_detail (self ):
97
110
"""
98
111
Ensure we can see folder detail.
@@ -301,6 +314,20 @@ def test_post_create_with_illegal_parent(self):
301
314
self .assertFalse ("object" in self .last_response .context )
302
315
self .assertFalse (Document .objects .filter (name = simple_file .name ))
303
316
317
+ def test_post_create_with_duplicate_name (self ):
318
+ """
319
+ Ensure POST does not create a document with duplicate name
320
+ """
321
+ simple_file = SimpleUploadedFile ("delicious.txt" , self .file_contents )
322
+ Document .objects .create (name = "delicious.txt" , author = self .user , file = simple_file , modified_by = self .user )
323
+ simple_file = SimpleUploadedFile ("delicious.txt" , self .file_contents )
324
+ post_args = {"name" : "file" , "file" : simple_file }
325
+ with self .login (self .user ):
326
+ response = self .post (self .create_urlname , data = post_args , follow = True )
327
+ self .response_200 (response )
328
+ self .assertTrue ("delicious.txt already exists." in str (response .context ["form" ].errors ))
329
+ self .assertFalse ("object" in self .last_response .context )
330
+
304
331
def test_detail (self ):
305
332
"""
306
333
Ensure we can see document detail.
0 commit comments