From 3aa98edaaf439196f1145beb95eb6caf760a775e Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 7 Mar 2014 00:45:35 +0100 Subject: [PATCH] [IMP] test add an url_open helper to http case bzr revid: al@openerp.com-20140306234535-9zhumihumbzcddb2 --- openerp/tests/common.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/openerp/tests/common.py b/openerp/tests/common.py index b68bbfe20df..75207841454 100644 --- a/openerp/tests/common.py +++ b/openerp/tests/common.py @@ -13,6 +13,7 @@ import subprocess import threading import time import unittest2 +import urllib2 import xmlrpclib import openerp @@ -150,7 +151,7 @@ class SingleTransactionCase(BaseCase): class HttpCase(TransactionCase): - """ Transactionnal HTTP TestCase with a phantomjs helper. + """ Transactionnal HTTP TestCase with url_open and phantomjs helpers. """ def __init__(self, methodName='runTest'): @@ -171,11 +172,17 @@ class HttpCase(TransactionCase): self.cr._test_lock = threading.RLock() HTTP_SESSION[self.session_id] = self.cr - def tearDown(self): del HTTP_SESSION[self.session_id] super(HttpCase, self).tearDown() + def url_open(self, url, data=None, timeout=10): + opener = urllib2.build_opener() + opener.addheaders.append(('Cookie', 'session_id=%s' % self.session_id)) + if url.startswith('/'): + url = "http://localhost:%s%s" % (PORT, url) + return opener.open(url, data, timeout) + def phantom_poll(self, phantom, timeout): """ Phantomjs Test protocol.