test_apcurl.py 991 B

12345678910111213141516171819202122232425262728293031
  1. import unittest
  2. from .. api_client import ApcUrl, UrlBadParam, IncompleteUrl
  3. class TestApcUrl(unittest.TestCase):
  4. def test_init(self):
  5. url = "/testing"
  6. u = ApcUrl(url)
  7. self.assertEquals( u.base_url, url)
  8. def test_params_1(self):
  9. u = ApcUrl("/testing/%%key%%")
  10. self.assertEquals(u.params(key='val').url(), '/testing/val')
  11. def test_params_2(self):
  12. u = ApcUrl('/testing/%%key%%/%%api%%/more_testing')
  13. full_url = u.params(key="AAA",api="BBB").url()
  14. self.assertEquals(full_url, '/testing/AAA/BBB/more_testing')
  15. def test_params_ex(self):
  16. u = ApcUrl("/testing/%%key%%")
  17. with self.assertRaises(UrlBadParam):
  18. u.params(bad_key='testing')
  19. def test_url(self):
  20. u = "one/two/three"
  21. self.assertEquals( ApcUrl(u).url(), u )
  22. def test_url_ex(self):
  23. u = ApcUrl('/%%one%%/%%two%%/three').params(two='testing')
  24. with self.assertRaises(IncompleteUrl): u.url()