@@ -501,3 +501,199 @@ def test_remaining_eligible_companions(self):
501501
502502 # Non-companion should not be in eligible companions list
503503 assert self .user_three not in remaining_eligible_companions
504+
505+
506+
507+
508+ class ActivityAddCommentViewTest (TestCase ):
509+ def setUp (self ):
510+ self .
companion_one = User .
objects .
create_user (
"[email protected] " ,
"test12345" )
511+ self .
companion_two = User .
objects .
create_user (
"[email protected] " ,
"test12345" )
512+
513+ self .circle = Circle .objects .create (name = "Test circle" )
514+
515+ Companion .objects .create (
516+ circle = self .circle ,
517+ user = self .companion_one ,
518+ )
519+ Companion .objects .create (
520+ circle = self .circle ,
521+ user = self .companion_two ,
522+ )
523+ self .user_without_circle = User .objects .create_user (
524+ 525+ "test12345" ,
526+ )
527+
528+ self .circle_with_companion = Circle .objects .create (name = "Companion circle" )
529+ self .companionship_through = Companion .objects .create (
530+ circle = self .circle_with_companion ,
531+ user = self .companion_one ,
532+ is_organizer = True ,
533+ )
534+ self .activity_for_circle_with_companion = Activity .objects .create (
535+ activity_type = Activity .ActivityTypeChoices .APPOINTMENT ,
536+ activity_date = "2022-10-23" ,
537+ circle = self .circle_with_companion ,
538+ )
539+
540+ def test_anonymous_add_comment (self ):
541+ """Anonymous user should not be authorized to add comment"""
542+ response = self .client .post (
543+ reverse ("activity-add-comment" ,
544+ kwargs = {
545+ "activity_id" : self .activity_for_circle_with_companion .id ,
546+ }),
547+ {
548+ "activity_id" : self .activity_for_circle_with_companion .id ,
549+ },
550+ )
551+
552+ self .assertEqual (response .status_code , HTTPStatus .FORBIDDEN )
553+
554+ def test_authenticated_non_companion_add_comment (self ):
555+ """Authenticated user who is not companion should not be authorized to add comment"""
556+ self .client .force_login (self .user_without_circle )
557+
558+ response = self .client .post (
559+ reverse ("activity-add-comment" ,
560+ kwargs = {
561+ "activity_id" : self .activity_for_circle_with_companion .id ,
562+ }),
563+ {
564+ "activity_id" : self .activity_for_circle_with_companion .id ,
565+ "user_comment" : "HELLO" ,
566+ "user_id" : self .companion_one .id ,
567+ },
568+ )
569+
570+ self .assertEqual (response .status_code , HTTPStatus .FORBIDDEN )
571+
572+
573+
574+ def test_authenticated_organizer_add_comment (self ):
575+ """Organizer of activity should be able to add comemnt"""
576+ self .client .force_login (self .companion_one )
577+
578+ response = self .client .post (
579+ reverse (
580+ "activity-add-comment" ,
581+ kwargs = {
582+ "activity_id" : self .activity_for_circle_with_companion .id ,
583+ },
584+ ),
585+ {
586+ "activity_id" : self .activity_for_circle_with_companion .id ,
587+ "user_comment" : "HELLO" ,
588+ "user_id" : self .companion_one .id ,
589+ },
590+ )
591+
592+ self .assertEqual (response .status_code , HTTPStatus .FOUND )
593+
594+ def test_participant_add_comment (self ):
595+ """Participant of activity should be able to add comemnt"""
596+ self .client .force_login (self .companion_one )
597+ self .client .post (
598+ reverse (
599+ "activity-add-participant" ,
600+ kwargs = {
601+ "activity_id" : self .activity_for_circle_with_companion .id ,
602+ },
603+ ),
604+ {
605+ "user_id" : self .companion_two .id ,
606+ },
607+ )
608+
609+ response = self .client .post (
610+ reverse (
611+ "activity-add-comment" ,
612+ kwargs = {
613+ "activity_id" : self .activity_for_circle_with_companion .id ,
614+ },
615+ ),
616+ {
617+ "activity_id" : self .activity_for_circle_with_companion .id ,
618+ "user_comment" : "HELLO" ,
619+ "user_id" : self .companion_two .id ,
620+ },
621+ )
622+
623+ self .assertEqual (response .status_code , HTTPStatus .FOUND )
624+
625+
626+
627+
628+
629+ class ActivityCommentViewTest (TestCase ):
630+ def setUp (self ):
631+ self .
companion_one = User .
objects .
create_user (
"[email protected] " ,
"test12345" )
632+ self .
companion_two = User .
objects .
create_user (
"[email protected] " ,
"test12345" )
633+
634+ self .circle = Circle .objects .create (name = "Test circle" )
635+
636+ Companion .objects .create (
637+ circle = self .circle ,
638+ user = self .companion_one ,
639+ is_organizer = True ,
640+ )
641+ Companion .objects .create (
642+ circle = self .circle ,
643+ user = self .companion_two ,
644+ )
645+
646+ self .activity_for_circle_with_companion = Activity .objects .create (
647+ activity_type = Activity .ActivityTypeChoices .APPOINTMENT ,
648+ activity_date = "2022-11-23" ,
649+ circle = self .circle ,
650+ )
651+
652+
653+
654+ def test_anonymous_access (self ):
655+ """Anonymous user should not be authorized to view the comment page"""
656+ response = self .client .get (
657+ reverse ("activity-view-comments" ,
658+ kwargs = {
659+ "activity_id" : self .activity_for_circle_with_companion .id ,
660+ }),
661+ {
662+ "activity_id" : self .activity_for_circle_with_companion .id ,
663+ },
664+ )
665+
666+ self .assertEqual (response .status_code , HTTPStatus .FORBIDDEN )
667+
668+ def test_authenticated_access (self ):
669+ """Authorized user should be authorized to view the comment page"""
670+ self .client .force_login (self .companion_one )
671+ comment = "wow, this activity looks cool!"
672+
673+ response = self .client .post (
674+ reverse (
675+ "activity-add-comment" ,
676+ kwargs = {
677+ "activity_id" : self .activity_for_circle_with_companion .id ,
678+ },
679+ ),
680+ {
681+ "activity_id" : self .activity_for_circle_with_companion .id ,
682+ "user_comment" : comment ,
683+ "user_id" : self .companion_one .id ,
684+ },
685+ )
686+ response = self .client .get (
687+ reverse (
688+ "activity-view-comments" ,
689+ kwargs = {
690+ "activity_id" : self .activity_for_circle_with_companion .id ,
691+ },
692+ ),
693+ {
694+ "activity_id" : self .activity_for_circle_with_companion .id ,
695+ },
696+ )
697+ self .assertEqual (response .status_code , HTTPStatus .OK )
698+ self .assertContains (response , self .companion_two .display_name )
699+ self .assertContains (response , comment )
0 commit comments