[IMP] test add an url_open helper to http case

bzr revid: al@openerp.com-20140306234535-9zhumihumbzcddb2
This commit is contained in:
Antony Lesuisse 2014-03-07 00:45:35 +01:00
parent c878b34c3e
commit 3aa98edaaf
1 changed files with 9 additions and 2 deletions

View File

@ -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.