示例#1
0
    def test_serverroute_partial_update__update_all(self):
        update_params = {"awake": False}
        update_params["timeout_duration_seconds"] = 9001

        self.assertNotEqual(
            update_params["awake"],
            ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                                  self.serverid)["awake"],
        )
        self.assertNotEqual(
            update_params["timeout_duration_seconds"],
            ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                                  self.serverid)["timeout_duration_seconds"],
        )

        ServerRoute().partial_update(self.session, "Bot " + BOT_TOKEN,
                                     self.serverid, update_params)
        self.assertEqual(
            update_params["awake"],
            ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                                  self.serverid)["awake"],
        )
        self.assertEqual(
            update_params["timeout_duration_seconds"],
            ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                                  self.serverid)["timeout_duration_seconds"],
        )
示例#2
0
 def test_serverroute_post_collection__good_request(self):
     serverid = 1234
     result = ServerRoute().post_collection(self.session,
                                            "Bot " + BOT_TOKEN,
                                            str(serverid))
     self.assertEqual(
         result,
         ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                               str(serverid)),
     )
示例#3
0
    def test_serverroute_partial_update__update_awake(self):
        update_params = {"awake": False}

        self.assertNotEqual(
            update_params["awake"],
            ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                                  self.serverid)["awake"],
        )

        ServerRoute().partial_update(self.session, "Bot " + BOT_TOKEN,
                                     self.serverid, update_params)
        self.assertEqual(
            update_params["awake"],
            ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                                  self.serverid)["awake"],
        )
示例#4
0
    def test_serverroute_partial_update__update_timeout_duration(self):
        update_params = {"timeout_duration_seconds": 9001}

        self.assertNotEqual(
            update_params["timeout_duration_seconds"],
            ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                                  self.serverid)["timeout_duration_seconds"],
        )

        ServerRoute().partial_update(self.session, "Bot " + BOT_TOKEN,
                                     self.serverid, update_params)
        self.assertEqual(
            update_params["timeout_duration_seconds"],
            ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                                  self.serverid)["timeout_duration_seconds"],
        )
示例#5
0
 def test_serverroute_post_collection__duplicate_request(self):
     serverid = 1234
     result = ServerRoute().post_collection(self.session,
                                            "Bot " + BOT_TOKEN,
                                            str(serverid))
     self.assertEqual(
         result,
         ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                               str(serverid)),
     )
     self.assertRaises(
         DuplicateResourceError,
         ServerRoute().post_collection,
         self.session,
         "Bot " + BOT_TOKEN,
         str(serverid),
     )
示例#6
0
 def test_serverroute_get_one__not_found(self):
     self.assertRaises(
         NotFoundError,
         ServerRoute().get_one,
         self.session,
         "Bot " + BOT_TOKEN,
         "1111",
     )
示例#7
0
 def test_serverroute_get_one__bad_input(self):
     self.assertRaises(
         InvalidTypeError,
         ServerRoute().get_one,
         self.session,
         "Bot " + BOT_TOKEN,
         "asdf",
     )
示例#8
0
 def test_serverroute_post_collection__bad_id_float_request(self):
     serverid = 1.23
     self.assertRaises(
         InvalidTypeError,
         ServerRoute().post_collection,
         self.session,
         "Bot " + BOT_TOKEN,
         str(serverid),
     )
示例#9
0
 def test_serverroute_get_one__unauthorized(self, auth_mock):
     auth_mock.return_value = False
     self.assertRaises(
         AuthenticationError,
         ServerRoute().get_one,
         self.session,
         "Bot " + "asdffdsa",
         "1234",
     )
示例#10
0
 def test_serverroute_get_collection__unauthorized(self, auth_mock):
     auth_mock.return_value = False
     create_server(self.session, server_id=1234)
     create_server(self.session, server_id=4321)
     self.assertRaises(
         AuthenticationError,
         ServerRoute().get_collection,
         self.session,
         "Bot " + "asdffdsa",
     )
示例#11
0
 def test_serverroute_partial_update__update_timeout_duration_invalid(self):
     update_params = {"timeout_duration_seconds": "asdf"}
     self.assertRaises(
         InvalidTypeError,
         ServerRoute().partial_update,
         self.session,
         "Bot " + BOT_TOKEN,
         self.serverid,
         update_params,
     )
示例#12
0
 def test_serverroute_partial_update__update_awake_invalid(self):
     update_params = {"awake": "asdf"}
     self.assertRaises(
         InvalidTypeError,
         ServerRoute().partial_update,
         self.session,
         "Bot " + BOT_TOKEN,
         self.serverid,
         update_params,
     )
示例#13
0
 def test_serverroute_partial_update__nonexistant_server(self):
     update_params = {"awake": False}
     self.assertRaises(
         NotFoundError,
         ServerRoute().partial_update,
         self.session,
         "Bot " + BOT_TOKEN,
         9001,
         update_params,
     )
示例#14
0
 def test_serverroute_partial_update__bad_server_id(self):
     update_params = {"awake": False}
     self.assertRaises(
         InvalidTypeError,
         ServerRoute().partial_update,
         self.session,
         "Bot " + BOT_TOKEN,
         "asdf",
         update_params,
     )
示例#15
0
 def test_serverroute_post_collection__unauthorized_request(
         self, auth_mock):
     auth_mock.return_value = False
     serverid = 1234
     self.assertRaises(
         AuthenticationError,
         ServerRoute().post_collection,
         self.session,
         "Bot " + "asdffdsa",
         str(serverid),
     )
示例#16
0
    def test_serverroute_partial_update__unauthorized(self, auth_mock):
        auth_mock.return_value = False

        update_params = {"awake": False}
        self.assertRaises(
            AuthenticationError,
            ServerRoute().partial_update,
            self.session,
            "",
            "1",
            update_params,
        )
示例#17
0
    def test_serverroute_partial_update__update_timeout_duration_too_long(
            self):
        update_params = {"timeout_duration_seconds": 777777777777777}

        self.assertNotEqual(
            update_params["timeout_duration_seconds"],
            ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                                  self.serverid)["timeout_duration_seconds"],
        )

        self.assertRaises(
            ValidationError,
            ServerRoute().partial_update,
            self.session,
            "Bot " + BOT_TOKEN,
            self.serverid,
            update_params,
        )
        self.assertNotEqual(
            update_params["timeout_duration_seconds"],
            ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                                  self.serverid)["timeout_duration_seconds"],
        )
示例#18
0
 def test_serverroute_get_one__good_request(self):
     result = ServerRoute().get_one(self.session, "Bot " + BOT_TOKEN,
                                    "1234")
     self.assertEqual(result, self.expected_output[0])
示例#19
0
 def test_serverroute_get_collection__multiple_elements(self):
     create_server(self.session, server_id=1234)
     create_server(self.session, server_id=4321)
     result = ServerRoute().get_collection(self.session, "Bot " + BOT_TOKEN)
     self.assertEqual(len(result), 2)
示例#20
0
 def test_serverroute_get_collection__one_element(self):
     create_server(self.session, server_id=1234)
     result = ServerRoute().get_collection(self.session, "Bot " + BOT_TOKEN)
     self.assertEqual(len(result), 1)
     self.assertEqual(result[0]["server_id"], 1234)
示例#21
0
 def test_serverroute_get_collection__no_elements(self):
     result = ServerRoute().get_collection(self.session, "Bot " + BOT_TOKEN)
     self.assertEqual(result, [])