def test_register_bad_args(self, registry):

        r1 = registry.register()

        with self.assertRaises(SystemExit):
            main(["--show-traceback", "register", "--publish", "--private", self.data_dir("foo-0.1-0.tar.bz2")], False)

        r1.assertNotCalled()
Beispiel #2
0
 def test_whoami_anon(self, urls):
     
     user = urls.register(method='GET', path='/user', status=401)
     
     main(['--show-traceback', 'whoami'], False)
     self.assertIn('Anonymous User', self.stream.getvalue())
     
     user.assertCalled() 
    def test_whoami(self, urls):
        content = json.dumps({'login': '******', '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()
    def test_upload_private_package_not_allowed(self, registry):

        registry.register(method='HEAD', path='/', status=200)
        registry.register(method='GET', path='/user', content='{"login": "******"}')
        registry.register(method='GET', path='/package/eggs/foo', content='{}', status=404)
        registry.register(method='POST', path='/package/eggs/foo', content='{"error": "You can not create a private package."}', status=400)

        with self.assertRaises(errors.BinstarError):
            main(['--show-traceback', 'upload', '--private', data_dir('foo-0.1-0.tar.bz2')], False)
Beispiel #5
0
    def test_upload_bad_package_no_register(self, registry):

        registry.register(method='GET', path='/user', content='{"login": "******"}')
        registry.register(method='GET', path='/package/eggs/foo', status=404)

        with self.assertRaises(errors.UserError):
            main(['--show-traceback', 'upload', '--no-register', self.data_dir('foo-0.1-0.tar.bz2')], False)

        registry.assertAllCalled()
    def test_remove_member(self, urls):
        urls.register(
            method='DELETE',
            path='/group/org/grp/members/new_member',
            status=204,
        )

        main(['--show-traceback', 'groups', 'remove_member', 'org/grp/new_member'], False)

        urls.assertAllCalled()
    def test_show(self, urls):
        urls.register(
            method='GET',
            path='/groups/org',
            content='{"groups": [{"name":"grp", "permission": "read"}]}',
        )

        main(['--show-traceback', 'groups', 'show', 'org'], False)

        urls.assertAllCalled()
    def test_copy_label(self, urls):
        urls.register(method='GET', path='/channels/u1', content='["dev"]')
        copy = urls.register(method='POST', 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'], False)

        urls.assertAllCalled()
        req = json.loads(copy.req.body)
        self.assertEqual(req['from_channel'], 'dev')
        self.assertEqual(req['to_channel'], 'release/xyz')
    def test_show_group(self, urls):
        urls.register(
            method='GET',
            path='/group/org/owners',
            content='{"name": "owners", "permission": "read", "members_count": 1, "repos_count": 1}',
        )

        main(['--show-traceback', 'groups', 'show', 'org/owners'], False)

        urls.assertAllCalled()
    def test_create(self, urls):
        urls.register(
            method='POST',
            path='/group/org/new_grp',
            status=204,
        )

        main(['--show-traceback', 'groups', 'add', 'org/new_grp'], False)

        urls.assertAllCalled()
    def test_add_package(self, urls):
        urls.register(
            method='PUT',
            path='/group/org/grp/packages/pkg',
            status=204,
        )

        main(['--show-traceback', 'groups', 'add_package', 'org/grp/pkg'], False)

        urls.assertAllCalled()
    def test_packages(self, urls):
        urls.register(
            method='GET',
            path='/group/org/grp/packages',
            content='[{"name": "pkg", "full_name": "org/pkg", "summary": "An org pkg"}]'
        )

        main(['--show-traceback', 'groups', 'packages', 'org/grp'], False)

        urls.assertAllCalled()
    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()
    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)
        self.assertEqual('', self.stream.getvalue())

        remove_token.assertCalled()
    def test_register_private(self, registry):
        r1 = registry.register(method='GET', path='/user', content='{"login": "******"}')
        r2 = registry.register(method='GET', path='/package/eggs/foo', status=404)
        r3 = registry.register(method='POST', path='/package/eggs/foo', status=200, content='{"login": "******"}')

        main(['--show-traceback', 'register', '--private', data_dir('foo-0.1-0.tar.bz2')], False)

        r1.assertCalled()
        r2.assertCalled()
        r3.assertCalled()

        data = json.loads(r3.req.body)
        self.assertFalse(data['public'])
    def test_upload_interactive_no_overwrite(self, registry, bool_input):
        # regression test for #364
        registry.register(method='HEAD', path='/', status=200)
        registry.register(method='GET', path='/user', content='{"login": "******"}')
        content = {'package_types': 'conda'}
        registry.register(method='GET', path='/package/eggs/foo', content=content)
        registry.register(method='GET', path='/release/eggs/foo/0.1', content='{}')
        registry.register(method='GET', path='/dist/eggs/foo/0.1/osx-64/foo-0.1-0.tar.bz2', status=200, content='{}')

        # don't overwrite
        bool_input.return_value = False

        main(['--show-traceback', 'upload', '-i', data_dir('foo-0.1-0.tar.bz2')], False)
    def test_register_publish(self, registry):
        r1 = registry.register(method="GET", path="/user", content=b'{"login": "******"}')
        r2 = registry.register(method="GET", path="/package/eggs/foo", status=404)
        r3 = registry.register(method="POST", path="/package/eggs/foo", status=200, content=b'{"login": "******"}')

        main(["--show-traceback", "register", "--publish", self.data_dir("foo-0.1-0.tar.bz2")], False)

        r1.assertCalled()
        r2.assertCalled()
        r3.assertCalled()

        data = json.loads(base64.b64decode(r3.req.body).decode())

        self.assertTrue(data["public"])
        self.assertTrue(data["publish"])
Beispiel #18
0
 def test_login(self, urls, input, getpass, store_token):
     input.return_value = 'test_user'
     getpass.return_value = 'password'
     
     auth = urls.register(method='POST', path='/authentications', content='{"token": "a-token"}')
     main(['--show-traceback', 'login'], False)
     self.assertIn('login successful', self.stream.getvalue()) 
     
     auth.assertCalled()
     
     self.assertIn('Authorization', auth.req.headers)
     self.assertIn('Basic ', auth.req.headers['Authorization'])
     
     store_token.assert_called_once()
     self.assertEqual(store_token.call_args[0][0], 'a-token')
    def test_upload_notebook_as_project(self, registry):
        registry.register(method='HEAD', path='/', status=200)
        registry.register(method='GET', path='/user/eggs', content='{"login": "******"}')
        registry.register(method='GET', path='/user', content='{"login": "******"}')
        registry.register(method='GET', path='/apps/eggs/projects/foo', content='{}')
        stage_content = '{"post_url":"http://s3url.com/s3_url", "form_data":{"foo":"bar"}, "dist_id":"dist42"}'
        registry.register(method='POST', path='/apps/eggs/projects/foo/stage',
                          content=stage_content)
        registry.register(method='POST', path='/s3_url', status=201)
        registry.register(method='POST', path='/apps/eggs/projects/foo/commit/dist42', content='{}')

        main(['--show-traceback', 'upload',
              '--package-type', 'project',
              data_dir('foo.ipynb')], False)

        registry.assertAllCalled()
    def test_upload_project_specifying_user(self, registry):
        registry.register(method='HEAD', path='/', status=200)
        registry.register(method='GET', path='/user/alice', content='{"login": "******"}')
        registry.register(method='GET', path='/apps/alice/projects/dog', content='{}')
        stage_content = '{"post_url":"http://s3url.com/s3_url", "form_data":{"foo":"bar"}, "dist_id":"dist42"}'
        registry.register(method='POST', path='/apps/alice/projects/dog/stage',
                          content=stage_content)
        registry.register(method='POST', path='/s3_url', status=201)
        registry.register(method='POST', path='/apps/alice/projects/dog/commit/dist42', content='{}')

        main(['--show-traceback', 'upload',
              '--package-type', 'project',
              '--user', 'alice',
              data_dir('bar')], False)

        registry.assertAllCalled()
    def test_upload(self, registry):
        
        registry.register(method='GET', path='/user', content='{"login": "******"}')
        registry.register(method='GET', path='/package/eggs/foo', content='{}')
        registry.register(method='GET', path='/release/eggs/foo/0.1', content='{}')
        registry.register(method='GET', path='/dist/eggs/foo/0.1/osx-64/foo-0.1-0.tar.bz2', status=404, content='{}')
        
        content = {"s3_url": "http://s3_url.com/s3_url", "s3form_data": {}, "dist_id": "dist_id"}
        registry.register(method='POST', path='/stage/eggs/foo/0.1/osx-64/foo-0.1-0.tar.bz2', content=content)

        registry.register(method='POST', path='/s3_url', status=201)
        registry.register(method='POST', path='/commit/eggs/foo/0.1/osx-64/foo-0.1-0.tar.bz2', status=200, content={})
        
        main(['--show-traceback', 'upload', self.data_dir('foo-0.1-0.tar.bz2')], False)
        
        registry.assertAllCalled()
    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)
        self.assertNotIn('Authorization', user.req.headers)
Beispiel #23
0
    def test_upload_pypi(self, registry):

        registry.register(method='GET', path='/user', content='{"login": "******"}')
        registry.register(method='GET', path='/package/eggs/test-package34', content='{}')
        registry.register(method='GET', path='/release/eggs/test-package34/0.3.1', content='{}')
        registry.register(method='GET', path='/dist/eggs/test-package34/0.3.1/test_package34-0.3.1.tar.gz', status=404, content='{}')

        content = {"post_url": "http://s3_url.com/s3_url", "form_data": {}, "dist_id": "dist_id"}
        registry.register(method='POST', path='/stage/eggs/test-package34/0.3.1/test_package34-0.3.1.tar.gz', content=content)

        registry.register(method='POST', path='/s3_url', status=201)
        registry.register(method='POST', path='/commit/eggs/test-package34/0.3.1/test_package34-0.3.1.tar.gz', status=200, content={})

        main(['--show-traceback', 'upload', self.data_dir('test_package34-0.3.1.tar.gz')], False)

        registry.assertAllCalled()
    def test_upload_project_specifying_token(self, registry):
        registry.register(method='HEAD', path='/', status=200)
        registry.register(method='GET', path='/user/eggs', content='{"login": "******"}',
                          expected_headers={'Authorization':'token abcdefg'})
        registry.register(method='GET', path='/user', content='{"login": "******"}')
        registry.register(method='GET', path='/apps/eggs/projects/dog', content='{}')
        stage_content = '{"post_url":"http://s3url.com/s3_url", "form_data":{"foo":"bar"}, "dist_id":"dist42"}'
        registry.register(method='POST', path='/apps/eggs/projects/dog/stage',
                          content=stage_content)
        registry.register(method='POST', path='/s3_url', status=201)
        registry.register(method='POST', path='/apps/eggs/projects/dog/commit/dist42', content='{}')

        main(['--show-traceback', '--token', 'abcdefg',
              'upload',
              '--package-type', 'project',
              data_dir('bar')], False)

        registry.assertAllCalled()
    def test_upload_project(self, registry):
        # there's redundant work between anaconda-client which
        # checks auth and anaconda-project also checks auth;
        # -project has no way to know it was already checked :-/
        registry.register(method='HEAD', path='/', status=200)
        registry.register(method='GET', path='/user/eggs', content='{"login": "******"}')
        registry.register(method='GET', path='/user', content='{"login": "******"}')
        registry.register(method='GET', path='/apps/eggs/projects/dog', content='{}')
        stage_content = '{"post_url":"http://s3url.com/s3_url", "form_data":{"foo":"bar"}, "dist_id":"dist42"}'
        registry.register(method='POST', path='/apps/eggs/projects/dog/stage',
                          content=stage_content)
        registry.register(method='POST', path='/s3_url', status=201)
        registry.register(method='POST', path='/apps/eggs/projects/dog/commit/dist42', content='{}')

        main(['--show-traceback', 'upload',
              '--package-type', 'project',
              data_dir('bar')], False)

        registry.assertAllCalled()
Beispiel #26
0
    def test_login_kerberos(self, urls, store_token):

        urls.register(path='/authentication-type', content='{"authentication_type": "kerberos"}')

        def update_authentications():
            # The second request should succeed
            auth_success = urls.register(
                method='POST',
                path='/authentications',
                content='{"token": "a-token"}',
                headers={'WWW-Authenticate': 'Negotiate STOKEN'},
            )

        auth_fail = urls.register(method='POST', path='/authentications', status=401, headers={'WWW-Authenticate': 'Negotiate'}, side_effect=update_authentications)

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

        urls.assertAllCalled()
        self.assertTrue(store_token.called)
        self.assertEqual(store_token.call_args[0][0], 'a-token')
Beispiel #27
0
from binstar_client.scripts.cli import main
from binstar_client.errors import BinstarError

token = os.environ['BINSTAR_TOKEN']
options = ['-t', token, 'upload', '-u', 'brian-team']
filenames = glob.glob('*.tar.bz2')
release = '+git' not in filenames[0]
if not release:
    options.extend(['--channel', 'dev', '--force'])

# Uploading sometimes fails due to server or network errors -- we try it five
# times before giving up
attempts = 5
uploaded = set()
for attempt in range(attempts):
    try:
        for filename in filenames:
            if filename in uploaded:  # We already uploaded this file
                continue
            main(args=options + [filename])
            uploaded.add(filename)
    except BinstarError as ex:
        print('Something did not work (%s).' % str(ex))
        if attempt < attempts - 1:
            print('Trying again in 10 seconds...')
            time.sleep(10)
        else:
            print('Giving up...')
            raise ex
Beispiel #28
0
import sys
import os
import glob

from binstar_client.scripts.cli import main

token = os.environ["BINSTAR_TOKEN"]
options = ["-t", token, "upload", "-u", "brian-team"]
filename = glob.glob("*.tar.bz2")
assert len(filename) == 1, "Expected to find one .tar.bz2 file, found %d" % len(filename)
release = "+git" not in filename[0]
if not release:
    options.extend(["--channel", "dev", "--force"])

options.extend(filename)

sys.exit(main(args=options))
Beispiel #29
0
import os
import glob
# import subprocess
# import traceback
from binstar_client.scripts import cli


def get_token():
    token = None
    if os.environ.get('TRAVIS_BRANCH', None) == 'master' or os.environ.get(
            'APPVEYOR_REPO_BRANCH', None) == 'master':
        token = os.environ.get('BINSTAR_TOKEN', None)
    return token


token = get_token()
if token is not None:
    cmd = ['-t', token, 'upload', '--force', '-u', 'ingeotec']
    cmd.extend(glob.glob('*.tar.bz2'))
    cli.main(args=cmd)
    # try:
    #     print('*', cmd, platform.system())
    #     subprocess.check_call(cmd)
    # except subprocess.CalledProcessError:
    #     traceback.print_exc()
from binstar_client.scripts.cli import main
from binstar_client.errors import BinstarError

token = os.environ['BINSTAR_TOKEN']
options = ['-t', token, 'upload',
           '-u', 'brian-team']
filenames = glob.glob('*.tar.bz2')
release = '+git' not in filenames[0]
if not release:
    options.extend(['--channel', 'dev', '--force'])

# Uploading sometimes fails due to server or network errors -- we try it five
# times before giving up
attempts = 5
uploaded = set()
for attempt in range(attempts):
    try:
        for filename in filenames:
            if filename in uploaded:  # We already uploaded this file
                continue
            main(args=options+[filename])
            uploaded.add(filename)
    except BinstarError as ex:
        print('Something did not work (%s).' % str(ex))
        if attempt < attempts - 1:
            print('Trying again in 10 seconds...')
            time.sleep(10)
        else:
            print('Giving up...')
            raise ex
 def test_create_missing_group(self, urls):
     with self.assertRaisesRegexp(errors.UserError, 'Group name not given'):
         main(['--show-traceback', 'groups', 'add', 'org'], False)
 def test_add_member_missing_member(self, urls):
     with self.assertRaisesRegexp(errors.UserError, 'Member name not given'):
         main(['--show-traceback', 'groups', 'add_member', 'org/grp'], False)