# 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/utils/test/utils.py
# def data_dir(filename):
#     base_path = inspect.stack()[1][1]  # function caller path
#     test_data = os.path.join(os.path.dirname(base_path), 'data')
#     return os.path.join(test_data, filename)


import json
import mock
import os
import unittest
import requests.utils
from binstar_client.scripts.cli import main
from binstar_client.tests.fixture import CLITestCase
from binstar_client.tests.urlmock import urlpatch
from binstar_client.utils.test.utils import data_dir
        self.assertIn('Anonymous User', self.stream.getvalue())

        user.assertCalled() 

    @urlpatch
    def test_whoami(self, urls):
        content = json.dumps({'login': 'eggs', 'created_at':'1/2/2000'})
        user = urls.register(method='GET', path='/user', content=content)

        main(['--show-traceback', 'whoami'], False)
        self.assertIn('eggs', self.stream.getvalue()) 

        user.assertCalled()

    @urlpatch
    @mock.patch('os.path.expanduser')
    def test_netrc_ignored(self, urls, expanduser):
        # Disable token authentication
        self.load_token.return_value = None
        os.environ.pop('BINSTAR_API_TOKEN', None)
        os.environ.pop('ANACONDA_API_TOKEN', None)

        # requests.get_netrc_auth uses expanduser to find the netrc file, point to our
        # test file
        expanduser.return_value = data_dir('netrc')
        auth = requests.utils.get_netrc_auth('http://localhost', raise_errors=True)
        self.assertEqual(auth, ('anonymous', 'pass'))

        user = urls.register(path='/user', status=401)


# 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/utils/test/utils.py
# def data_dir(filename):
#     base_path = inspect.stack()[1][1]  # function caller path
#     test_data = os.path.join(os.path.dirname(base_path), 'data')
#     return os.path.join(test_data, filename)


# Path: binstar_client/tests/test_whoami.py
import json
import mock
import os
import unittest
import requests.utils
from binstar_client.scripts.cli import main
from binstar_client.tests.fixture import CLITestCase
from binstar_client.tests.urlmock import urlpatch
from binstar_client.utils.test.utils import data_dir

        self.assertIn('Anonymous User', self.stream.getvalue())

        user.assertCalled() 

    @urlpatch
    def test_whoami(self, urls):
        content = json.dumps({'login': 'eggs', 'created_at':'1/2/2000'})
        user = urls.register(method='GET', path='/user', content=content)

        main(['--show-traceback', 'whoami'], False)
        self.assertIn('eggs', self.stream.getvalue()) 

        user.assertCalled()

    @urlpatch
    @mock.patch('os.path.expanduser')
    def test_netrc_ignored(self, urls, expanduser):
        # Disable token authentication
        self.load_token.return_value = None
        os.environ.pop('BINSTAR_API_TOKEN', None)
        os.environ.pop('ANACONDA_API_TOKEN', None)

        # requests.get_netrc_auth uses expanduser to find the netrc file, point to our
        # test file
        expanduser.return_value = data_dir('netrc')
        auth = requests.utils.get_netrc_auth('http://localhost', raise_errors=True)
        self.assertEqual(auth, ('anonymous', 'pass'))

        user = urls.register(path='/user', status=401)


        main(['--show-traceback', 'whoami'], False)