# Path: binstar_client/scripts/cli.py
# def main(args=None, exit=True):
#     binstar_main(command_module, args, exit,
#                  description=__doc__, version=version)
# 
# Path: binstar_client/tests/fixture.py
# class CLITestCase(unittest.TestCase):
#     def setUp(self):
#         self.get_config_patch = mock.patch('binstar_client.utils.get_config')
#         self.get_config = self.get_config_patch.start()
#         self.get_config.return_value = {}
# 
#         self.load_token_patch = mock.patch('binstar_client.utils.config.load_token')
#         self.load_token = self.load_token_patch.start()
#         self.load_token.return_value = '123'
# 
#         self.store_token_patch = mock.patch('binstar_client.utils.config.store_token')
#         self.store_token = self.store_token_patch.start()
# 
#         self.setup_logging_patch = mock.patch('binstar_client.scripts.cli._setup_logging')
#         self.setup_logging_patch.start()
# 
#         self.logger = logger = logging.getLogger('binstar')
#         logger.setLevel(logging.INFO)
#         self.stream = AnyIO()
#         self.hndlr = hndlr = logging.StreamHandler(stream=self.stream)
#         hndlr.setLevel(logging.INFO)
#         logger.addHandler(hndlr)
# 
#     def tearDown(self):
#         self.setup_logging_patch.stop()
#         self.get_config_patch.stop()
#         self.load_token_patch.stop()
#         self.store_token_patch.stop()
# 
#         self.logger.removeHandler(self.hndlr)
# 
# Path: binstar_client/tests/urlmock.py
# def urlpatch(func):
#     @wraps(func)
#     def inner(self, *args, **kwargs):
#         with Registry() as r:
#             return func(self, r, *args, **kwargs)
#     return inner


from binstar_client.scripts.cli import main
from binstar_client.tests.fixture import CLITestCase
from binstar_client.tests.urlmock import urlpatch
from binstar_client.errors import BinstarError
from mock import patch
import unittest

    @urlpatch
    def test_remove_token(self, urls):
        remove_token = urls.register(
            method='DELETE',
            path='/authentications/name/tokenname',
            content='{"token": "a-token"}',
            status=201
        )
        main(['--show-traceback', 'auth', '--remove', 'tokenname'], False)
        self.assertIn('Removed token tokenname', self.stream.getvalue())

        remove_token.assertCalled()


    @urlpatch
    def test_remove_token_forbidden(self, urls):
        remove_token = urls.register(
            method='DELETE',
            path='/authentications/org/wrong_org/name/tokenname',
            content='{"token": "a-token"}',
            status=403
        )
        with self.assertRaises(BinstarError):
            main(['--show-traceback', 'auth', '--remove', 'tokenname', '-o', 'wrong_org'], False)

        remove_token.assertCalled()


if __name__ == '__main__':

# Path: binstar_client/scripts/cli.py
# def main(args=None, exit=True):
#     binstar_main(command_module, args, exit,
#                  description=__doc__, version=version)
# 
# Path: binstar_client/tests/fixture.py
# class CLITestCase(unittest.TestCase):
#     def setUp(self):
#         self.get_config_patch = mock.patch('binstar_client.utils.get_config')
#         self.get_config = self.get_config_patch.start()
#         self.get_config.return_value = {}
# 
#         self.load_token_patch = mock.patch('binstar_client.utils.config.load_token')
#         self.load_token = self.load_token_patch.start()
#         self.load_token.return_value = '123'
# 
#         self.store_token_patch = mock.patch('binstar_client.utils.config.store_token')
#         self.store_token = self.store_token_patch.start()
# 
#         self.setup_logging_patch = mock.patch('binstar_client.scripts.cli._setup_logging')
#         self.setup_logging_patch.start()
# 
#         self.logger = logger = logging.getLogger('binstar')
#         logger.setLevel(logging.INFO)
#         self.stream = AnyIO()
#         self.hndlr = hndlr = logging.StreamHandler(stream=self.stream)
#         hndlr.setLevel(logging.INFO)
#         logger.addHandler(hndlr)
# 
#     def tearDown(self):
#         self.setup_logging_patch.stop()
#         self.get_config_patch.stop()
#         self.load_token_patch.stop()
#         self.store_token_patch.stop()
# 
#         self.logger.removeHandler(self.hndlr)
# 
# Path: binstar_client/tests/urlmock.py
# def urlpatch(func):
#     @wraps(func)
#     def inner(self, *args, **kwargs):
#         with Registry() as r:
#             return func(self, r, *args, **kwargs)
#     return inner


# Path: binstar_client/tests/test_authorizations.py
from binstar_client.scripts.cli import main
from binstar_client.tests.fixture import CLITestCase
from binstar_client.tests.urlmock import urlpatch
from binstar_client.errors import BinstarError
from mock import patch
import unittest


    @urlpatch
    def test_remove_token(self, urls):
        remove_token = urls.register(
            method='DELETE',
            path='/authentications/name/tokenname',
            content='{"token": "a-token"}',
            status=201
        )
        main(['--show-traceback', 'auth', '--remove', 'tokenname'], False)
        self.assertIn('Removed token tokenname', self.stream.getvalue())

        remove_token.assertCalled()


    @urlpatch
    def test_remove_token_forbidden(self, urls):
        remove_token = urls.register(
            method='DELETE',
            path='/authentications/org/wrong_org/name/tokenname',
            content='{"token": "a-token"}',
            status=403
        )
        with self.assertRaises(BinstarError):
            main(['--show-traceback', 'auth', '--remove', 'tokenname', '-o', 'wrong_org'], False)

        remove_token.assertCalled()


if __name__ == '__main__':

    unittest.main()