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"], )
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)), )
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"], )
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"], )
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), )
def test_serverroute_get_one__not_found(self): self.assertRaises( NotFoundError, ServerRoute().get_one, self.session, "Bot " + BOT_TOKEN, "1111", )
def test_serverroute_get_one__bad_input(self): self.assertRaises( InvalidTypeError, ServerRoute().get_one, self.session, "Bot " + BOT_TOKEN, "asdf", )
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), )
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", )
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", )
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, )
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, )
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, )
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, )
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), )
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, )
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"], )
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])
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)
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)
def test_serverroute_get_collection__no_elements(self): result = ServerRoute().get_collection(self.session, "Bot " + BOT_TOKEN) self.assertEqual(result, [])