# Path: rpaas/admin_plugin.py
# class CommandNotFoundError(Exception):
# class DisplayTable:
#     def __init__(self, name):
#     def __str__(self):
#     def __unicode__(self):
#     def __init__(self, fields, max_field_width=30):
#     def _compute_widths(self):
#     def _add_hrule(self):
#     def _align_left(self, fieldname, width):
#     def _write_row(self, row):
#     def add_row(self, *args):
#     def display(self):
# def handle_plan_flavor(option, args):
# def list_plan_flavor(option, args, parser_choice, parser):
# def create_plan_flavor(option, args, parser_choice, parser):
# def update_plan_flavor(option, args, parser_choice, parser):
# def delete_plan_flavor(option, args, parser_choice, parser):
# def show_plan_flavor(option, args, parser_choice, parser):
# def _merge_config(current, changes):
# def _retrieve_plan_flavor(option, service_name, name):
# def _render_plan_flavor(option):
# def _change_plan_flavor_args(args, parser_choice, parser):
# def _plan_flavor_arg(option, args, parser_choice, parser):
# def show_quota(args):
# def set_quota(args):
# def list_healings(args):
# def restore_instance(args):
# def parser_result(fileobj, buffersize=1):
# def _render_healings_list(healings_table, healings_list):
# def _base_args(cmd_name, parser=None):
# def available_commands():
# def get_command(name):
# def get_env(name):
# def proxy_request(service_name, path, body=None, headers=None, method='POST'):
# def help_commands():
# def main(args=None):


import datetime
import json
import os
import time
import unittest
import urllib
import urllib2
import urlparse
import mock
from io import StringIO
from rpaas import admin_plugin
from bson import json_util
        Request.return_value = request
        result = mock.Mock()
        result.getcode.return_value = 400
        result.read.return_value = "something went wrong"
        urlopen.return_value = result
        with self.assertRaises(SystemExit) as cm:
            admin_plugin.show_quota(["-s", self.service_name, "-t", "myteam"])
        exc = cm.exception
        self.assertEqual(1, exc.code)
        self.assertEqual("ERROR: something went wrong\n", "".join(lines))

    @mock.patch("sys.stderr")
    def test_show_quota_invalid_args(self, stderr):
        with self.assertRaises(SystemExit) as cm:
            admin_plugin.show_quota(["-s", self.service_name])
        exc = cm.exception
        self.assertEqual(2, exc.code)
        stderr.write.assert_called_with("show-quota: error: argument -t/--team is required\n")

    @mock.patch("urllib2.urlopen")
    @mock.patch("urllib2.Request")
    @mock.patch("sys.stdout")
    def test_set_quota(self, stdout, Request, urlopen):
        lines = []
        stdout.write.side_effect = lambda data, **kw: lines.append(data)
        request = mock.Mock()
        Request.return_value = request
        result = mock.Mock()
        result.getcode.return_value = 200
        urlopen.return_value = result

# Path: rpaas/admin_plugin.py
# class CommandNotFoundError(Exception):
# class DisplayTable:
#     def __init__(self, name):
#     def __str__(self):
#     def __unicode__(self):
#     def __init__(self, fields, max_field_width=30):
#     def _compute_widths(self):
#     def _add_hrule(self):
#     def _align_left(self, fieldname, width):
#     def _write_row(self, row):
#     def add_row(self, *args):
#     def display(self):
# def handle_plan_flavor(option, args):
# def list_plan_flavor(option, args, parser_choice, parser):
# def create_plan_flavor(option, args, parser_choice, parser):
# def update_plan_flavor(option, args, parser_choice, parser):
# def delete_plan_flavor(option, args, parser_choice, parser):
# def show_plan_flavor(option, args, parser_choice, parser):
# def _merge_config(current, changes):
# def _retrieve_plan_flavor(option, service_name, name):
# def _render_plan_flavor(option):
# def _change_plan_flavor_args(args, parser_choice, parser):
# def _plan_flavor_arg(option, args, parser_choice, parser):
# def show_quota(args):
# def set_quota(args):
# def list_healings(args):
# def restore_instance(args):
# def parser_result(fileobj, buffersize=1):
# def _render_healings_list(healings_table, healings_list):
# def _base_args(cmd_name, parser=None):
# def available_commands():
# def get_command(name):
# def get_env(name):
# def proxy_request(service_name, path, body=None, headers=None, method='POST'):
# def help_commands():
# def main(args=None):


# Path: tests/test_admin_plugin.py
import datetime
import json
import os
import time
import unittest
import urllib
import urllib2
import urlparse
import mock
from io import StringIO
from rpaas import admin_plugin
from bson import json_util

        Request.return_value = request
        result = mock.Mock()
        result.getcode.return_value = 400
        result.read.return_value = "something went wrong"
        urlopen.return_value = result
        with self.assertRaises(SystemExit) as cm:
            admin_plugin.show_quota(["-s", self.service_name, "-t", "myteam"])
        exc = cm.exception
        self.assertEqual(1, exc.code)
        self.assertEqual("ERROR: something went wrong\n", "".join(lines))

    @mock.patch("sys.stderr")
    def test_show_quota_invalid_args(self, stderr):
        with self.assertRaises(SystemExit) as cm:
            admin_plugin.show_quota(["-s", self.service_name])
        exc = cm.exception
        self.assertEqual(2, exc.code)
        stderr.write.assert_called_with("show-quota: error: argument -t/--team is required\n")

    @mock.patch("urllib2.urlopen")
    @mock.patch("urllib2.Request")
    @mock.patch("sys.stdout")
    def test_set_quota(self, stdout, Request, urlopen):
        lines = []
        stdout.write.side_effect = lambda data, **kw: lines.append(data)
        request = mock.Mock()
        Request.return_value = request
        result = mock.Mock()
        result.getcode.return_value = 200
        urlopen.return_value = result

        admin_plugin.set_quota(["-s", self.service_name, "-t", "myteam", "-q", "10"])