def test_lua_remove(self, stdout, Request, urlopen): request = Request.return_value urlopen.return_value.getcode.return_value = 200 self.set_envs() self.addCleanup(self.delete_envs) plugin.lua(['remove', '-s', 'myservice', '-i', 'myinst', '-t', 'server', '-n', 'module_name']) Request.assert_called_with(self.target + "services/myservice/proxy/myinst?" + "callback=/resources/myinst/lua") request.add_header.assert_any_call("Authorization", "bearer " + self.token) request.add_header.assert_any_call("Content-Type", "application/x-www-form-urlencoded") self.assertEqual(request.get_method(), 'DELETE') urlopen.assert_called_with(request) stdout.write.assert_called_with('lua module successfully removed\n')
def test_lua_add_file_content(self, stdout, Request, urlopen): request = Request.return_value urlopen.return_value.getcode.return_value = 200 self.set_envs() self.addCleanup(self.delete_envs) path = os.path.join(os.path.dirname(__file__), "testdata", "lua_module") plugin.lua(['add', '-s', 'myservice', '-i', 'myinst', '-t', 'server', '-n', 'module', '-c', '@'+path]) Request.assert_called_with(self.target + "services/myservice/proxy/myinst?" + "callback=/resources/myinst/lua") request.add_header.assert_any_call("Authorization", "bearer " + self.token) request.add_header.assert_any_call("Content-Type", "application/x-www-form-urlencoded") request.add_data.assert_called_with( "content=%27init+globo_ab%27&lua_module_name=module&lua_module_type=server") self.assertEqual(request.get_method(), 'POST') urlopen.assert_called_with(request) stdout.write.assert_called_with("lua module successfully added\n")
def test_lua_list(self, stdout, Request, urlopen): request = Request.return_value urlopen.return_value.getcode.return_value = 200 urlopen.return_value.read.return_value = '{"_id": "myinst", ' + \ '"modules": [{"lua_name": "server", "content": "server content"}]}' self.set_envs() self.addCleanup(self.delete_envs) plugin.lua(['list', '-s', 'myservice', '-i', 'myinst']) Request.assert_called_with(self.target + "services/myservice/proxy/myinst?" + "callback=/resources/myinst/lua") request.add_header.assert_any_call("Authorization", "bearer " + self.token) self.assertEqual(request.get_method(), 'GET') urlopen.assert_called_with(request) stdout.write.assert_called_with("""module_name: content server: server content """)