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_bdist_wheel(self): filename = data_dir('test_package34-0.3.1-py2-none-any.whl') with open(filename, 'rb') as fd: package_data, version_data, file_data = pypi.inspect_pypi_package( filename, fd) expected_file_data = { 'attrs': { 'abi': None, 'build_no': 0, 'packagetype': 'bdist_wheel', 'python_version': 'py2' }, 'basename': 'test_package34-0.3.1-py2-none-any.whl', 'dependencies': expected_whl_dependencies, 'platform': None } self.assertEqual(expected_package_data, package_data) self.assertEqual(expected_version_data, version_data) self.assertEqual(set(expected_file_data), set(file_data)) for key in expected_file_data: self.assertEqual(expected_file_data[key], file_data[key])
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()
def test_package_data_normalized_name(self): with open(data_dir('notebook.ipynb')) as fd: package_data, _, _ = inspect_ipynb_package('test nótëbOOk.ipynb', fd) self.assertIn('name', package_data) self.assertEqual(package_data['name'], 'test-notebook')
def test_sdist_distutils(self): filename = data_dir('test_package34-distutils-0.3.1.tar.gz') with open(filename, 'rb') as fd: package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd) expected_file_data = {'attrs': {'packagetype': 'sdist', 'python_version': 'source'}, 'basename': 'test_package34-distutils-0.3.1.tar.gz', 'dependencies': {'depends': [{'name': 'requests', 'specs': [('>=', '2.0'), ('<=', '3.0')]}, {'name': 'pyyaml', 'specs': [('==', '2.0')]}, {'name': 'pytz', 'specs': []}], 'extras': [], 'has_dep_errors': False}} dexpected_package_data = expected_package_data.copy() dexpected_package_data['name'] = dexpected_package_data['name'].replace('-', '_') self.assertEqual(dexpected_package_data, package_data) self.assertEqual(expected_version_data, version_data) self.assertEqual(set(expected_file_data), set(file_data)) for key in expected_file_data: print(expected_file_data[key]) print(file_data[key]) self.assertEqual(expected_file_data[key], file_data[key])
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_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_r(self): filename = data_dir('rfordummies_0.1.2.tar.gz') with open(filename, 'rb') as fd: package_data, version_data, file_data = r.inspect_r_package(filename, fd) self.assertEqual(expected_package_data, package_data) self.assertEqual(expected_version_data, version_data) self.assertEqual(expected_file_data, file_data)
def test_can_download(self): package_1 = {'basename': 'notebook.ipynb'} package_2 = {'basename': 'NOEXIST'} downloader = Downloader('binstar', 'username', 'notebook') downloader.output = data_dir('') self.assertTrue(not downloader.can_download(package_1)) self.assertTrue(downloader.can_download(package_1, True)) self.assertTrue(downloader.can_download(package_2))
def test_file_data(self): with open(data_dir('notebook.ipynb')) as fd: _, _, file_data = inspect_ipynb_package('notebook.ipynb', fd) self.assertEqual({ 'basename': 'notebook.ipynb', 'attrs': {} }, file_data)
def test_upload_bad_package_no_register(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', status=404) with self.assertRaises(errors.UserError): main(['--show-traceback', 'upload', '--no-register', data_dir('foo-0.1-0.tar.bz2')], False) registry.assertAllCalled()
def test_r(self): filename = data_dir('rfordummies_0.1.2.tar.gz') with open(filename, 'rb') as fd: package_data, version_data, file_data = r.inspect_r_package( filename, fd) self.assertEqual(expected_package_data, package_data) self.assertEqual(expected_version_data, version_data) self.assertEqual(expected_file_data, file_data)
def test_package_data_no_metadata(self): with open(data_dir('notebook-no-metadata.ipynb')) as fd: package_data, _, _ = inspect_ipynb_package('notebook.ipynb', fd) self.assertEqual({ 'name': 'notebook', 'description': 'Jupyter Notebook', 'summary': 'Jupyter Notebook', }, package_data)
def test_conda(self): filename = data_dir('conda_gc_test-2.2.1-py27_3.tar.bz2') with open(filename, 'rb') as fd: package_data, version_data, file_data = conda.inspect_conda_package( filename, fd) self.assertEqual(expected_package_data, package_data) self.assertEqual(expected_version_data_221, version_data) self.assertEqual(expected_file_data_221, file_data)
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)
def test_conda_app_image(self): filename = data_dir('test-app-package-icon-0.1-0.tar.bz2') with open(filename, 'rb') as fd: package_data, version_data, file_data = conda.inspect_conda_package( filename, fd) self.assertEqual(app_expected_package_data, package_data) self.assertEqual(app_expected_version_data.pop('icon'), version_data.pop('icon')) self.assertEqual(app_expected_version_data, version_data)
def test_package_data_no_metadata(self): with open(data_dir('notebook-no-metadata.ipynb')) as fd: package_data, _, _ = inspect_ipynb_package('notebook.ipynb', fd) self.assertEqual( { 'name': 'notebook', 'description': 'Jupyter Notebook', 'summary': 'Jupyter Notebook', }, package_data)
def test_release_data(self): with freeze_time('2018-02-01 09:10:00', tz_offset=0): with open(data_dir('notebook.ipynb')) as fd: _, release_data, _ = inspect_ipynb_package('notebook.ipynb', fd) self.assertEqual({ 'version': '2018.02.01.0910', 'description': 'ipynb description', 'summary': 'ipynb summary', }, release_data)
def test_release_data_no_metadata(self): with freeze_time('2018-05-03 12:30:00', tz_offset=0): with open(data_dir('notebook-no-metadata.ipynb')) as fd: _, release_data, _ = inspect_ipynb_package('notebook-no-metadata.ipynb', fd) self.assertEqual({ 'version': '2018.05.03.1230', 'description': 'Jupyter Notebook', 'summary': 'Jupyter Notebook', }, release_data)
def test_release_data(self): with freeze_time('2018-02-01 09:10:00', tz_offset=0): with open(data_dir('notebook.ipynb')) as fd: _, release_data, _ = inspect_ipynb_package( 'notebook.ipynb', fd) self.assertEqual( { 'version': '2018.02.01.0910', 'description': 'ipynb description', 'summary': 'ipynb summary', }, release_data)
def test_release_data_no_metadata(self): with freeze_time('2018-05-03 12:30:00', tz_offset=0): with open(data_dir('notebook-no-metadata.ipynb')) as fd: _, release_data, _ = inspect_ipynb_package( 'notebook-no-metadata.ipynb', fd) self.assertEqual( { 'version': '2018.05.03.1230', 'description': 'Jupyter Notebook', 'summary': 'Jupyter Notebook', }, release_data)
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_inspect_ipynb_package(self): with open(data_dir('notebook.ipynb')) as fileobj: package_data, release_data, file_data = inspect_ipynb_package('notebook.ipynb', fileobj) self.assertEqual({ 'name': 'notebook', 'summary': 'IPython notebook' }, package_data) self.assertEqual({ 'basename': 'notebook.ipynb', 'attrs': {} }, file_data)
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_bdist_egg(self): filename = data_dir('test_package34-0.3.1-py2.7.egg') with open(filename, 'rb') as fd: package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd) self.assertEqual(expected_package_data, package_data) self.assertEqual(expected_version_data, version_data) self.assertEqual(set(expected_egg_file_data), set(file_data)) for key in expected_egg_file_data: self.assertEqual(expected_egg_file_data[key], file_data[key])
def test_upload_bad_package_no_register(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', status=404) with self.assertRaises(errors.UserError): main([ '--show-traceback', 'upload', '--no-register', data_dir('foo-0.1-0.tar.bz2') ], False) registry.assertAllCalled()
def test_inspect_env_package(self): with open(data_dir('environment.yml')) as fileobj: package_data, release_data, file_data = inspect_env_package( 'environment.yml', fileobj) self.assertEqual({ 'name': 'stats', 'summary': 'Environment file' }, package_data) self.assertEqual({ 'basename': 'environment.yml', 'attrs': {} }, file_data)
def test_upload_bad_package(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) content = {"package_types": ['conda']} registry.register(method='POST', path='/package/eggs/foo', content=content, status=200) 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 = {"post_url": "http://s3url.com/s3_url", "form_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', data_dir('foo-0.1-0.tar.bz2')], False) registry.assertAllCalled()
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_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)
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_sdist(self): filename = data_dir('test_package34-0.3.1.tar.gz') with open(filename, 'rb') as fd: package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd) expected_file_data = {'attrs': {'packagetype': 'sdist', 'python_version': 'source'}, 'basename': 'test_package34-0.3.1.tar.gz', 'dependencies': expected_dependencies} self.assertEqual(expected_package_data, package_data) self.assertEqual(expected_version_data, version_data) self.assertEqual(set(expected_file_data), set(file_data)) for key in expected_file_data: self.assertEqual(expected_file_data[key], file_data[key])
def test_upload_pypi(self, registry): registry.register(method='HEAD', path='/', status=200) registry.register(method='GET', path='/user', content='{"login": "******"}') content = {'package_types': 'pypi'} registry.register(method='GET', path='/package/eggs/test-package34', content=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://s3url.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', 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_private_package(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) content = {'package_types': ['conda']} registry.register(method='POST', path='/package/eggs/foo', content=content, status=200) 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 = { "post_url": "http://s3url.com/s3_url", "form_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', '--private', data_dir('foo-0.1-0.tar.bz2') ], False) registry.assertAllCalled()
def test_upload_file(self, registry): registry.register(method='HEAD', path='/', status=200) registry.register(method='GET', path='/user', content='{"login": "******"}') content = {'package_types': ['file']} registry.register(method='GET', path='/package/eggs/test-package34', content=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://s3url.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', '--package-type', 'file', '--package', 'test-package34', '--version', '0.3.1', data_dir('test_package34-0.3.1.tar.gz') ], False) registry.assertAllCalled()
def test_bdist_wheel_newer_version(self): filename_whl = 'azure_cli_extension-0.2.1-py2.py3-none-any.whl' filename = data_dir(filename_whl) with open(filename, 'rb') as fd: package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd) expected_file_data = { 'platform': None, 'basename': filename_whl, 'dependencies': { u'depends': [ {u'name': u'azure-cli-command-modules-nspkg', u'specs': [(u'>=', u'2.0.0')]}, {u'name': u'azure-cli-core', u'specs': []}, {u'name': u'pip', u'specs': []}, {u'name': u'wheel', u'specs': [(u'==', u'0.30.0')]} ], u'extras': [], u'has_dep_errors': False, u'environments': []}, u'attrs': { 'abi': None, 'packagetype': u'bdist_wheel', 'python_version': u'py2.py3', 'build_no': 0 } } expected_package_data = { u'name': 'azure-cli-extension', u'license': 'MIT', u'summary': 'Microsoft Azure Command-Line Tools Extension Command Module', } expected_version_data = { u'home_page': 'https://github.com/Azure/azure-cli', u'version': '0.2.1', u'description': u"Microsoft Azure CLI 'extension' Command Module", } self.assertEqual(expected_package_data, package_data) self.assertEqual(expected_version_data, version_data) self.assertEqual(set(expected_file_data), set(file_data)) for key in expected_file_data: print(expected_file_data[key]) print(file_data[key]) self.assertEqual(expected_file_data[key], file_data[key])
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()
def test_bdist_egg_dashed_path(self): filename = data_dir('test_package34-0.3.1-py2.7.egg') tmpdir = tempfile.gettempdir() dash_count = tmpdir.count('-') if dash_count == 0: tmpdir = os.path.join(tmpdir, 'has-dash') try: os.mkdir(tmpdir) except (IOError, OSError): raise unittest.SkipTest( 'Cannot create temporary directory %r' % tmpdir) elif dash_count > 1: raise unittest.SkipTest( 'Too many dashes in temporary directory path %r' % tmpdir) try: shutil.copy(filename, tmpdir) except (IOError, OSError): raise unittest.SkipTest( 'Cannot copy package to temporary directory') tmpfilename = os.path.join(tmpdir, 'test_package34-0.3.1-py2.7.egg') with open(tmpfilename, 'rb') as fd: package_data, version_data, file_data = pypi.inspect_pypi_package( tmpfilename, fd) # If we could create this file, we ought to be able to delete it os.remove(tmpfilename) if dash_count == 0: # We created a temporary directory like /tmp/has-dash, delete it os.rmdir(tmpdir) self.assertEqual(expected_package_data, package_data) self.assertEqual(expected_version_data, version_data) self.assertEqual(set(expected_egg_file_data), set(file_data)) self.assertEqual(expected_egg_file_data['platform'], file_data['platform']) self.assertEqual(expected_egg_file_data['attrs']['python_version'], file_data['attrs']['python_version'])
def test_register_public(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', data_dir('foo-0.1-0.tar.bz2')], False) r1.assertCalled() r2.assertCalled() r3.assertCalled() data = json.loads(r3.req.body) self.assertTrue(data['public'])
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)
def test_bdist_wheel(self): filename = data_dir('test_package34-0.3.1-py2-none-any.whl') with open(filename, 'rb') as fd: package_data, version_data, file_data = pypi.inspect_pypi_package(filename, fd) expected_file_data = {'attrs': {'abi': None, 'build_no': 0, 'packagetype': 'bdist_wheel', 'python_version': 'py2'}, 'basename': 'test_package34-0.3.1-py2-none-any.whl', 'dependencies': expected_whl_dependencies, 'platform': None} self.assertEqual(expected_package_data, package_data) self.assertEqual(expected_version_data, version_data) self.assertEqual(set(expected_file_data), set(file_data)) for key in expected_file_data: print(expected_file_data[key]) print(file_data[key]) self.assertEqual(expected_file_data[key], file_data[key])
def test_sdist_distutils(self): filename = data_dir('test_package34-distutils-0.3.1.tar.gz') with open(filename, 'rb') as fd: package_data, version_data, file_data = pypi.inspect_pypi_package( filename, fd) expected_file_data = { 'attrs': { 'packagetype': 'sdist', 'python_version': 'source' }, 'basename': 'test_package34-distutils-0.3.1.tar.gz', 'dependencies': { 'depends': [{ 'name': 'requests', 'specs': [('>=', '2.0'), ('<=', '3.0')] }, { 'name': 'pyyaml', 'specs': [('==', '2.0')] }, { 'name': 'pytz', 'specs': [] }], 'extras': [], 'has_dep_errors': False } } dexpected_package_data = expected_package_data.copy() dexpected_package_data['name'] = dexpected_package_data[ 'name'].replace('-', '_') self.assertEqual(dexpected_package_data, package_data) self.assertEqual(expected_version_data, version_data) self.assertEqual(set(expected_file_data), set(file_data)) for key in expected_file_data: self.assertEqual(expected_file_data[key], file_data[key])
def test_bdist_egg_dashed_path(self): filename = data_dir('test_package34-0.3.1-py2.7.egg') tmpdir = tempfile.gettempdir() dash_count = tmpdir.count('-') if dash_count == 0: tmpdir = os.path.join(tmpdir, 'has-dash') try: os.mkdir(tmpdir) except (IOError, OSError): raise unittest.SkipTest('Cannot create temporary directory %r' % tmpdir) elif dash_count > 1: raise unittest.SkipTest('Too many dashes in temporary directory path %r' % tmpdir) try: shutil.copy(filename, tmpdir) except (IOError, OSError): raise unittest.SkipTest('Cannot copy package to temporary directory') tmpfilename = os.path.join(tmpdir, 'test_package34-0.3.1-py2.7.egg') with open(tmpfilename, 'rb') as fd: package_data, version_data, file_data = pypi.inspect_pypi_package(tmpfilename, fd) # If we could create this file, we ought to be able to delete it os.remove(tmpfilename) if dash_count == 0: # We created a temporary directory like /tmp/has-dash, delete it os.rmdir(tmpdir) self.assertEqual(expected_package_data, package_data) self.assertEqual(expected_version_data, version_data) self.assertEqual(set(expected_egg_file_data), set(file_data)) self.assertEqual(expected_egg_file_data['platform'], file_data['platform']) self.assertEqual(expected_egg_file_data['attrs']['python_version'], file_data['attrs']['python_version'])
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_is_url(self): location = 'http://docs.continuum.io/_static/img/continuum_analytics_logo.png' self.assertTrue(DataURIConverter(location).is_url()) location = data_dir('bokeh-logo.png') self.assertNotEqual(DataURIConverter(location).is_url(), True)
def test_local_image(self): location = data_dir('bokeh-logo.png') output = DataURIConverter(location)() self.assertEqual(output[0:5], "iVBOR")
def test_package_thumbnail(self): parser_args = namedtuple('parser_args', ['thumbnail'])(data_dir('43c9b994a4d96f779dad87219d645c9f.png')) with open(data_dir('notebook.ipynb')) as fd: package_data, _, _ = inspect_ipynb_package('notebook.ipynb', fd, parser_args=parser_args) self.assertIn('thumbnail', package_data)
def test_package_name(self): with open(data_dir('environment.yml')) as fileobj: assert EnvInspector('environment.yml', fileobj).name == 'stats'
def test_version(self): with open(data_dir('environment.yml')) as fileobj: self.assertIsInstance(EnvInspector('environment.yml', fileobj).version, str)