Test coverage report: ftp_deploy.utils.core

# ftp_deploy.utils.core: 76 total statements, 59.4% covered

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

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

Stats: 41 executed, 28 missed, 7 excluded, 41 ignored

1. `import re`
2. `import pycurl`
3. `import certifi`
4. `import StringIO`
5. ``
6. `from .ftp import ftp_check`
7. `from .repo import bitbucket_check`
8. `from ftp_deploy.conf import *`
9. ``
10. ``
11. `class service_check(object):`
12. ``
13. `"""Service check class, what group together all checking points. Return 'fails' and 'message' lists"""`
14. ``
15. `def __init__(self, service):`
16. `self.service = service`
17. `self.message = list()`
18. `self.fails = [False, False, False, False]`
19. ``
20. `def check_log(self):`
21. `"""Check logs"""`
22. `if self.service.pk is not None:`
23. `log_fail = self.service.log_set.all().filter(status=False).filter(skip=False).count()`
24. `if log_fail:`
25. `self.message.append('<b>Log</b>: Deploy Fails(%d)' % log_fail)`
26. `self.fails[0] = True`
27. ``
28. `def check_repo(self):`
29. `"""Check repositories connection, along with POST Hook"""`
30. `if self.service.repo_source == 'bb':`
31. `bb = bitbucket_check(BITBUCKET_SETTINGS['username'], BITBUCKET_SETTINGS['password'], self.service)`
32. `bb_fail, bb_fail_message = bb.check_all()`
33. ``
34. `if bb_fail:`
35. `self.message.append(bb_fail_message)`
36. `self.fails[1] = True`
37. ``
38. `hook_fail, hook_fail_message = bb.check_hook_exist()`
39. `if hook_fail:`
40. `self.message.append(hook_fail_message)`
41. `self.fails[2] = True`
42. ``
43. `def check_ftp(self):`
44. `"""Check FTP connection"""`
45. `ftp = ftp_check(self.service.ftp_host, self.service.ftp_username, self.service.ftp_password, self.service.ftp_path)`
46. `ftp_fail, ftp_fail_message = ftp.check_all()`
47. `ftp.quit()`
48. ``
49. `if ftp_fail:`
50. `self.message.append(ftp_fail_message)`
51. `self.fails[3] = True`
52. ``
53. `def check_all(self):`
54. `self.check_log()`
55. `self.check_repo()`
56. `self.check_ftp()`
57. ``
58. `return self.fails, self.message`
59. ``
60. ``
61. `class commits_parser(object):`
62. ``
63. `"""Commit parser for list of commits. Take commits dictionary captured from payload"""`
64. ``
65. `def __init__(self, commits):`
66. `self.commits = commits`
67. ``
68. `def commits_info(self):`
69. `"""Return commits details list in format [message,author,raw_node]"""`
70. `output = list()`
71. `[output.append([commit['message'], commit['author'], commit['raw_node']]) for commit in reversed(self.commits)]`
72. `return output`
73. ``
74. `def email_list(self):`
75. `"""Return email list from raw_author, limited to unique emails"""`
76. `output = list()`
77. `for commit in self.commits:`
78. `email = re.search('%s(.*)%s' % ('<', '>'), commit['raw_author']).group(1)`
79. `output.append(email) if email not in output else False`
80. `return output`
81. ``
82. `def file_diff(self):`
83. `"""Return files list grouped by added, modified and removed. Respect order of commits"""`
84. `added, removed, modified = list(), list(), list()`
85. ``
86. `for commit in self.commits:`
87. `for file in commit['files']:`
88. `if file['type'] == 'added':`
89. `added.append(file['file']) if file['file'] not in added else False`
90. `removed.remove(file['file']) if file['file'] in removed else False`
91. `elif file['type'] == 'modified':`
92. `modified.append(file['file']) if file['file'] not in modified and file['file'] not in added else False`
93. `elif file['type'] == 'removed':`
94. `removed.append(file['file']) if file['file'] not in removed else False`
95. `added.remove(file['file']) if file['file'] in added else False`
96. `modified.remove(file['file']) if file['file'] in modified else False`
97. ``
98. `return added, modified, removed`
99. ``
100. ``
101. `class absolute_url(object):`
102. ``
103. `"""Build absolute url to root url whthout trailing slash"""`
104. ``
105. `def __init__(self, request):`
106. `self.request = request`
107. ``
108. `def build(self):`
109. `return self.request.build_absolute_uri('/')[:-1]`
110. ``
111. ``
112. `class LockError(Exception):`
113. ``
114. `"""Exception if service is locked"""`
115. ``
116. `def __str__(self):`
117. `return 'Deploy failed because service is Locked!'`