@@ -244,14 +244,11 @@ def test_no_redirect_login_to_logout(self):
244
244
self .assertTrue (get_user (self .client ).is_authenticated )
245
245
246
246
247
- """
248
- ---------------------------------------------------
249
- Tests for dashboard view
250
- ---------------------------------------------------
251
- """
252
-
253
-
254
247
class DashboardTestCase (UnitTest ):
248
+ """
249
+ Tests for the dashboard homepage.
250
+ """
251
+
255
252
def setUp (self ):
256
253
super ().setUp (create_user = True )
257
254
@@ -304,130 +301,12 @@ def test_all_compendium_entries_visible_on_dashboard(self):
304
301
self .assertEqual (entry ["owner" ], self .user )
305
302
306
303
307
- """
308
- ---------------------------------------------------
309
- Tests for adding new tags and compendium entries
310
- ---------------------------------------------------
311
- """
312
-
313
-
314
- @tag ("compendium-entries" )
315
- class AddNewCompendiumEntryTestCase (UnitTest ):
316
- def setUp (self ):
317
- super ().setUp (preauth = True )
318
- self .new_entry_page = reverse ("research new article" )
319
-
320
- # Add three tags for testing purposes
321
- for tagname in ("test_tag_A" , "test_tag_B" , "test_tag_C" ):
322
- if not CompendiumEntryTag .objects .filter (tagname = tagname ).exists ():
323
- CompendiumEntryTag .objects .create (tagname = tagname )
324
-
325
- def test_page_templates (self ):
326
- # Ensure that the page uses the correct templates in its response
327
- response = self .client .get (self .new_entry_page )
328
- self .assertTemplateUsed ("dashboard_base.html" )
329
- self .assertTemplateUsed ("new_article.html" )
330
-
331
- @tag ("tags" )
332
- def test_add_new_compendium_entry (self ):
333
- self .assertEqual (len (CompendiumEntry .objects .all ()), 0 )
334
-
335
- # Retrieve the tag ID for "test_tag_B"
336
- tag_id = CompendiumEntryTag .objects .get (tagname = "test_tag_B" ).id
337
-
338
- # publisher information
339
- publisher = random_username (self .rd )
340
-
341
- # published date
342
- year = random .randrange (1900 , datetime .date .today ().year )
343
- month = random .randrange (1 , 12 )
344
- day = random .randrange (1 , 31 )
345
-
346
- # Send POST data to the URL to create a new entry and ensure that
347
- # the entry was created correctly.
348
- data = {
349
- "title" : "New compendium entry" ,
350
- "abstract" : "Abstract for new entry" ,
351
- "url" : "https://example.com" ,
352
- "tags" : [tag_id ],
353
- "publisher_text" : publisher ,
354
- "year" : year ,
355
- "month" : month ,
356
- "day" : day ,
357
- "edit-entry" : "" ,
358
- }
359
- response = self .client .post (self .new_entry_page , data )
360
- self .assertTrue (len (CompendiumEntry .objects .all ()), 1 )
361
-
362
- entry = CompendiumEntry .objects .get (title = "New compendium entry" )
363
- self .assertEqual (entry .owner , self .user )
364
- self .assertEqual (entry .title , "New compendium entry" )
365
- self .assertEqual (entry .abstract , "Abstract for new entry" )
366
- self .assertEqual (entry .url , "https://example.com" )
367
- self .assertEqual (len (entry .tags .all ()), 1 )
368
- self .assertEqual (entry .tags .get ().tagname , "test_tag_B" )
369
- self .assertEqual (entry .publisher .publishername , publisher )
370
- self .assertEqual (entry .year , year )
371
- self .assertEqual (entry .month , month )
372
- self .assertEqual (entry .day , day )
373
-
374
- @tag ("tags" )
375
- def test_add_compendium_entry_with_multiple_tags (self ):
376
- """Create a CompendiumEntry with multiple tags"""
377
- self .assertEqual (len (CompendiumEntry .objects .all ()), 0 )
378
-
379
- # Retrieve tag IDs for "test_tag_B" and "test_tag_C"
380
- id_A = CompendiumEntryTag .objects .get (tagname = "test_tag_A" ).id
381
- id_C = CompendiumEntryTag .objects .get (tagname = "test_tag_C" ).id
382
-
383
- # Send POST data with multiple tag IDs
384
- data = {
385
- "title" : "New compendium entry" ,
386
- "tags" : [id_A , id_C ],
387
- "edit-entry" : "" ,
388
- }
389
- self .client .post (self .new_entry_page , data )
390
- self .assertEqual (len (CompendiumEntry .objects .all ()), 1 )
391
-
392
- entry = CompendiumEntry .objects .get (title = "New compendium entry" )
393
- self .assertEqual (len (entry .tags .all ()), 2 )
394
- self .assertTrue (entry .tags .filter (tagname = "test_tag_A" ).exists ())
395
- self .assertFalse (entry .tags .filter (tagname = "test_tag_B" ).exists ())
396
- self .assertTrue (entry .tags .filter (tagname = "test_tag_C" ).exists ())
397
-
398
- def test_attempt_to_create_entry_with_empty_title (self ):
399
- """New entries must have a title"""
400
- self .assertEqual (len (CompendiumEntry .objects .all ()), 0 )
401
- tag_id = CompendiumEntryTag .objects .get (tagname = "test_tag_A" ).id
402
-
403
- ### Try to create an entry without a title
404
- data = {
405
- "tags" : [tag_id ],
406
- }
407
- response = self .client .post (self .new_entry_page , data )
408
- self .assertEqual (len (CompendiumEntry .objects .all ()), 0 )
409
-
410
- ### Try to create an entry with an empty title
411
- data = {
412
- "title" : "" ,
413
- "tags" : [tag_id ],
414
- }
415
- response = self .client .post (self .new_entry_page , data )
416
- self .assertEqual (len (CompendiumEntry .objects .all ()), 0 )
417
-
418
- def test_attempt_to_create_entry_without_tags (self ):
419
- """New entries must have _at least_ one tag"""
420
- self .assertEqual (len (CompendiumEntry .objects .all ()), 0 )
421
-
422
- data = {
423
- "title" : "New compendium entry" ,
424
- }
425
- self .client .post (self .new_entry_page , data )
426
- self .assertEqual (len (CompendiumEntry .objects .all ()), 0 )
427
-
428
-
429
304
@tag ("compendium-entries" , "tags" )
430
305
class NewTagTestCase (UnitTest ):
306
+ """
307
+ Tests for the view to add a new tag to the compendium.
308
+ """
309
+
431
310
def setUp (self ):
432
311
super ().setUp (preauth = True )
433
312
self .new_tag_page = reverse ("research add tag" )
0 commit comments