Example #1
0
    def test_build_email_notification_poll_vote(self):
        
        poll_3 = config.orm.query(Poll).filter(Poll.start_dt == datetime.date(2020, 10, 1)).one() #@UndefinedVariable
        jo = config.orm.query(User).filter(User.first_name == "Jonathan").one() #@UndefinedVariable
        franck_p = config.orm.query(User).filter(User.email == "*****@*****.**").one() #@UndefinedVariable
        
        try:
            # Scenario 1 : first vote on a poll, non-empty list of choices
            poll_vote = poll_3.vote(jo, poll_3.choices)
            config.orm.commit()
            notification = build_email_notification(poll_vote, Events.NEW)

            self.assertEqual(notification.subject, u"VPT : le participant Jo a enregistré son vote (sondage : VPT d'octobre 2020)")
            self.assertListEqual(notification.recipients, [franck_p.email])
            self.assertIn("[20/10/2020, 27/10/2020]", notification.body)

            # Scenario 2 : second vote on a poll, same user, empty list of choices
            poll_vote = poll_3.vote(jo, [])
            config.orm.commit()
            notification = build_email_notification(poll_vote, Events.MODIFIED)
            
            self.assertEqual(notification.subject, u"VPT : le participant Jo a modifié son vote (sondage : VPT d'octobre 2020)")
            self.assertListEqual(notification.recipients, [franck_p.email])
            self.assertIn("[]", notification.body)
        
        finally:
            #TODO: should be done by the fixture
            config.orm.delete(poll_3.votes_by_user[jo])
            config.orm.commit()
Example #2
0
 def test_build_email_notification_user_token_new(self):
     
     user_token_active = config.orm.query(UserToken).filter(UserToken.email == "*****@*****.**").one() #@UndefinedVariable
     notification = build_email_notification(user_token_active, Events.NEW)
     
     self.assertEqual(notification.subject, u"Bienvenue sur le portail du VPT !")
     self.assertListEqual(notification.recipients, [user_token_active.email] + [user.email for user in User.all() if user.admin])
Example #3
0
 def test_build_email_notification_password_token_new(self):
     
     password_token_active = config.orm.query(PasswordToken).join(PasswordToken.user).filter(User.email == "*****@*****.**").one() #@UndefinedVariable
     notification = build_email_notification(password_token_active, Events.NEW)
     
     self.assertEqual(notification.subject, u"VPT : demande de changement de mot de passe")
     self.assertListEqual(notification.recipients, [password_token_active.user.email] + [user.email for user in User.all() if user.admin])
Example #4
0
    def test_build_email_notification_tournament_comment_new(self):

        try:
            tournament_21 = config.orm.query(Tournament).filter(
                Tournament.tournament_dt == datetime.date(
                    2010, 8, 1)).one()  #@UndefinedVariable
            nico = config.orm.query(User).filter(
                User.first_name == "Nicolas").one()
            zoe = config.orm.query(User).filter(User.first_name == "Zoe").one()
            comment = tournament_21.add_comment(nico, "Salut les amis !")
            config.orm.commit()
            notification = build_email_notification(comment, Events.NEW)

            self.assertEqual(
                notification.subject,
                u"VPT : un nouveau commentaire a été posté (tournoi du 01 août)"
            )
            self.assertListEqual(
                notification.recipients,
                [user.email for user in User.all() if user not in (nico, zoe)])

        finally:
            #TODO: should be done by the fixture
            config.orm.delete(tournament_21.comments[1])
            config.orm.commit()
Example #5
0
    def test_build_email_notification_poll_comment_new(self):

        try:
            poll_3 = config.orm.query(Poll).filter(
                Poll.start_dt == datetime.date(2020, 10,
                                               1)).one()  #@UndefinedVariable
            nico = config.orm.query(User).filter(
                User.first_name == "Nicolas").one()
            zoe = config.orm.query(User).filter(User.first_name == "Zoe").one()
            comment = poll_3.add_comment(nico, "Salut Franck !")
            config.orm.commit()
            notification = build_email_notification(comment, Events.NEW)

            self.assertEqual(
                notification.subject,
                u"VPT : un nouveau commentaire a été posté (sondage : VPT d'octobre 2020)"
            )
            self.assertListEqual(
                notification.recipients,
                [user.email for user in User.all() if user not in (nico, zoe)])

        finally:
            #TODO: should be done by the fixture
            config.orm.delete(poll_3.comments[0])
            config.orm.commit()
Example #6
0
 def test_build_email_notification_poll_new(self):
     
     poll_3 = config.orm.query(Poll).filter(Poll.start_dt == datetime.date(2020, 10, 1)).one() #@UndefinedVariable
     notification = build_email_notification(poll_3, Events.NEW)
     zoe = config.orm.query(User).filter(User.first_name == "Zoe").one()
     
     self.assertEqual(notification.subject, u"VPT d'octobre 2020 : votez !")
     self.assertListEqual(notification.recipients, [user.email for user in User.all() if user != zoe])
Example #7
0
 def test_build_email_notification_tournament_new(self):
     
     tournament_21 = config.orm.query(Tournament).filter(Tournament.tournament_dt == datetime.date(2010, 8, 1)).one() #@UndefinedVariable
     notification = build_email_notification(tournament_21, Events.NEW)
     zoe = config.orm.query(User).filter(User.first_name == "Zoe").one() 
     
     self.assertEqual(notification.subject, u"VPT : un nouveau tournoi a été planifié le dimanche 01 août")
     self.assertListEqual(notification.recipients, [user.email for user in User.all() if user != zoe])
