# Path: rpaas/plugin.py
# def encode_multipart_formdata(files):
#     def __init__(self, name):
#     def __str__(self):
#     def __unicode__(self):
# def scale(args):
# def update(args):
# def certificate(args):
# def nginx_block(value):
# def route(args):
# def block(args):
# def nginx_lua_block(value):
# def get_lua_args(args):
# def lua(args):
# def purge(args):
# def get_certificate_args(args):
# def get_ssl_args(args):
# def get_update_args(args):
# def ssl(args):
# def status(args):
# def info(args):
# def get_info_args(args):
# def get_status_args(args):
# def get_scale_args(args):
# def get_route_args(args):
# def get_block_args(args):
# def get_purge_args(args):
# def get_env(name):
# def proxy_request(service_name, instance_name, path, body=None, headers=None, method='POST'):
# def available_commands():
# def get_command(name):
# def help_commands():
# def main(args=None):
# class CommandNotFoundError(Exception):


import os
import unittest
import re
import mock
import argparse
from rpaas import plugin
from urllib2 import HTTPError
from io import StringIO
        with self.assertRaises(SystemExit) as cm:
            plugin.get_block_args(
                ['-s', 'myservice', '-i', 'myinst', '-b', 'http']
            )
        exc = cm.exception
        self.assertEqual(2, exc.code)
        stderr.write.assert_called_with('block: error: too few arguments\n')

    def test_nginx_block(self):
        self.assertEqual('http', plugin.nginx_block('http'))
        with self.assertRaises(argparse.ArgumentTypeError):
            plugin.nginx_block('lelele')

    @mock.patch("sys.stderr")
    def test_purge_args(self, stderr):
        _, _, path, _ = plugin.get_purge_args(['-s', 'myservice', '-i', 'myinst', '-l', '/foo/bar'])
        self.assertEqual(path, '/foo/bar')
        _, _, path, _ = plugin.get_purge_args(['-s', 'myservice', '-i', 'myinst', '-l', '/foo/bar?a=b&c=d'])
        self.assertEqual(path, '/foo/bar?a=b&c=d')

        _, _, path, preserve_path = plugin.get_purge_args(['-s', 'myservice', '-i', 'myinst', '-l',
                                                           'http://www.example.com/'])
        self.assertFalse(preserve_path)
        self.assertEqual(path, '/')

        _, _, path, preserve_path = plugin.get_purge_args(['-s', 'myservice', '-i', 'myinst', '-l',
                                                           'http://www.example.com/?a=b', '-p'])
        self.assertTrue(preserve_path)
        self.assertEqual(path, 'http://www.example.com/?a=b')


# Path: rpaas/plugin.py
# def encode_multipart_formdata(files):
#     def __init__(self, name):
#     def __str__(self):
#     def __unicode__(self):
# def scale(args):
# def update(args):
# def certificate(args):
# def nginx_block(value):
# def route(args):
# def block(args):
# def nginx_lua_block(value):
# def get_lua_args(args):
# def lua(args):
# def purge(args):
# def get_certificate_args(args):
# def get_ssl_args(args):
# def get_update_args(args):
# def ssl(args):
# def status(args):
# def info(args):
# def get_info_args(args):
# def get_status_args(args):
# def get_scale_args(args):
# def get_route_args(args):
# def get_block_args(args):
# def get_purge_args(args):
# def get_env(name):
# def proxy_request(service_name, instance_name, path, body=None, headers=None, method='POST'):
# def available_commands():
# def get_command(name):
# def help_commands():
# def main(args=None):
# class CommandNotFoundError(Exception):


# Path: tests/test_plugin.py
import os
import unittest
import re
import mock
import argparse
from rpaas import plugin
from urllib2 import HTTPError
from io import StringIO

        with self.assertRaises(SystemExit) as cm:
            plugin.get_block_args(
                ['-s', 'myservice', '-i', 'myinst', '-b', 'http']
            )
        exc = cm.exception
        self.assertEqual(2, exc.code)
        stderr.write.assert_called_with('block: error: too few arguments\n')

    def test_nginx_block(self):
        self.assertEqual('http', plugin.nginx_block('http'))
        with self.assertRaises(argparse.ArgumentTypeError):
            plugin.nginx_block('lelele')

    @mock.patch("sys.stderr")
    def test_purge_args(self, stderr):
        _, _, path, _ = plugin.get_purge_args(['-s', 'myservice', '-i', 'myinst', '-l', '/foo/bar'])
        self.assertEqual(path, '/foo/bar')
        _, _, path, _ = plugin.get_purge_args(['-s', 'myservice', '-i', 'myinst', '-l', '/foo/bar?a=b&c=d'])
        self.assertEqual(path, '/foo/bar?a=b&c=d')

        _, _, path, preserve_path = plugin.get_purge_args(['-s', 'myservice', '-i', 'myinst', '-l',
                                                           'http://www.example.com/'])
        self.assertFalse(preserve_path)
        self.assertEqual(path, '/')

        _, _, path, preserve_path = plugin.get_purge_args(['-s', 'myservice', '-i', 'myinst', '-l',
                                                           'http://www.example.com/?a=b', '-p'])
        self.assertTrue(preserve_path)
        self.assertEqual(path, 'http://www.example.com/?a=b')


        _, _, path, preserve_path = plugin.get_purge_args(['-s', 'myservice', '-i', 'myinst', '-l',