コード例 #1
0
 def test_banroute_delete__delete_last_word(self):
     BanRoute().delete(self.session, "Bot " + BOT_TOKEN, self.serverid, 1)
     BanRoute().delete(self.session, "Bot " + BOT_TOKEN, self.serverid, 3)
     self.assertRaises(
         ValidationError,
         BanRoute().delete,
         self.session,
         "Bot " + BOT_TOKEN,
         self.serverid,
         2,
     )
コード例 #2
0
 def test_banroute_post_collection__confusable_word(self):
     BanRoute().post_collection(self.session, "Bot " + BOT_TOKEN,
                                self.serverid, "lest")
     self.assertRaises(
         DuplicateResourceError,
         BanRoute().post_collection,
         self.session,
         self.authtoken,
         self.serverid,
         "iest",
     )
コード例 #3
0
 def test_banroute_post_collection__duplicate_word(self):
     banned_word = "asdf"
     BanRoute().post_collection(self.session, "Bot " + BOT_TOKEN,
                                self.serverid, banned_word)
     self.assertRaises(
         DuplicateResourceError,
         BanRoute().post_collection,
         self.session,
         self.authtoken,
         self.serverid,
         banned_word,
     )
コード例 #4
0
 def test_banroute_delete__twice(self):
     banid = 1
     BanRoute().delete(self.session, "Bot " + BOT_TOKEN, self.serverid,
                       banid)
     self.assertRaises(
         NotFoundError,
         BanRoute().delete,
         self.session,
         "Bot " + BOT_TOKEN,
         self.serverid,
         banid,
     )
コード例 #5
0
    def test_banroute_delete__good_request(self):
        banid = 1

        self.assertEqual(3, len(self.session.query(BanRecord).all()))
        BanRoute().delete(self.session, "Bot " + BOT_TOKEN, self.serverid,
                          banid)
        self.assertRaises(NotFoundError,
                          BanRoute().get_one, self.session, "Bot " + BOT_TOKEN,
                          banid)
        server_words = (self.session.query(Server).filter_by(
            server_id=self.serverid).first().banned_words)
        self.assertEqual(len(server_words), 2)
        self.assertEqual(2, len(self.session.query(BanRecord).all()))
コード例 #6
0
 def test_banroute_post_collection__too_many_words(self):
     BanRoute().post_collection(self.session, self.authtoken, self.serverid,
                                "asdf")
     BanRoute().post_collection(self.session, self.authtoken, self.serverid,
                                "sdfa")
     BanRoute().post_collection(self.session, self.authtoken, self.serverid,
                                "dfas")
     self.assertRaises(
         PlanError,
         BanRoute().post_collection,
         self.session,
         self.authtoken,
         self.serverid,
         "fasd",
     )
コード例 #7
0
 def test_banroute_get_collection__server_not_found(self):
     self.assertRaises(
         NotFoundError,
         BanRoute().get_collection,
         self.session,
         self.authtoken,
         12345,
     )
コード例 #8
0
 def test_banroute_post_collection__good_request(self):
     banned_word = "asdf"
     result = BanRoute().post_collection(self.session, self.authtoken,
                                         self.serverid, banned_word)
     db_result = (self.session.query(Ban).filter_by(
         server_id=self.serverid, banned_word=banned_word).first())
     self.assertEqual(result, db_result.to_dict())
     self.assertTrue("record" in result)
コード例 #9
0
 def test_banroute_get_collection__bad_serverid(self):
     self.assertRaises(
         InvalidTypeError,
         BanRoute().get_collection,
         self.session,
         self.authtoken,
         "asdf",
     )
コード例 #10
0
 def test_banroute_get_collection__unauthorized(self):
     self.assertRaises(
         AuthenticationError,
         BanRoute().get_collection,
         self.session,
         "Bot " + "asdffdsa",
         12345,
     )
コード例 #11
0
 def test_banroute_post_collection__server_not_found(self):
     self.assertRaises(
         NotFoundError,
         BanRoute().post_collection,
         self.session,
         self.authtoken,
         "4321",
         "asdf",
     )
コード例 #12
0
    def test_banroute_post_one__resets_record(self):
        new_word = "qwerty"
        banid = 1

        self.assertNotEqual(0, self.record.record_seconds)
        BanRoute().post_one(self.session, "Bot " + BOT_TOKEN, self.serverid,
                            banid, new_word)
        self.assertEqual(0, self.record.record_seconds)
        self.assertEqual(0, self.record.infraction_count)
コード例 #13
0
 def test_banroute_delete__ban_not_found(self):
     self.assertRaises(
         NotFoundError,
         BanRoute().delete,
         self.session,
         "Bot " + BOT_TOKEN,
         self.serverid,
         5,
     )
コード例 #14
0
 def test_banroute_get_one__unauthorized(self, auth_mock):
     auth_mock.return_value = False
     self.assertRaises(
         AuthenticationError,
         BanRoute().get_one,
         self.session,
         "Bot " + "asdffdsa",
         "0",
     )
