From e6ac29ee43658c58e49a7f8fa1776ab13dd295a6 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Sun, 9 Feb 2014 16:18:22 +0100 Subject: [PATCH] [IMP] move test cases to tests.py remove deprecated wsgi import bzr revid: al@openerp.com-20140209151822-cgk0wibqe1kfd42w --- openerp/__init__.py | 50 +++++++++++++++------------ openerp/http.py | 2 +- openerp/{tests/common.py => tests.py} | 8 +++-- openerp/tests/__init__.py | 15 -------- openerp/tests/test_expression.py | 13 ------- 5 files changed, 35 insertions(+), 53 deletions(-) rename openerp/{tests/common.py => tests.py} (96%) delete mode 100644 openerp/tests/__init__.py delete mode 100644 openerp/tests/test_expression.py diff --git a/openerp/__init__.py b/openerp/__init__.py index a06c85d0c21..995822c9cb0 100644 --- a/openerp/__init__.py +++ b/openerp/__init__.py @@ -19,17 +19,27 @@ # ############################################################################## -""" OpenERP core library.. - -""" - -import sys +""" OpenERP core library.""" +#---------------------------------------------------------- +# Running mode flags (gevent, prefork) +#---------------------------------------------------------- # Is the server running with gevent. +import sys evented = False if sys.modules.get("gevent") is not None: evented = True +# Is the server running in pefork mode (e.g. behind Gunicorn). +# If this is True, the processes have to communicate some events, +# e.g. database update or cache invalidation. Each process has also +# its own copy of the data structure and we don't need to care about +# locks between threads. +multi_process = False + +#---------------------------------------------------------- +# libc UTC hack +#---------------------------------------------------------- # Make sure the OpenERP server runs in UTC. This is especially necessary # under Windows as under Linux it seems the real import of time is # sufficiently deferred so that setting the TZ environment variable @@ -40,9 +50,22 @@ import time # ... *then* import time. del os del time +#---------------------------------------------------------- +# Shortcuts +#---------------------------------------------------------- # The hard-coded super-user id (a.k.a. administrator, or root user). SUPERUSER_ID = 1 +def registry(database_name): + """ + Return the model registry for the given database. If the registry does not + exist yet, it is created on the fly. + """ + return modules.registry.RegistryManager.get(database_name) + +#---------------------------------------------------------- +# Imports +#---------------------------------------------------------- import addons import cli import conf @@ -58,23 +81,6 @@ import service import sql_db import tools import workflow -# backward compatilbility -# TODO: This is for the web addons, can be removed later. -wsgi = service -wsgi.register_wsgi_handler = wsgi.wsgi_server.register_wsgi_handler -# Is the server running in multi-process mode (e.g. behind Gunicorn). -# If this is True, the processes have to communicate some events, -# e.g. database update or cache invalidation. Each process has also -# its own copy of the data structure and we don't need to care about -# locks between threads. -multi_process = False - -def registry(database_name): - """ - Return the model registry for the given database. If the registry does not - exist yet, it is created on the fly. - """ - return modules.registry.RegistryManager.get(database_name) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/http.py b/openerp/http.py index 0b7fba85e64..fe5b113d286 100644 --- a/openerp/http.py +++ b/openerp/http.py @@ -1181,6 +1181,6 @@ root = None def wsgi_postload(): global root root = Root() - openerp.wsgi.register_wsgi_handler(root) + openerp.service.wsgi_server.register_wsgi_handler(root) # vim:et:ts=4:sw=4: diff --git a/openerp/tests/common.py b/openerp/tests.py similarity index 96% rename from openerp/tests/common.py rename to openerp/tests.py index 775066f6c96..9af002f5fcc 100644 --- a/openerp/tests/common.py +++ b/openerp/tests.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- """ -The module :mod:`openerp.tests.common` provides a few helpers and classes to write -tests. +The module :mod:`openerp.tests.common` provides unittest2 test cases and a few +helpers and classes to write tests. + """ import json import os @@ -13,8 +14,11 @@ import unittest2 import uuid import xmlrpclib import logging +import sys import openerp +# backward compatbility +common = sys.modules['openerp.tests.common'] = sys.modules['openerp.tests'] _logger = logging.getLogger(__name__) diff --git a/openerp/tests/__init__.py b/openerp/tests/__init__.py deleted file mode 100644 index 80b3933b80b..00000000000 --- a/openerp/tests/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Tests for the OpenERP library. - -This module groups a few sub-modules containing unittest2 test cases. - -Tests can be explicitely added to the `fast_suite` or `checks` lists or not. -See the :ref:`test-framework` section in the :ref:`features` list. -""" - -import common -from common import * - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/tests/test_expression.py b/openerp/tests/test_expression.py deleted file mode 100644 index 1c5678becf1..00000000000 --- a/openerp/tests/test_expression.py +++ /dev/null @@ -1,13 +0,0 @@ -import unittest2 - -import openerp - - -class test_domain_normalization(unittest2.TestCase): - def test_normalize_domain(self): - expression = openerp.osv.expression - norm_domain = domain = ['&', (1, '=', 1), ('a', '=', 'b')] - assert norm_domain == expression.normalize_domain(domain), "Normalized domains should be left untouched" - domain = [('x', 'in', ['y', 'z']), ('a.v', '=', 'e'), '|', '|', ('a', '=', 'b'), '!', ('c', '>', 'd'), ('e', '!=', 'f'), ('g', '=', 'h')] - norm_domain = ['&', '&', '&'] + domain - assert norm_domain == expression.normalize_domain(domain), "Non-normalized domains should be properly normalized"