def test_params_post(self): '''Provides default parameters''' client = http.BaseClient('http://foo.com:1/', a='b') with mock.patch('nsq.http.requests') as MockClass: MockClass.post.return_value = mock.Mock(status_code=200, content='{"foo": "bar"}') client.post('path') MockClass.post.assert_called_with('http://foo.com:1/path', params={'a': 'b'})
def test_prefix_post(self): '''Posts to the appropriately-relativized path''' client = http.BaseClient('http://foo.com:1/prefix/') with mock.patch('nsq.http.requests') as MockClass: MockClass.post.return_value = mock.Mock(status_code=200, content='{"foo": "bar"}') client.post('path') MockClass.post.assert_called_with('http://foo.com:1/prefix/path', params={})
def setUp(self): self.result = mock.Mock() self.result.content = '{"foo": "bar"}' self.result.status_code = 200 self.result.reason = 'OK' self.func = mock.Mock(return_value=self.result) self.client = http.BaseClient('http://foo:1') def function(*args, **kwargs): return self.func(*args, **kwargs) self.function = function
def test_tuple(self): '''Can create a client with a tuple''' http.BaseClient(('foo.com', 4161))
def test_string(self): '''Can make a client with a string''' # This test passes if no exception is thrown http.BaseClient('http://foo.com:4161')