def test_call(self): ret = json.dumps({'ok': 'ok'}) read = MagicMock() read.read = MagicMock(return_value=ret) read.info = MagicMock(return_value=ResponseInfo()) u = 'http://localhost/testing' with patch('urllib.request.urlopen') as mock_method: mock_method.return_value = read request = ApiRequest('mm', ApcUrl(u))() self.assertEqual(request, json.loads(ret))
def test_init(self): url = "/testing" u = ApcUrl(url) self.assertEqual(u.base_url, url)
def test_init(self): u = ApiRequest('request_name', ApcUrl('/test/ing')) self.assertEqual(u.name, "request_name")
def test_url_ex(self): u = ApcUrl('/%%one%%/%%two%%/three').params(two='testing') with self.assertRaises(IncompleteUrl): u.url()
def test_url(self): u = "one/two/three" self.assertEqual(ApcUrl(u).url(), u)
def test_params_ex(self): u = ApcUrl("/testing/%%key%%") with self.assertRaises(UrlBadParam): u.params(bad_key='testing')
def test_params_2(self): u = ApcUrl('/testing/%%key%%/%%api%%/more_testing') full_url = u.params(key="AAA", api="BBB").url() self.assertEqual(full_url, '/testing/AAA/BBB/more_testing')
def test_params_1(self): u = ApcUrl("/testing/%%key%%") self.assertEqual(u.params(key='val').url(), '/testing/val')