Merge "Unmock requests when testing complete."

This commit is contained in:
Jenkins
2013-06-28 01:56:47 +00:00
committed by Gerrit Code Review
2 changed files with 34 additions and 16 deletions

View File

@@ -1,5 +1,6 @@
import time import time
import mock
import mox import mox
import requests import requests
import testtools import testtools
@@ -72,9 +73,12 @@ class TestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(TestCase, self).setUp() super(TestCase, self).setUp()
self.mox = mox.Mox() self.mox = mox.Mox()
self._original_time = time.time self.request_patcher = mock.patch.object(requests, 'request',
time.time = lambda: 1234 self.mox.CreateMockAnything())
requests.request = self.mox.CreateMockAnything() self.time_patcher = mock.patch.object(time, 'time',
lambda: 1234)
self.request_patcher.start()
self.time_patcher.start()
self.client = client.Client(username=self.TEST_USER, self.client = client.Client(username=self.TEST_USER,
token=self.TEST_TOKEN, token=self.TEST_TOKEN,
tenant_name=self.TEST_TENANT_NAME, tenant_name=self.TEST_TENANT_NAME,
@@ -82,7 +86,8 @@ class TestCase(testtools.TestCase):
endpoint=self.TEST_URL) endpoint=self.TEST_URL)
def tearDown(self): def tearDown(self):
time.time = self._original_time self.request_patcher.stop()
self.time_patcher.stop()
self.mox.UnsetStubs() self.mox.UnsetStubs()
self.mox.VerifyAll() self.mox.VerifyAll()
super(TestCase, self).tearDown() super(TestCase, self).tearDown()
@@ -101,12 +106,16 @@ class UnauthenticatedTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(UnauthenticatedTestCase, self).setUp() super(UnauthenticatedTestCase, self).setUp()
self.mox = mox.Mox() self.mox = mox.Mox()
self._original_time = time.time self.request_patcher = mock.patch.object(requests, 'request',
time.time = lambda: 1234 self.mox.CreateMockAnything())
requests.request = self.mox.CreateMockAnything() self.time_patcher = mock.patch.object(time, 'time',
lambda: 1234)
self.request_patcher.start()
self.time_patcher.start()
def tearDown(self): def tearDown(self):
time.time = self._original_time self.request_patcher.stop()
self.time_patcher.stop()
self.mox.UnsetStubs() self.mox.UnsetStubs()
self.mox.VerifyAll() self.mox.VerifyAll()
super(UnauthenticatedTestCase, self).tearDown() super(UnauthenticatedTestCase, self).tearDown()

View File

@@ -4,6 +4,7 @@ import time
import urlparse import urlparse
import uuid import uuid
import mock
import mox import mox
import requests import requests
import testtools import testtools
@@ -127,9 +128,12 @@ class TestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(TestCase, self).setUp() super(TestCase, self).setUp()
self.mox = mox.Mox() self.mox = mox.Mox()
self._original_time = time.time self.request_patcher = mock.patch.object(requests, 'request',
time.time = lambda: 1234 self.mox.CreateMockAnything())
requests.request = self.mox.CreateMockAnything() self.time_patcher = mock.patch.object(time, 'time',
lambda: 1234)
self.request_patcher.start()
self.time_patcher.start()
self.client = TestClient(username=self.TEST_USER, self.client = TestClient(username=self.TEST_USER,
token=self.TEST_TOKEN, token=self.TEST_TOKEN,
tenant_name=self.TEST_TENANT_NAME, tenant_name=self.TEST_TENANT_NAME,
@@ -137,7 +141,8 @@ class TestCase(testtools.TestCase):
endpoint=self.TEST_URL) endpoint=self.TEST_URL)
def tearDown(self): def tearDown(self):
time.time = self._original_time self.request_patcher.stop()
self.time_patcher.stop()
self.mox.UnsetStubs() self.mox.UnsetStubs()
self.mox.VerifyAll() self.mox.VerifyAll()
super(TestCase, self).tearDown() super(TestCase, self).tearDown()
@@ -156,12 +161,16 @@ class UnauthenticatedTestCase(testtools.TestCase):
def setUp(self): def setUp(self):
super(UnauthenticatedTestCase, self).setUp() super(UnauthenticatedTestCase, self).setUp()
self.mox = mox.Mox() self.mox = mox.Mox()
self._original_time = time.time
time.time = lambda: 1234 self.request_patcher = mock.patch.object(requests, 'request',
requests.request = self.mox.CreateMockAnything() self.mox.CreateMockAnything())
self.time_patcher = mock.patch.object(time, 'time',
lambda: 1234)
self.request_patcher.start()
def tearDown(self): def tearDown(self):
time.time = self._original_time self.request_patcher.stop()
self.time_patcher.stop()
self.mox.UnsetStubs() self.mox.UnsetStubs()
self.mox.VerifyAll() self.mox.VerifyAll()
super(UnauthenticatedTestCase, self).tearDown() super(UnauthenticatedTestCase, self).tearDown()