def setUp(self):
   super(FunctionalTests, self).setUp()
   clever.api_base = os.environ.get('CLEVER_API_BASE', 'https://api.clever.com')
   if auth.get("token", None):
     clever.set_token(auth["token"])
   elif auth.get("api_key", None):
     clever.set_api_key(auth["api_key"])
 def test_invalid_credentials(self):
   key = clever.get_api_key()
   try:
     clever.set_api_key('invalid')
     clever.District.all()
   except clever.AuthenticationError, e:
     self.assertEqual(401, e.http_status)
     self.assertTrue(isinstance(e.http_body, str))
     self.assertTrue(isinstance(e.json_body, dict))
 def setUp(self):
   super(CleverTestCase, self).setUp()
   clever.api_base = os.environ.get('CLEVER_API_BASE', 'https://api.clever.com')
   clever.set_api_key('DEMO_KEY')


class AuthenticationErrorTest(CleverTestCase):

  def test_invalid_credentials(self):
    key = clever.get_api_key()
    try:
      clever.set_api_key('invalid')
      clever.District.all()
    except clever.AuthenticationError, e:
      self.assertEqual(401, e.http_status)
      self.assertTrue(isinstance(e.http_body, str))
      self.assertTrue(isinstance(e.json_body, dict))
    finally:
      clever.set_api_key(key)


class InvalidRequestErrorTest(CleverTestCase):

  def test_nonexistent_object(self):
    try:
      clever.District.retrieve('invalid')
    except clever.APIError, e:
      self.assertEqual(404, e.http_status)
      self.assertFalse(isinstance(e.json_body, dict))  # 404 does not have a body
      self.assertTrue(isinstance(e.http_body, str))

#generates httmock responses for TooManyRequestsErrorTest
def too_many_requests_content(url, request):
  headers =  {
 def setUp(self):
   super(CleverTestCase, self).setUp()
   clever.set_api_key('DEMO_KEY')