Skip to content

Commit

Permalink
Use FakeJsonClient for testing SimpleClient
Browse files Browse the repository at this point in the history
This allows us to avoid using minimock and
better control the request behaviour.
  • Loading branch information
thp committed Dec 29, 2009
1 parent fc70a23 commit 31f57e8
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions mygpoclient/simple_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from mygpoclient import http
from mygpoclient import simple
from mygpoclient import testing

import unittest
import minimock

class Test_SimpleClient(unittest.TestCase):
USERNAME = 'a'
Expand All @@ -35,22 +34,19 @@ class Test_SimpleClient(unittest.TestCase):
"""

def setUp(self):
self.client = simple.SimpleClient(self.USERNAME, self.PASSWORD)

def tearDown(self):
minimock.restore()

def mock_setHttpResponse(self, value):
http.HttpClient._request = minimock.Mock('http.HttpClient._request')
http.HttpClient._request.mock_returns = value
self.fake_client = testing.FakeJsonClient()
self.client = simple.SimpleClient(self.USERNAME, self.PASSWORD,
client_class=self.fake_client)

def test_putSubscriptions(self):
self.mock_setHttpResponse('')
self.fake_client.response_value = ''
result = self.client.put_subscriptions(self.DEVICE_NAME, self.SUBSCRIPTIONS)
self.assertEquals(result, True)
self.assertEquals(len(self.fake_client.requests), 1)

def test_getSubscriptions(self):
self.mock_setHttpResponse(self.SUBSCRIPTIONS_JSON)
self.fake_client.response_value = self.SUBSCRIPTIONS_JSON
subscriptions = self.client.get_subscriptions(self.DEVICE_NAME)
self.assertEquals(subscriptions, self.SUBSCRIPTIONS)
self.assertEquals(len(self.fake_client.requests), 1)

0 comments on commit 31f57e8

Please sign in to comment.