async def test_api_permission_key(self): async with WolframCloudAsyncSession(server=server) as cloud: url = "api/public/permkey_stringreverse_wxf" api = (self.api_owner, url) apicall = WolframAPICallAsync(cloud, api, permission_key="my_key") apicall.set_parameter("str", "abcde") response = await apicall.perform() self.assertEqual("edcba", await response.get())
async def test_api_permission_key(self): async with WolframCloudAsyncSession(server=server) as cloud: url = 'api/public/permkey_stringreverse_wxf' api = (self.api_owner, url) apicall = WolframAPICallAsync(cloud, api, permission_key='my_key') apicall.set_parameter('str', 'abcde') response = await apicall.perform() self.assertEqual('edcba', await response.get())
async def test_wolfram_api_call_named_image(self): api = (self.api_owner, "api/private/imagedimensions") apicall = WolframAPICallAsync(self.cloud_session_async, api) with open(self.get_data_path("32x2.png"), "rb") as fp: apicall.add_file_parameter("image", fp, filename="testimage") res = await apicall.perform() self.assertTrue(res.success) res = await res.get() self.assertEqual(res, [32, 2])
async def test_wolfram_api_call_named_image(self): api = (self.api_owner, 'api/private/imagedimensions') apicall = WolframAPICallAsync(self.cloud_session_async, api) with open(self.get_data_path('32x2.png'), 'rb') as fp: apicall.add_file_parameter('image', fp, filename='testimage') res = await apicall.perform() self.assertTrue(res.success) res = await res.get() self.assertListEqual(res, [32, 2])
async def test_api_invalid_input(self): api_urls = ('api/private/two_parameters_out_json', 'api/private/two_parameters_out_wxf', 'api/private/two_parameters_out_default') for url in api_urls: api = (self.api_owner, url) apicall = WolframAPICallAsync(self.cloud_session_async, api) apicall.set_parameter('x', 'abc') res = await apicall.perform() self.assertFalse(res.success)
async def test_wolfram_api_image_string_int(self): api = (self.api_owner, "api/private/str_image_int") with open(self.get_data_path("32x2.png"), "rb") as fp: apicall = WolframAPICallAsync(self.cloud_session_async, api) apicall.set_parameter("str", "abc") apicall.set_parameter("int", 10) apicall.add_file_parameter("image", fp) result = await apicall.perform() res = await result.get() self.assertEqual(res, ["abc", [32, 2], 10])
async def test_wolfram_api_image_string_int(self): api = (self.api_owner, 'api/private/str_image_int') with open(self.get_data_path('32x2.png'), 'rb') as fp: apicall = WolframAPICallAsync(self.cloud_session_async, api) apicall.set_parameter('str', 'abc') apicall.set_parameter('int', 10) apicall.add_file_parameter('image', fp) result = await apicall.perform() res = await result.get() self.assertListEqual(res, ['abc', [32, 2], 10])
async def test_wolfram_api_call_str(self): api = (self.api_owner, "api/private/stringreverse") apicall = WolframAPICallAsync(self.cloud_session_async, api) apicall.set_parameter("str", "abcde") res = await apicall.perform() self.assertEqual('"edcba"', force_text(await res.get()))