Beispiel #1
0
    def test_messageroute_post__invalid_paras(self):
        request = {
            "ban_id": "asdf",
            "author_id": 1,
            "sent_time": self.current_time_string,
            "called_out": True,
        }
        self.assertRaises(
            InvalidTypeError,
            MessageRoute().post,
            self.session,
            "Bot " + BOT_TOKEN,
            request,
        )

        request = {
            "ban_id": 1,
            "sent_time": 1234,
            "author_id": 1,
            "called_out": True
        }
        self.assertRaises(
            InvalidTypeError,
            MessageRoute().post,
            self.session,
            "Bot " + BOT_TOKEN,
            request,
        )

        request = {
            "ban_id": 1,
            "sent_time": "asdf",
            "author_id": 1,
            "called_out": True
        }
        self.assertRaises(
            ValidationError,
            MessageRoute().post,
            self.session,
            "Bot " + BOT_TOKEN,
            request,
        )

        request = {
            "ban_id": 1,
            "sent_time": self.current_time_string,
            "author_id": "asdf",
            "called_out": True
        }

        self.assertRaises(
            ValidationError,
            MessageRoute().post,
            self.session,
            "Bot " + BOT_TOKEN,
            request,
        )
Beispiel #2
0
    def test_messageroute_post__good_request_callout(self):
        request = {
            "ban_id": 1,
            "author_id": 1,
            "sent_time": self.current_time_string,
            "called_out": True,
        }
        self.assertNotEqual(
            self.current_time_string,
            self.session.query(Ban).filter_by(rowid=1).first().infracted_at,
        )
        self.assertNotEqual(
            self.current_time_string,
            self.session.query(Ban).filter_by(rowid=1).first().calledout_at,
        )

        MessageRoute().post(self.session, "Bot " + BOT_TOKEN, request)
        self.assertEqual(
            self.current_time_string,
            self.session.query(Ban).filter_by(rowid=1).first().infracted_at,
        )
        self.assertEqual(
            self.current_time_string,
            self.session.query(Ban).filter_by(rowid=1).first().calledout_at,
        )
Beispiel #3
0
 def test_messageroute_post__record_setting(self):
     request = {
         "ban_id": 1,
         "author_id": 1,
         "sent_time": self.current_time_string,
     }
     MessageRoute().post(self.session, "Bot " + BOT_TOKEN, request)
     self.assertEqual(
         timedelta(days=6).total_seconds(),
         self.session.query(BanRecord).filter_by(
             rowid=1).first().record_seconds)
Beispiel #4
0
 def test_messageroute_post__unauthorized(self):
     request = {
         "ban_id": 3,
         "author_id": 1,
         "sent_time": self.current_time_string,
     }
     self.assertRaises(
         AuthenticationError,
         MessageRoute().post,
         self.session,
         "Bot " + "asdffdsa",
         request,
     )
Beispiel #5
0
 def test_messageroute_post__ban_not_found(self):
     request = {
         "ban_id": 3,
         "author_id": 1,
         "sent_time": self.current_time_string,
     }
     self.assertRaises(
         NotFoundError,
         MessageRoute().post,
         self.session,
         "Bot " + BOT_TOKEN,
         request,
     )
Beispiel #6
0
 def test_messageroute_post__new_author(self):
     request = {
         "ban_id": 1,
         "author_id": 1,
         "sent_time": self.current_time_string,
     }
     MessageRoute().post(self.session, "Bot " + BOT_TOKEN, request)
     self.assertEqual(
         1,
         self.session.query(Author).filter_by(
             user_id=1).first().infraction_count)
     self.assertEqual(
         1,
         self.session.query(AuthorInfraction).filter_by(
             user_id=1, ban_id=1).first().infraction_count)
Beispiel #7
0
    def test_messageroute_post__existing_author_and_infraction(self):
        new_author = Author(user_id=1, infraction_count=9)
        new_authinf = AuthorInfraction(user_id=1, ban_id=1, infraction_count=2)
        self.session.add(new_author)
        self.session.add(new_authinf)

        request = {
            "ban_id": 1,
            "author_id": 1,
            "sent_time": self.current_time_string,
        }
        MessageRoute().post(self.session, "Bot " + BOT_TOKEN, request)
        self.assertEqual(
            3,
            self.session.query(AuthorInfraction).filter_by(
                user_id=1, ban_id=1).first().infraction_count)