Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ported tests to plone.app.testing and pep8 #10

Merged
merged 21 commits into from
Sep 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Changelog
- Fix some testes.
[rafaelbco]

- ported tests to plone.app.testing
[tomgross]

1.5.10 (2014-04-16)
-------------------
Expand Down
184 changes: 150 additions & 34 deletions bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##############################################################################
#
# Copyright (c) 2006 Zope Corporation and Contributors.
# Copyright (c) 2006 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
Expand All @@ -16,47 +16,163 @@
Simply run this script in a directory containing a buildout.cfg.
The script accepts buildout command-line options, so you can
use the -c option to specify an alternate configuration file.

$Id: bootstrap.py 85041 2008-03-31 15:57:30Z andreasjung $
"""

import os, shutil, sys, tempfile, urllib2
import os
import shutil
import sys
import tempfile

from optparse import OptionParser

tmpeggs = tempfile.mkdtemp()

usage = '''\
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]

Bootstraps a buildout-based project.

Simply run this script in a directory containing a buildout.cfg, using the
Python that you want bin/buildout to use.

Note that by using --find-links to point to local resources, you can keep
this script from going over the network.
'''

parser = OptionParser(usage=usage)
parser.add_option("-v", "--version", help="use a specific zc.buildout version")

parser.add_option("-t", "--accept-buildout-test-releases",
dest='accept_buildout_test_releases',
action="store_true", default=False,
help=("Normally, if you do not specify a --version, the "
"bootstrap script and buildout gets the newest "
"*final* versions of zc.buildout and its recipes and "
"extensions for you. If you use this flag, "
"bootstrap and buildout will get the newest releases "
"even if they are alphas or betas."))
parser.add_option("-c", "--config-file",
help=("Specify the path to the buildout configuration "
"file to be used."))
parser.add_option("-f", "--find-links",
help=("Specify a URL to search for buildout releases"))
parser.add_option("--allow-site-packages",
action="store_true", default=False,
help=("Let bootstrap.py use existing site packages"))


options, args = parser.parse_args()

######################################################################
# load/install setuptools

try:
import pkg_resources
if options.allow_site_packages:
import setuptools
import pkg_resources
from urllib.request import urlopen
except ImportError:
ez = {}
exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
).read() in ez
ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)

import pkg_resources

if sys.platform == 'win32':
def quote(c):
if ' ' in c:
return '"%s"' % c # work around spawn lamosity on windows
else:
return c
else:
def quote (c):
return c

cmd = 'from setuptools.command.easy_install import main; main()'
ws = pkg_resources.working_set
assert os.spawnle(
os.P_WAIT, sys.executable, quote (sys.executable),
'-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout',
dict(os.environ,
PYTHONPATH=
ws.find(pkg_resources.Requirement.parse('setuptools')).location
),
) == 0
from urllib2 import urlopen

ez = {}
exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)

if not options.allow_site_packages:
# ez_setup imports site, which adds site packages
# this will remove them from the path to ensure that incompatible versions
# of setuptools are not in the path
import site
# inside a virtualenv, there is no 'getsitepackages'.
# We can't remove these reliably
if hasattr(site, 'getsitepackages'):
for sitepackage_path in site.getsitepackages():
sys.path[:] = [x for x in sys.path if sitepackage_path not in x]

setup_args = dict(to_dir=tmpeggs, download_delay=0)
ez['use_setuptools'](**setup_args)
import setuptools
import pkg_resources

# This does not (always?) update the default working set. We will
# do it.
for path in sys.path:
if path not in pkg_resources.working_set.entries:
pkg_resources.working_set.add_entry(path)

######################################################################
# Install buildout

ws = pkg_resources.working_set

cmd = [sys.executable, '-c',
'from setuptools.command.easy_install import main; main()',
'-mZqNxd', tmpeggs]

find_links = os.environ.get(
'bootstrap-testing-find-links',
options.find_links or
('http://downloads.buildout.org/'
if options.accept_buildout_test_releases else None)
)
if find_links:
cmd.extend(['-f', find_links])

setuptools_path = ws.find(
pkg_resources.Requirement.parse('setuptools')).location

requirement = 'zc.buildout'
version = options.version
if version is None and not options.accept_buildout_test_releases:
# Figure out the most recent final version of zc.buildout.
import setuptools.package_index
_final_parts = '*final-', '*final'

def _final_version(parsed_version):
for part in parsed_version:
if (part[:1] == '*') and (part not in _final_parts):
return False
return True
index = setuptools.package_index.PackageIndex(
search_path=[setuptools_path])
if find_links:
index.add_find_links((find_links,))
req = pkg_resources.Requirement.parse(requirement)
if index.obtain(req) is not None:
best = []
bestv = None
for dist in index[req.project_name]:
distv = dist.parsed_version
if _final_version(distv):
if bestv is None or distv > bestv:
best = [dist]
bestv = distv
elif distv == bestv:
best.append(dist)
if best:
best.sort()
version = best[-1].version
if version:
requirement = '=='.join((requirement, version))
cmd.append(requirement)

import subprocess
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0:
raise Exception(
"Failed to execute command:\n%s" % repr(cmd)[1:-1])

######################################################################
# Import and run buildout

ws.add_entry(tmpeggs)
ws.require('zc.buildout')
ws.require(requirement)
import zc.buildout.buildout
zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])

if not [a for a in args if '=' not in a]:
args.append('bootstrap')

# if -c was provided, we push it back into args for buildout' main function
if options.config_file is not None:
args[0:0] = ['-c', options.config_file]

zc.buildout.buildout.main(args)
shutil.rmtree(tmpeggs)
39 changes: 21 additions & 18 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
[buildout]
extends =
http://dist.plone.org/release/4.2.1/versions.cfg
find-links =
http://dist.plone.org/release/4.2.1
http://dist.plone.org/thirdparty/
extends = https://raw.githubusercontent.com/collective/buildout.plonetest/master/test-5.x.cfg
package-name = plone.app.blob
package-extras = [test]

parts = test
develop = .
versions = versions
extensions = mr.developer
sources = sources
sources-dir = src-dev
auto-checkout =
plone.app.testing
plone.app.imaging
Products.GenericSetup

[remotes]
plone = git://github.com/plone
plone_push = git@github.com:plone
zope = svn://svn.zope.org/repos/main/

[versions]
plone.app.blob =
plone.app.testing =
plone.app.blob =

[test]
recipe = zc.recipe.testrunner
eggs = Zope2
Pillow
Products.CMFPlone [test]
plone.app.blob [test]
# Products.LinguaPlone not included
# because tests with LinguaPlone do not seem to be maintained.
defaults = ['--auto-color', '--auto-progress', '-s', 'plone.app.blob']
[sources]
plone.app.testing = git ${remotes:plone}/plone.app.testing.git pushurl=${remotes:plone_push}/plone.app.testing.git branch=master
plone.app.imaging = git ${remotes:plone}/plone.app.imaging.git pushurl=${remotes:plone_push}/plone.app.imaging.git branch=master
Products.GenericSetup = svn svn://svn.zope.org/repos/main/Products.GenericSetup/trunk
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def read(*rnames):
tests_require = [
'collective.monkeypatcher',
'Products.contentmigration',
'plone.app.imaging [test]']
'plone.app.imaging',
'plone.app.testing',]

setup(name='plone.app.blob',
version=version,
Expand Down Expand Up @@ -51,12 +52,14 @@ def read(*rnames):
classifiers=[
'Environment :: Web Environment',
'Framework :: Plone',
'Framework :: Plone :: 5.0',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Intended Audience :: Other Audience',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
],
entry_points='''
[z3c.autoinclude.plugin]
Expand Down
2 changes: 1 addition & 1 deletion src/plone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = locals()['__path__'] # make pyflakes happy...
__path__ = locals()['__path__'] # make pyflakes happy...
__path__ = extend_path(__path__, __name__)
2 changes: 1 addition & 1 deletion src/plone/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = locals()['__path__'] # make pyflakes happy...
__path__ = locals()['__path__'] # make pyflakes happy...
__path__ = extend_path(__path__, __name__)
35 changes: 20 additions & 15 deletions src/plone/app/blob/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ In any way, the setup should make the new content type available as well as
instantiable:

>>> from Products.CMFCore.utils import getToolByName
>>> portal = layer['portal']
>>> portal_types = getToolByName(portal, 'portal_types')
>>> portal_types.getTypeInfo('Blob')
<DynamicViewTypeInformation at /plone/portal_types/Blob>

>>> from plone.app.testing import TEST_USER_ID
>>> folder = portal.portal_membership.getHomeFolder(TEST_USER_ID)
>>> folder.invokeFactory('Blob', id='blob', title='a Blob')
'blob'
>>> blob = folder.blob
Expand Down Expand Up @@ -77,7 +80,8 @@ and a now non-empty blob file:
'image/gif'
>>> len(blob.getFile().getBlob().open().read())
43
>>> self.assertEqual(str(blob), gif.getvalue())
>>> str(blob) == gif.getvalue()
True

Migration from existing file content, i.e. `ATFile` instances, is also
provided. The payload data as well as all other fields should be properly
Expand Down Expand Up @@ -124,7 +128,8 @@ migrated:
('me',)
>>> folder.foo.getFile().getBlob()
<ZODB.blob.Blob object at ...>
>>> self.assertEqual(str(folder.foo), gif.getvalue())
>>> str(folder.foo) == gif.getvalue()
True
>>> folder.foo.getFile().getBlob().open().read()
'GIF89a...'

Expand All @@ -133,26 +138,26 @@ or wrong data from showing up in some views, i.e. folder listing:

>>> catalog = getToolByName(portal, 'portal_catalog')
>>> brain = catalog(id = 'foo')[0]
>>> self.assertEqual(folder.foo.UID(), brain.UID)
>>> self.assertEqual(folder.foo.getObjSize(), brain.getObjSize)
>>> folder.foo.UID() == brain.UID
True

>>> folder.foo.getObjSize() == brain.getObjSize
True

Finally the correct creation of blob-based content "through the web" is tested
using a testbrowser:

>>> self.setRoles('Editor')
>>> from plone.app.testing import setRoles
>>> setRoles(portal, TEST_USER_ID, ['Editor'])

# BBB Zope 2.12
>>> try:
... from Testing.testbrowser import Browser
... except ImportError:
... from Products.Five.testbrowser import Browser
>>> from plone.testing.z2 import Browser

>>> from Products.PloneTestCase import PloneTestCase as ptc
>>> user, pwd = ptc.default_user, ptc.default_password
>>> browser = Browser()
>>> browser.addHeader('Authorization', 'Basic %s:%s' % (user, pwd))
>>> from plone.app.testing import TEST_USER_NAME, TEST_USER_PASSWORD
>>> browser = Browser(layer['app'])
>>> browser.addHeader('Authorization', 'Basic %s:%s' % (
... TEST_USER_NAME, TEST_USER_PASSWORD))

>>> browser.open('http://nohost/plone/Members/%s' % user)
>>> browser.open(folder.absolute_url())
>>> browser.getLink(url='createObject?type_name=Blob').click()
>>> browser.url
'http://nohost/plone/.../portal_factory/Blob/blob.../edit'
Expand Down
12 changes: 6 additions & 6 deletions src/plone/app/blob/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def initialize(context):
atapi.listTypes(packageName), packageName)
for atype, constructor in zip(content_types, constructors):
utils.ContentInit("%s: %s" % (packageName, atype.portal_type),
content_types = (atype,),
permission = permissions[atype.portal_type],
extra_constructors = (constructor,),
content_types=(atype, ),
permission=permissions[atype.portal_type],
extra_constructors=(constructor, ),
).initialize(context)

replacement_types = (
Expand All @@ -31,7 +31,7 @@ def initialize(context):
)
for name, constructor in replacement_types:
utils.ContentInit("%s: %s" % (packageName, name),
content_types = (content.ATBlob,),
permission = atct.permissions.get(name),
extra_constructors = (constructor,),
content_types=(content.ATBlob, ),
permission=atct.permissions.get(name),
extra_constructors=(constructor, ),
).initialize(context)
Loading