ftp_deploy.utils.curl: 25 total statements, 31.8% covered

Generated: Thu 2013-12-19 21:13 GMT

Source file: /var/www/service.dev/service/ftp_deploy/utils/curl.py

Stats: 7 executed, 15 missed, 3 excluded, 15 ignored

  1. import pycurl
  2. import certifi
  3. import StringIO
  4. class curl_connection(object):
  5. """Helper for curl connections"""
  6. def __init__(self, username, password):
  7. self.username = username
  8. self.password = password
  9. def authenticate(self):
  10. """Authenticate curl connection"""
  11. self.curl = pycurl.Curl()
  12. self.curl.setopt(pycurl.CAINFO, certifi.where())
  13. self.curl.setopt(self.curl.USERPWD, '%s:%s' % (self.username, self.password))
  14. def perform(self, url):
  15. """Perform get request and return respond value"""
  16. b = StringIO.StringIO()
  17. self.curl.setopt(self.curl.URL, str(url))
  18. self.curl.setopt(self.curl.WRITEFUNCTION, b.write)
  19. self.curl.perform()
  20. return b.getvalue()
  21. def perform_post(self, url, post):
  22. """Perform post request"""
  23. self.curl.setopt(self.curl.URL, str(url))
  24. self.curl.setopt(self.curl.POSTFIELDS, post)
  25. self.curl.perform()
  26. def get_http_code(self):
  27. """Return curl HTTP Code"""
  28. return self.curl.getinfo(pycurl.HTTP_CODE)
  29. def close(self):
  30. """Close curl connection"""
  31. self.curl.close()