Test coverage report: ftp_deploy.utils.curl

# 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. ``
5. ``
6. `class curl_connection(object):`
7. ``
8. `"""Helper for curl connections"""`
9. ``
10. `def __init__(self, username, password):`
11. `self.username = username`
12. `self.password = password`
13. ``
14. `def authenticate(self):`
15. `"""Authenticate curl connection"""`
16. `self.curl = pycurl.Curl()`
17. `self.curl.setopt(pycurl.CAINFO, certifi.where())`
18. `self.curl.setopt(self.curl.USERPWD, '%s:%s' % (self.username, self.password))`
19. ``
20. `def perform(self, url):`
21. `"""Perform get request and return respond value"""`
22. `b = StringIO.StringIO()`
23. `self.curl.setopt(self.curl.URL, str(url))`
24. `self.curl.setopt(self.curl.WRITEFUNCTION, b.write)`
25. `self.curl.perform()`
26. `return b.getvalue()`
27. ``
28. `def perform_post(self, url, post):`
29. `"""Perform post request"""`
30. `self.curl.setopt(self.curl.URL, str(url))`
31. `self.curl.setopt(self.curl.POSTFIELDS, post)`
32. `self.curl.perform()`
33. ``
34. `def get_http_code(self):`
35. `"""Return curl HTTP Code"""`
36. `return self.curl.getinfo(pycurl.HTTP_CODE)`
37. ``
38. `def close(self):`
39. `"""Close curl connection"""`
40. `self.curl.close()`