# 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/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/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)


import json
import unittest
from binstar_client.errors import Conflict
from binstar_client.scripts.cli import main
from binstar_client.tests.urlmock import urlpatch
from binstar_client.tests.fixture import CLITestCase
        urls.register(method='GET', path='/channels/u1', content='["dev"]')
        copy = urls.register(
            method='PATCH', path='/copy/package/u1/p1/1.0/', content='[{"basename": "copied-file_1.0.tgz"}]')

        main(['--show-traceback', 'copy', '--from-label', 'dev', '--to-label', 'release/xyz', 'u1/p1/1.0', '--update'],
             False)

        urls.assertAllCalled()
        req = json.loads(copy.req.body)
        self.assertEqual(req['from_channel'], 'dev')
        self.assertEqual(req['to_channel'], 'release/xyz')

    @urlpatch
    def test_copy_file_conflict(self, urls):
        urls.register(method='GET', path='/channels/u1', content='["dev"]')
        copy = urls.register(
            method='POST', path='/copy/package/u1/p1/1.0/', status=409
        )
        with self.assertRaises(Conflict):
            main(['--show-traceback', 'copy', '--from-label', 'dev', '--to-label', 'release/xyz', 'u1/p1/1.0'], False)

        urls.assertAllCalled()
        req = json.loads(copy.req.body)
        self.assertEqual(req['from_channel'], 'dev')
        self.assertEqual(req['to_channel'], 'release/xyz')

    @urlpatch
    def test_copy_argument_error(self, urls):
        urls.register(method='GET', path='/channels/u1', content='["dev"]')
        with self.assertRaises(SystemExit):

# 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/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/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/test_copy.py
import json
import unittest
from binstar_client.errors import Conflict
from binstar_client.scripts.cli import main
from binstar_client.tests.urlmock import urlpatch
from binstar_client.tests.fixture import CLITestCase

        urls.register(method='GET', path='/channels/u1', content='["dev"]')
        copy = urls.register(
            method='PATCH', path='/copy/package/u1/p1/1.0/', content='[{"basename": "copied-file_1.0.tgz"}]')

        main(['--show-traceback', 'copy', '--from-label', 'dev', '--to-label', 'release/xyz', 'u1/p1/1.0', '--update'],
             False)

        urls.assertAllCalled()
        req = json.loads(copy.req.body)
        self.assertEqual(req['from_channel'], 'dev')
        self.assertEqual(req['to_channel'], 'release/xyz')

    @urlpatch
    def test_copy_file_conflict(self, urls):
        urls.register(method='GET', path='/channels/u1', content='["dev"]')
        copy = urls.register(
            method='POST', path='/copy/package/u1/p1/1.0/', status=409
        )
        with self.assertRaises(Conflict):
            main(['--show-traceback', 'copy', '--from-label', 'dev', '--to-label', 'release/xyz', 'u1/p1/1.0'], False)

        urls.assertAllCalled()
        req = json.loads(copy.req.body)
        self.assertEqual(req['from_channel'], 'dev')
        self.assertEqual(req['to_channel'], 'release/xyz')

    @urlpatch
    def test_copy_argument_error(self, urls):
        urls.register(method='GET', path='/channels/u1', content='["dev"]')
        with self.assertRaises(SystemExit):

            main([