Test coverage report: ftp_deploy.utils.repo

# ftp_deploy.utils.repo: 50 total statements, 15.2% covered

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

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

Stats: 7 executed, 39 missed, 4 excluded, 18 ignored

1. `import pycurl`
2. `import json`
3. `from .curl import curl_connection`
4. `from .decorators import check`
5. ``
6. ``
7. `class bitbucket_check(curl_connection):`
8. ``
9. `"""Bitbucket check class contain all checking points for bitbucket repository, return True if fail"""`
10. ``
11. `def __init__(self, username, password, service):`
12. `super(bitbucket_check, self).__init__(username, password)`
13. `self.service = service`
14. ``
15. `@check('Bitbucket')`
16. `def check_authentication(self):`
17. `self.authenticate()`
18. `self.perform('https://bitbucket.org/api/1.0/user/repositories')`
19. `if self.curl.getinfo(pycurl.HTTP_CODE) != 200:`
20. `raise Exception("Login Fail")`
21. ``
22. `@check('Bitbucket')`
23. `def check_repo_exist(self):`
24. `self.authenticate()`
25. `repos = json.loads(self.perform('https://bitbucket.org/api/1.0/user/repositories'))`
26. `for repo in repos:`
27. `if repo['slug'] == self.service.repo_slug_name:`
28. `return False, ''`
29. `raise Exception("Repository %s doesn't exist" % self.service.repo_slug_name)`
30. ``
31. `@check('Bitbucket')`
32. `def check_branch_exist(self):`
33. `self.authenticate()`
34. `url = 'https://bitbucket.org/api/1.0/repositories/%s/%s/branches' % (self.username, self.service.repo_slug_name)`
35. `branches = json.loads(self.perform(url))`
36. `try:`
37. `branches[self.service.repo_branch]`
38. `except KeyError, e:`
39. `raise Exception("Branch %s doesn't exist" % self.service.repo_branch)`
40. ``
41. `@check('Bitbucket')`
42. `def check_hook_exist(self):`
43. `self.authenticate()`
44. `url = 'https://bitbucket.org/api/1.0/repositories/%s/%s/services' % (self.username, self.service.repo_slug_name)`
45. `hooks = json.loads(self.perform(url))`
46. ``
47. `if type(hooks) == list:`
48. `for hook in hooks:`
49. `if len(hook['service']['fields']) > 0:`
50. `value = hook['service']['fields'][0]['value']`
51. `if value.find(str(self.service.hook_url())) != -1 and hook['service']['type'] == 'POST':`
52. `return False, ''`
53. `raise Exception("Hook is not set up")`
54. ``
55. `def check_all(self):`
56. `status = self.check_authentication()`
57. `if status[0] == True:`
58. `return status`
59. ``
60. `status = self.check_repo_exist()`
61. `if status[0] == True:`
62. `return status`
63. ``
64. `status = self.check_branch_exist()`
65. `if status[0] == True:`
66. `return status`
67. ``
68. `return False, ''`