Example #8
0
    def test_build_email_notification_poll_new(self):

        poll_3 = config.orm.query(Poll).filter(Poll.start_dt == datetime.date(
            2020, 10, 1)).one()  #@UndefinedVariable
        notification = build_email_notification(poll_3, Events.NEW)
        zoe = config.orm.query(User).filter(User.first_name == "Zoe").one()

        self.assertEqual(notification.subject, u"VPT d'octobre 2020 : votez !")
        self.assertListEqual(
            notification.recipients,
            [user.email for user in User.all() if user != zoe])
Example #9
0
    def test_build_email_notification_user_token_new(self):

        user_token_active = config.orm.query(UserToken).filter(
            UserToken.email ==
            "*****@*****.**").one()  #@UndefinedVariable
        notification = build_email_notification(user_token_active, Events.NEW)

        self.assertEqual(notification.subject,
                         u"Bienvenue sur le portail du VPT !")
        self.assertListEqual(notification.recipients,
                             [user_token_active.email] +
                             [user.email for user in User.all() if user.admin])
Example #10
0
    def test_build_email_notification_password_token_new(self):

        password_token_active = config.orm.query(PasswordToken).join(
            PasswordToken.user).filter(
                User.email == "*****@*****.**").one()  #@UndefinedVariable
        notification = build_email_notification(password_token_active,
                                                Events.NEW)

        self.assertEqual(notification.subject,
                         u"VPT : demande de changement de mot de passe")
        self.assertListEqual(notification.recipients,
                             [password_token_active.user.email] +
                             [user.email for user in User.all() if user.admin])
Example #11
0
    def test_build_email_notification_poll_vote(self):

        poll_3 = config.orm.query(Poll).filter(Poll.start_dt == datetime.date(
            2020, 10, 1)).one()  #@UndefinedVariable
        jo = config.orm.query(User).filter(
            User.first_name == "Jonathan").one()  #@UndefinedVariable
        franck_p = config.orm.query(User).filter(
            User.email == "*****@*****.**").one()  #@UndefinedVariable

        try:
            # Scenario 1 : first vote on a poll, non-empty list of choices
            poll_vote = poll_3.vote(jo, poll_3.choices)
            config.orm.commit()
            notification = build_email_notification(poll_vote, Events.NEW)

            self.assertEqual(
                notification.subject,
                u"VPT : le participant Jo a enregistré son vote (sondage : VPT d'octobre 2020)"
            )
            self.assertListEqual(notification.recipients, [franck_p.email])
            self.assertIn("[20/10/2020, 27/10/2020]", notification.body)

            # Scenario 2 : second vote on a poll, same user, empty list of choices
            poll_vote = poll_3.vote(jo, [])
            config.orm.commit()
            notification = build_email_notification(poll_vote, Events.MODIFIED)

            self.assertEqual(
                notification.subject,
                u"VPT : le participant Jo a modifié son vote (sondage : VPT d'octobre 2020)"
            )
            self.assertListEqual(notification.recipients, [franck_p.email])
            self.assertIn("[]", notification.body)

        finally:
            #TODO: should be done by the fixture
            config.orm.delete(poll_3.votes_by_user[jo])
            config.orm.commit()
Example #12
0
    def test_build_email_notification_tournament_new(self):

        tournament_21 = config.orm.query(Tournament).filter(
            Tournament.tournament_dt == datetime.date(
                2010, 8, 1)).one()  #@UndefinedVariable
        notification = build_email_notification(tournament_21, Events.NEW)
        zoe = config.orm.query(User).filter(User.first_name == "Zoe").one()

        self.assertEqual(
            notification.subject,
            u"VPT : un nouveau tournoi a été planifié le dimanche 01 août")
        self.assertListEqual(
            notification.recipients,
            [user.email for user in User.all() if user != zoe])
Example #13
0
    def test_build_email_notification_poll_comment_new(self):
        
        try:
            poll_3 = config.orm.query(Poll).filter(Poll.start_dt == datetime.date(2020, 10, 1)).one() #@UndefinedVariable
            nico = config.orm.query(User).filter(User.first_name == "Nicolas").one()
            zoe = config.orm.query(User).filter(User.first_name == "Zoe").one()
            comment = poll_3.add_comment(nico, "Salut Franck !")
            config.orm.commit()
            notification = build_email_notification(comment, Events.NEW)
            
            self.assertEqual(notification.subject, u"VPT : un nouveau commentaire a été posté (sondage : VPT d'octobre 2020)")
            self.assertListEqual(notification.recipients, [user.email for user in User.all() if user not in (nico, zoe)])

        finally:
            #TODO: should be done by the fixture
            config.orm.delete(poll_3.comments[0])
            config.orm.commit()
Example #14
0
    def test_build_email_notification_tournament_comment_new(self):
        
        try:
            tournament_21 = config.orm.query(Tournament).filter(Tournament.tournament_dt == datetime.date(2010, 8, 1)).one() #@UndefinedVariable
            nico = config.orm.query(User).filter(User.first_name == "Nicolas").one()
            zoe = config.orm.query(User).filter(User.first_name == "Zoe").one()
            comment = tournament_21.add_comment(nico, "Salut les amis !")
            config.orm.commit()
            notification = build_email_notification(comment, Events.NEW)
            
            self.assertEqual(notification.subject, u"VPT : un nouveau commentaire a été posté (tournoi du 01 août)")
            self.assertListEqual(notification.recipients, [user.email for user in User.all() if user not in (nico, zoe)])

        finally:
            #TODO: should be done by the fixture
            config.orm.delete(tournament_21.comments[1])
            config.orm.commit()