コード例 #15
0
 def test_banroute_post_one__ban_not_found(self):
     self.assertRaises(
         NotFoundError,
         BanRoute().post_one,
         self.session,
         "Bot " + BOT_TOKEN,
         self.serverid,
         5,
         "asdf",
     )
コード例 #16
0
 def test_banroute_post_collection__unauthorized(self, auth_mock):
     auth_mock.return_value = False
     self.assertRaises(
         AuthenticationError,
         BanRoute().post_collection,
         self.session,
         "Bot " + "asdffdsa",
         self.serverid,
         "asdf",
     )
コード例 #17
0
 def test_banroute_delete__unauthorized(self, auth_mock):
     auth_mock.return_value = False
     self.assertRaises(
         AuthenticationError,
         BanRoute().delete,
         self.session,
         "Bot " + "asdffdsa",
         self.serverid,
         1,
     )
コード例 #18
0
 def test_banroute_post_collection__invalid_word(self):
     banned_word = 1234
     self.assertRaises(
         InvalidTypeError,
         BanRoute().post_collection,
         self.session,
         self.authtoken,
         self.serverid,
         banned_word,
     )
コード例 #19
0
 def test_banroute_post_one__word_invalid(self):
     self.assertRaises(
         InvalidTypeError,
         BanRoute().post_one,
         self.session,
         "Bot " + BOT_TOKEN,
         self.serverid,
         1,
         1234,
     )
コード例 #20
0
 def test_banroute_post_one__too_many_words(self):
     self.assertRaises(
         PlanError,
         BanRoute().post_one,
         self.session,
         "Bot " + BOT_TOKEN,
         self.overloaded_server_id,
         1,
         "qwert",
     )
コード例 #21
0
 def test_banroute_post_one__confusable_word(self):
     self.assertRaises(
         DuplicateResourceError,
         BanRoute().post_one,
         self.session,
         "Bot " + BOT_TOKEN,
         self.serverid,
         1,
         "AsDf",
     )
コード例 #22
0
    def test_banroute_post_one__good_request(self):
        new_word = "qwerty"
        banid = 1

        ban = self.session.query(Ban).filter_by(rowid=banid).first()
        old_time = ban.infracted_at
        self.assertNotEqual(new_word, ban.banned_word)

        BanRoute().post_one(self.session, "Bot " + BOT_TOKEN, self.serverid,
                            banid, new_word)
        self.assertEqual(
            new_word,
            BanRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                               banid)["banned_word"],
        )
        self.assertEqual(
            True,
            datetime.strptime(ban.infracted_at, "%Y-%m-%d %H:%M:%S") >
            datetime.strptime(old_time, "%Y-%m-%d %H:%M:%S"),
        )
コード例 #23
0
    def test_banroute_get_collection__one_element(self):
        banned_word = "asdf"
        ban = Ban(server_id=int(self.serverid), banned_word=banned_word)
        record = BanRecord(server_banned_word=ban)
        self.session.add(ban)
        self.session.add(record)

        result = BanRoute().get_collection(self.session, "Bot " + BOT_TOKEN,
                                           self.serverid)
        self.assertEqual(len(result), 1)
        self.assertEqual(result[0]["banned_word"], banned_word)
コード例 #24
0
    def test_banroute_get_one__good_request(self):
        b1 = Ban(server_id=1, banned_word="asdf")
        r1 = BanRecord(server_banned_word=b1)
        b2 = Ban(server_id=1, banned_word="qwerty")
        r2 = BanRecord(server_banned_word=b2)
        self.session.add(b1)
        self.session.add(r1)
        self.session.add(b2)
        self.session.add(r2)

        result = BanRoute().get_one(self.session, "Bot " + BOT_TOKEN, "2")
        self.assertEqual(b2.banned_word, result["banned_word"])
コード例 #25
0
    def test_banroute_get_collection__multiple_elements(self):
        b1w = "asdf"
        b2w = "qwerty"
        ban1 = Ban(server_id=int(self.serverid), banned_word=b1w)
        record1 = BanRecord(server_banned_word=ban1)
        ban2 = Ban(server_id=int(self.serverid), banned_word=b2w)
        record2 = BanRecord(server_banned_word=ban2)
        self.session.add(ban1)
        self.session.add(record1)
        self.session.add(ban2)
        self.session.add(record2)

        result = BanRoute().get_collection(self.session, "Bot " + BOT_TOKEN,
                                           self.serverid)
        self.assertEqual(len(result), 2)
        self.assertEqual(result[0]["banned_word"], b1w)
        self.assertEqual(result[1]["banned_word"], b2w)
コード例 #26
0
 def test_banroute_get_one__not_found(self):
     self.assertRaises(NotFoundError,
                       BanRoute().get_one, self.session, self.authtoken,
                       "0")
コード例 #27
0
 def test_banroute_get_collection__no_elements(self):
     result = BanRoute().get_collection(self.session, self.authtoken,
                                        self.serverid)
     self.assertEqual(result, [])