Commit 12935efc authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[test] update test to unittest2 api (still using lgc.testlib though)

--HG--
branch : stable
parent bdc3dc94d744
......@@ -68,7 +68,7 @@ class ValueGeneratorTC(TestCase):
def test_string(self):
"""test string generation"""
surname = self.person_valgen.generate_attribute_value({}, 'surname', 12)
self.assertEquals(surname, u'&surname12')
self.assertEqual(surname, u'&surname12')
def test_domain_value(self):
"""test value generation from a given domain value"""
......@@ -100,21 +100,21 @@ class ValueGeneratorTC(TestCase):
def test_phone(self):
"""tests make_tel utility"""
self.assertEquals(make_tel(22030405), '22 03 04 05')
self.assertEqual(make_tel(22030405), '22 03 04 05')
def test_customized_generation(self):
self.assertEquals(self.bug_valgen.generate_attribute_value({}, 'severity', 12),
self.assertEqual(self.bug_valgen.generate_attribute_value({}, 'severity', 12),
u'dangerous')
self.assertEquals(self.bug_valgen.generate_attribute_value({}, 'description', 12),
self.assertEqual(self.bug_valgen.generate_attribute_value({}, 'description', 12),
u'yo')
self.assertEquals(self.person_valgen.generate_attribute_value({}, 'description', 12),
self.assertEqual(self.person_valgen.generate_attribute_value({}, 'description', 12),
u'yo')
class ConstraintInsertionTC(TestCase):
def test_writeme(self):
self.skip('Test automatic insertion / Schema Constraints')
self.skipTest('Test automatic insertion / Schema Constraints')
if __name__ == '__main__':
......
......@@ -15,7 +15,7 @@ class TwistedCWAnonTC(CubicWebServerTC):
def test_response_anon(self):
response = self.web_get()
self.assertEquals(response.status, httplib.OK)
self.assertEqual(response.status, httplib.OK)
def test_base_url(self):
......@@ -29,20 +29,20 @@ class TwistedCWIdentTC(CubicWebServerTC):
def test_response_denied(self):
response = self.web_get()
self.assertEquals(response.status, httplib.FORBIDDEN)
self.assertEqual(response.status, httplib.FORBIDDEN)
def test_login(self):
response = self.web_get()
if response.status != httplib.FORBIDDEN:
self.skip('Already authenticated')
self.skipTest('Already authenticated')
# login
self.web_login(self.admlogin, self.admpassword)
response = self.web_get()
self.assertEquals(response.status, httplib.OK, response.body)
self.assertEqual(response.status, httplib.OK, response.body)
# logout
self.web_logout()
response = self.web_get()
self.assertEquals(response.status, httplib.FORBIDDEN, response.body)
self.assertEqual(response.status, httplib.FORBIDDEN, response.body)
......
......@@ -20,7 +20,7 @@ class QUnitTestCaseTC(QUnitTestCase):
def test_simple_failure(self):
js_tests = list(self._test_qunit(js('test_simple_failure.js')))
self.assertEquals(len(js_tests), 3)
self.assertEqual(len(js_tests), 3)
test_1, test_2, test_3 = js_tests
self.assertRaises(self.failureException, test_1[0], *test_1[1:])
self.assertRaises(self.failureException, test_2[0], *test_2[1:])
......
......@@ -47,9 +47,9 @@ class WebTestTC(TestCase):
tests = [MyWebTest('test_error_view'), MyWebTest('test_correct_view')]
result = self.runner.run(TestSuite(tests))
self.assertEquals(result.testsRun, 2)
self.assertEquals(len(result.errors), 0)
self.assertEquals(len(result.failures), 1)
self.assertEqual(result.testsRun, 2)
self.assertEqual(len(result.errors), 0)
self.assertEqual(len(result.failures), 1)
clean_repo_test_cls(MyWebTest)
......@@ -104,7 +104,7 @@ class HTMLPageInfoTC(TestCase):
def test_source1(self):
"""make sure source is stored correctly"""
self.assertEquals(self.page_info.source, HTML_PAGE2)
self.assertEqual(self.page_info.source, HTML_PAGE2)
def test_source2(self):
"""make sure source is stored correctly - raise exception"""
......@@ -114,47 +114,47 @@ class HTMLPageInfoTC(TestCase):
def test_has_title_no_level(self):
"""tests h? tags information"""
self.assertEquals(self.page_info.has_title('Test'), True)
self.assertEquals(self.page_info.has_title('Test '), False)
self.assertEquals(self.page_info.has_title('Tes'), False)
self.assertEquals(self.page_info.has_title('Hello world !'), True)
self.assertEqual(self.page_info.has_title('Test'), True)
self.assertEqual(self.page_info.has_title('Test '), False)
self.assertEqual(self.page_info.has_title('Tes'), False)
self.assertEqual(self.page_info.has_title('Hello world !'), True)
def test_has_title_level(self):
"""tests h? tags information"""
self.assertEquals(self.page_info.has_title('Test', level = 1), True)
self.assertEquals(self.page_info.has_title('Test', level = 2), False)
self.assertEquals(self.page_info.has_title('Test', level = 3), False)
self.assertEquals(self.page_info.has_title('Test', level = 4), False)
self.assertEqual(self.page_info.has_title('Test', level = 1), True)
self.assertEqual(self.page_info.has_title('Test', level = 2), False)
self.assertEqual(self.page_info.has_title('Test', level = 3), False)
self.assertEqual(self.page_info.has_title('Test', level = 4), False)
self.assertRaises(IndexError, self.page_info.has_title, 'Test', level = 5)
def test_has_title_regexp_no_level(self):
"""tests has_title_regexp() with no particular level specified"""
self.assertEquals(self.page_info.has_title_regexp('h[23] title'), True)
self.assertEqual(self.page_info.has_title_regexp('h[23] title'), True)
def test_has_title_regexp_level(self):
"""tests has_title_regexp() with a particular level specified"""
self.assertEquals(self.page_info.has_title_regexp('h[23] title', 2), True)
self.assertEquals(self.page_info.has_title_regexp('h[23] title', 3), True)
self.assertEquals(self.page_info.has_title_regexp('h[23] title', 4), False)
self.assertEqual(self.page_info.has_title_regexp('h[23] title', 2), True)
self.assertEqual(self.page_info.has_title_regexp('h[23] title', 3), True)
self.assertEqual(self.page_info.has_title_regexp('h[23] title', 4), False)
def test_appears(self):
"""tests PageInfo.appears()"""
self.assertEquals(self.page_info.appears('CW'), True)
self.assertEquals(self.page_info.appears('Logilab'), True)
self.assertEquals(self.page_info.appears('Logilab introduces'), True)
self.assertEquals(self.page_info.appears('H2 title'), False)
self.assertEqual(self.page_info.appears('CW'), True)
self.assertEqual(self.page_info.appears('Logilab'), True)
self.assertEqual(self.page_info.appears('Logilab introduces'), True)
self.assertEqual(self.page_info.appears('H2 title'), False)
def test_has_link(self):
"""tests has_link()"""
self.assertEquals(self.page_info.has_link('Logilab'), True)
self.assertEquals(self.page_info.has_link('logilab'), False)
self.assertEquals(self.page_info.has_link('Logilab', 'http://www.logilab.org'), True)
self.assertEquals(self.page_info.has_link('Logilab', 'http://www.google.com'), False)
self.assertEqual(self.page_info.has_link('Logilab'), True)
self.assertEqual(self.page_info.has_link('logilab'), False)
self.assertEqual(self.page_info.has_link('Logilab', 'http://www.logilab.org'), True)
self.assertEqual(self.page_info.has_link('Logilab', 'http://www.google.com'), False)
def test_has_link_regexp(self):
"""test has_link_regexp()"""
self.assertEquals(self.page_info.has_link_regexp('L[oi]gilab'), True)
self.assertEquals(self.page_info.has_link_regexp('L[ai]gilab'), False)
self.assertEqual(self.page_info.has_link_regexp('L[oi]gilab'), True)
self.assertEqual(self.page_info.has_link_regexp('L[ai]gilab'), False)
if __name__ == '__main__':
......
......@@ -44,16 +44,16 @@ class MetadataTC(BaseEntityTC):
self.login(u'member')
entity = self.request().create_entity('Bookmark', title=u"hello", path=u'project/cubicweb')
self.commit()
self.assertEquals(entity.creator.eid, self.member.eid)
self.assertEquals(entity.dc_creator(), u'member')
self.assertEqual(entity.creator.eid, self.member.eid)
self.assertEqual(entity.dc_creator(), u'member')
def test_type(self):
self.assertEquals(self.member.dc_type(), 'cwuser')
self.assertEqual(self.member.dc_type(), 'cwuser')
def test_entity_meta_attributes(self):
# XXX move to yams
self.assertEquals(self.schema['CWUser'].meta_attributes(), {})
self.assertEquals(dict((str(k), v) for k, v in self.schema['State'].meta_attributes().iteritems()),
self.assertEqual(self.schema['CWUser'].meta_attributes(), {})
self.assertEqual(dict((str(k), v) for k, v in self.schema['State'].meta_attributes().iteritems()),
{'description_format': ('format', 'description')})
......@@ -63,20 +63,20 @@ class EmailAddressTC(BaseEntityTC):
email2 = self.execute('INSERT EmailAddress X: X address "maarten@philips.com"').get_entity(0, 0)
email3 = self.execute('INSERT EmailAddress X: X address "toto@logilab.fr"').get_entity(0, 0)
email1.set_relations(prefered_form=email2)
self.assertEquals(email1.prefered.eid, email2.eid)
self.assertEquals(email2.prefered.eid, email2.eid)
self.assertEquals(email3.prefered.eid, email3.eid)
self.assertEqual(email1.prefered.eid, email2.eid)
self.assertEqual(email2.prefered.eid, email2.eid)
self.assertEqual(email3.prefered.eid, email3.eid)
def test_mangling(self):
email = self.execute('INSERT EmailAddress X: X address "maarten.ter.huurne@philips.com"').get_entity(0, 0)
self.assertEquals(email.display_address(), 'maarten.ter.huurne@philips.com')
self.assertEquals(email.printable_value('address'), 'maarten.ter.huurne@philips.com')
self.assertEqual(email.display_address(), 'maarten.ter.huurne@philips.com')
self.assertEqual(email.printable_value('address'), 'maarten.ter.huurne@philips.com')
self.vreg.config.global_set_option('mangle-emails', True)
self.assertEquals(email.display_address(), 'maarten.ter.huurne at philips dot com')
self.assertEquals(email.printable_value('address'), 'maarten.ter.huurne at philips dot com')
self.assertEqual(email.display_address(), 'maarten.ter.huurne at philips dot com')
self.assertEqual(email.printable_value('address'), 'maarten.ter.huurne at philips dot com')
email = self.execute('INSERT EmailAddress X: X address "syt"').get_entity(0, 0)
self.assertEquals(email.display_address(), 'syt')
self.assertEquals(email.printable_value('address'), 'syt')
self.assertEqual(email.display_address(), 'syt')
self.assertEqual(email.printable_value('address'), 'syt')
class CWUserTC(BaseEntityTC):
......@@ -94,19 +94,19 @@ class CWUserTC(BaseEntityTC):
def test_dc_title_and_name(self):
e = self.execute('CWUser U WHERE U login "member"').get_entity(0, 0)
self.assertEquals(e.dc_title(), 'member')
self.assertEquals(e.name(), 'member')
self.assertEqual(e.dc_title(), 'member')
self.assertEqual(e.name(), 'member')
e.set_attributes(firstname=u'bouah')
self.assertEquals(e.dc_title(), 'member')
self.assertEquals(e.name(), u'bouah')
self.assertEqual(e.dc_title(), 'member')
self.assertEqual(e.name(), u'bouah')
e.set_attributes(surname=u'lôt')
self.assertEquals(e.dc_title(), 'member')
self.assertEquals(e.name(), u'bouah lôt')
self.assertEqual(e.dc_title(), 'member')
self.assertEqual(e.name(), u'bouah lôt')
def test_allowed_massmail_keys(self):
e = self.execute('CWUser U WHERE U login "member"').get_entity(0, 0)
# Bytes/Password attributes should be omited
self.assertEquals(e.cw_adapt_to('IEmailable').allowed_massmail_keys(),
self.assertEqual(e.cw_adapt_to('IEmailable').allowed_massmail_keys(),
set(('surname', 'firstname', 'login', 'last_login_time',
'creation_date', 'modification_date', 'cwuri', 'eid'))
)
......@@ -144,7 +144,7 @@ class SpecializedEntityClassesTC(CubicWebTC):
# no specific class for Subdivisions, the default one should be selected
eclass = self.select_eclass('SubDivision')
self.failUnless(eclass.__autogenerated__)
#self.assertEquals(eclass.__bases__, (AnyEntity,))
#self.assertEqual(eclass.__bases__, (AnyEntity,))
# build class from most generic to most specific and make
# sure the most specific is always selected
self.vreg._loadedmods[__name__] = {}
......@@ -156,12 +156,12 @@ class SpecializedEntityClassesTC(CubicWebTC):
self.failUnless(eclass.__autogenerated__)
self.failIf(eclass is Foo)
if etype == 'SubDivision':
self.assertEquals(eclass.__bases__, (Foo,))
self.assertEqual(eclass.__bases__, (Foo,))
else:
self.assertEquals(eclass.__bases__[0].__bases__, (Foo,))
self.assertEqual(eclass.__bases__[0].__bases__, (Foo,))
# check Division eclass is still selected for plain Division entities
eclass = self.select_eclass('Division')
self.assertEquals(eclass.__regid__, 'Division')
self.assertEqual(eclass.__regid__, 'Division')
if __name__ == '__main__':
unittest_main()
This diff is collapsed.
......@@ -29,9 +29,9 @@ class RestTC(CubicWebTC):
def test_eid_role(self):
context = self.context()
self.assertEquals(rest_publish(context, ':eid:`%s`' % context.eid),
self.assertEqual(rest_publish(context, ':eid:`%s`' % context.eid),
'<p><a class="reference" href="http://testing.fr/cubicweb/cwuser/admin">#%s</a></p>\n' % context.eid)
self.assertEquals(rest_publish(context, ':eid:`%s:some text`' % context.eid),
self.assertEqual(rest_publish(context, ':eid:`%s:some text`' % context.eid),
'<p><a class="reference" href="http://testing.fr/cubicweb/cwuser/admin">some text</a></p>\n')
def test_bad_rest_no_crash(self):
......
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
#
# CubicWeb is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
"""cubicweb on google appengine
"""
__docformat__ = "restructuredtext en"
try:
# WARNING: do not import the google's db module here since it will take
# precedence over our own db submodule
from google.appengine.api.datastore import Key, Get, Query
from google.appengine.api.datastore_errors import BadKeyError
except ImportError:
# not in google app environment
pass
else:
import os
_SS = os.environ.get('SERVER_SOFTWARE')
if _SS is None:
MODE = 'test'
elif _SS.startswith('Dev'):
MODE = 'dev'
else:
MODE = 'prod'
from cubicweb.server import SOURCE_TYPES
from cubicweb.goa.gaesource import GAESource
SOURCE_TYPES['gae'] = GAESource
def do_monkey_patch():
# monkey patch yams Bytes validator since it should take a bytes string with gae
# and not a StringIO
def check_bytes(eschema, value):
"""check value is a bytes string"""
return isinstance(value, str)
from yams import constraints
constraints.BASE_CHECKERS['Bytes'] = check_bytes
def rql_for_eid(eid):
return 'Any X WHERE X eid "%s"' % eid
from cubicweb import uilib
uilib.rql_for_eid = rql_for_eid
def typed_eid(eid):
try:
return str(Key(eid))
except BadKeyError:
raise ValueError(eid)
import cubicweb
cubicweb.typed_eid = typed_eid
# XXX monkey patch cubicweb.schema.CubicWebSchema to have string eid with
# optional cardinality (since eid is set after the validation)
import re
from yams import buildobjs as ybo
def add_entity_type(self, edef):
edef.name = edef.name.encode()
assert re.match(r'[A-Z][A-Za-z0-9]*[a-z]+[0-9]*$', edef.name), repr(edef.name)
eschema = super(CubicWebSchema, self).add_entity_type(edef)
if not eschema.final:
# automatically add the eid relation to non final entity types
rdef = ybo.RelationDefinition(eschema.type, 'eid', 'Bytes',
cardinality='?1', uid=True)
self.add_relation_def(rdef)
rdef = ybo.RelationDefinition(eschema.type, 'identity', eschema.type)
self.add_relation_def(rdef)
self._eid_index[eschema.eid] = eschema
return eschema
from cubicweb.schema import CubicWebSchema
CubicWebSchema.add_entity_type = add_entity_type
# don't reset vreg on repository set_schema
from cubicweb.server import repository
orig_set_schema = repository.Repository.set_schema
def set_schema(self, schema, resetvreg=True):
orig_set_schema(self, schema, False)
repository.Repository.set_schema = set_schema
# deactivate function ensuring relation cardinality consistency
repository.del_existing_rel_if_needed = lambda *args: None
def get_cubes(self):
"""return the list of top level cubes used by this instance"""
config = self.config
cubes = config['included-cubes'] + config['included-yams-cubes']
return config.expand_cubes(cubes)
repository.Repository.get_cubes = get_cubes
from rql import RQLHelper
RQLHelper.simplify = lambda x, r: None
# activate entity caching on the server side
def set_entity_cache(self, entity):
self.transaction_data.setdefault('_eid_cache', {})[entity.eid] = entity
def entity_cache(self, eid):
return self.transaction_data['_eid_cache'][eid]
def drop_entity_cache(self, eid=None):
if eid is None:
self.transaction_data['_eid_cache'] = {}
elif '_eid_cache' in self.transaction_data:
self.transaction_data['_eid_cache'].pop(eid, None)
def datastore_get(self, key):
if isinstance(key, basestring):
key = Key(key)
try:
gentity = self.transaction_data['_key_cache'][key]
#self.critical('cached %s', gentity)
except KeyError:
gentity = Get(key)
#self.critical('Get %s', gentity)
self.transaction_data.setdefault('_key_cache', {})[key] = gentity
return gentity
def clear_datastore_cache(self, key=None):
if key is None:
self.transaction_data['_key_cache'] = {}
else:
if isinstance(key, basestring):
key = Key(key)
self.transaction_data['_key_cache'].pop(key, None)
from cubicweb.server.session import Session
Session.set_entity_cache = set_entity_cache
Session.entity_cache = entity_cache
Session.drop_entity_cache = drop_entity_cache
Session.datastore_get = datastore_get
Session.clear_datastore_cache = clear_datastore_cache
from docutils.frontend import OptionParser
# avoid a call to expanduser which is not available under gae
def get_standard_config_files(self):
return self.standard_config_files
OptionParser.get_standard_config_files = get_standard_config_files
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
#
# CubicWeb is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
#
# CubicWeb is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
"""overrides some base views for cubicweb on google appengine
"""
__docformat__ = "restructuredtext en"
from logilab.mtconverter import xml_escape
from cubicweb import typed_eid
from cubicweb.selectors import one_line_rset, match_search_state, accept
from cubicweb.schema import display_name
from cubicweb.view import StartupView, EntityView
from cubicweb.web import Redirect
from cubicweb.web.views import vid_from_rset
from google.appengine.api import mail
class SearchForAssociationView(EntityView):
"""view called by the edition view when the user asks
to search for something to link to the edited eid
"""
id = 'search-associate'
__select__ = one_line_rset() & match_search_state('linksearch') & accept
def cell_call(self, row, col):
entity = self.rset.get_entity(0, 0)
role, eid, rtype, etype = self.req.search_state[1]
assert entity.eid == typed_eid(eid)
rset = entity.unrelated(rtype, etype, role, ordermethod='fetch_order')
vid = vid_from_rset(self.req, rset, self.schema)
self.w(u'<div id="search-associate-content">')
self.pagination(self.req, rset, w=self.w)
self.wview(vid, rset)
self.w(u'</div>')
class SchemaImageView(StartupView):
id = 'schemagraph'
binary = True
content_type = 'image/png'
def call(self):
"""display global schema information"""
skipmeta = int(self.req.form.get('skipmeta', 1))
if skipmeta:
url = self.build_url('data/schema.png')
else:
url = self.build_url('data/metaschema.png')
raise Redirect(url)
from cubicweb.web.views.baseviews import MetaDataView
class GAEMetaDataView(MetaDataView):
show_eid = False
from cubicweb.web.views.startup import ManageView
def entity_types_no_count(self, eschemas):
"""return a list of formatted links to get a list of entities of
a each entity's types
"""
req = self.req
for eschema in eschemas:
if eschema.final or not (eschema.has_perm(req, 'read') or
eschema.has_local_role('read')):
continue
etype = eschema.type
label = display_name(req, etype, 'plural')
view = self.vreg.select('views', 'list', req, req.etype_rset(etype))
url = view.url()
etypelink = u'&#160;<a href="%s">%s</a>' % (xml_escape(url), label)
yield (label, etypelink, self.add_entity_link(eschema, req))
ManageView.entity_types = entity_types_no_count
from cubicweb.web.views.basecontrollers import SendMailController
def sendmail(self, recipient, subject, body):
sender = '%s <%s>' % (
self.req.user.dc_title() or self.config['sender-name'],
self.req.user.cw_adapt_to('IEmailable').get_email() or self.config['sender-addr'])
mail.send_mail(sender=sender, to=recipient,
subject=subject, body=body)
SendMailController.sendmail = sendmail
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
#
# CubicWeb is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.
"""special management views to manage repository content (initialization and
restoration).