Exemple #1
0
 def test_route_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.route(['remove', '-s', 'myservice', '-i', 'myinst', '-p', '/path/out'])
     Request.assert_called_with(self.target +
                                "services/myservice/proxy/myinst?" +
                                "callback=/resources/myinst/route")
     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("path=%2Fpath%2Fout")
     self.assertEqual(request.get_method(), 'DELETE')
     urlopen.assert_called_with(request)
     stdout.write.assert_called_with("route successfully removed\n")
Exemple #2
0
 def test_route_list(self, stdout, Request, urlopen):
     request = Request.return_value
     urlopen.return_value.getcode.return_value = 200
     urlopen.return_value.read.return_value = '{"_id": "myinst", ' + \
         '"paths": [{"path": "/a", "content": "desta"}, {"path": "/b", "content": "destb"}]}'
     self.set_envs()
     self.addCleanup(self.delete_envs)
     plugin.route(['list', '-s', 'myservice', '-i', 'myinst'])
     Request.assert_called_with(self.target +
                                "services/myservice/proxy/myinst?" +
                                "callback=/resources/myinst/route")
     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("path = /a\ncontent = desta\npath = /b\ncontent = destb\n")
Exemple #3
0
 def test_route_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.route(['remove', '-s', 'myservice', '-i', 'myinst', '-p', '/path/out'])
     Request.assert_called_with(self.target +
                                "services/myservice/proxy/myinst?" +
                                "callback=/resources/myinst/route")
     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("path=%2Fpath%2Fout")
     self.assertEqual(request.get_method(), 'DELETE')
     urlopen.assert_called_with(request)
     stdout.write.assert_called_with("route successfully removed\n")
Exemple #4
0
 def test_route_list(self, stdout, Request, urlopen):
     request = Request.return_value
     urlopen.return_value.getcode.return_value = 200
     urlopen.return_value.read.return_value = '{"_id": "myinst", ' + \
         '"paths": [{"path": "/a", "content": "desta"}, {"path": "/b", "content": "destb"}]}'
     self.set_envs()
     self.addCleanup(self.delete_envs)
     plugin.route(['list', '-s', 'myservice', '-i', 'myinst'])
     Request.assert_called_with(self.target +
                                "services/myservice/proxy/myinst?" +
                                "callback=/resources/myinst/route")
     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("path = /a\ncontent = desta\npath = /b\ncontent = destb\n")
Exemple #5
0
 def test_route_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", "location")
     plugin.route(['add', '-s', 'myservice', '-i', 'myinst', '-p', '/path/out', '-c', '@'+path])
     Request.assert_called_with(self.target +
                                "services/myservice/proxy/myinst?" +
                                "callback=/resources/myinst/route")
     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=content%0A&path=%2Fpath%2Fout")
     self.assertEqual(request.get_method(), 'POST')
     urlopen.assert_called_with(request)
     stdout.write.assert_called_with("route successfully added\n")
Exemple #6
0
 def test_route_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", "location")
     plugin.route(['add', '-s', 'myservice', '-i', 'myinst', '-p', '/path/out', '-c', '@'+path])
     Request.assert_called_with(self.target +
                                "services/myservice/proxy/myinst?" +
                                "callback=/resources/myinst/route")
     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=content%0A&path=%2Fpath%2Fout")
     self.assertEqual(request.get_method(), 'POST')
     urlopen.assert_called_with(request)
     stdout.write.assert_called_with("route successfully added\n")