Test coverage report: ftp_deploy.models.service

# ftp_deploy.models.service: 57 total statements, 79.2% covered

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

Source file: /var/www/service.dev/service/ftp_deploy/models/service.py

Stats: 38 executed, 10 missed, 9 excluded, 25 ignored

1. `import random`
2. `import string`
3. `import json`
4. ``
5. `from django.db import models`
6. `from django.core.urlresolvers import reverse`
7. ``
8. `from ftp_deploy.utils.core import service_check`
9. `from .notification import Notification`
10. ``
11. ``
12. `class Service(models.Model):`
13. ``
14. `ftp_host = models.CharField('Host', max_length=255)`
15. `ftp_username = models.CharField('Username', max_length=50)`
16. `ftp_password = models.CharField('Password', max_length=50)`
17. `ftp_path = models.CharField('Path', max_length=255)`
18. ``
19. `repo_source = models.CharField('Source', max_length=10, choices=(('bb', 'BitBucket'),))`
20. `repo_name = models.CharField('Respository Name', max_length=50)`
21. `repo_slug_name = models.SlugField('Respository Slug', max_length=50)`
22. `repo_branch = models.CharField('Branch', max_length=50)`
23. `repo_hook = models.BooleanField(default=False)`
24. ``
25. `secret_key = models.CharField('Secret Key', unique=True, max_length=30, default=lambda: ''.join(random.choice(string.letters + string.digits) for x in range(30)))`
26. ``
27. `status = models.BooleanField()`
28. `status_message = models.TextField()`
29. `notification = models.ForeignKey(Notification, null=True, blank=True, on_delete=models.SET_NULL)`
30. `lock = models.BooleanField(default=False)`
31. `created = models.DateTimeField(auto_now_add=True)`
32. `updated = models.DateTimeField(auto_now=True)`
33. ``
34. `def __init__(self, *args, **kwargs):`
35. `self.check = True`
36. `return super(Service, self).__init__(*args, **kwargs)`
37. ``
38. `def __unicode__(self):`
39. `return self.repo_name`
40. ``
41. `def deploys(self):`
42. `return self.log_set.filter(status=True).count()`
43. ``
44. `def fail_deploys(self):`
45. `return self.log_set.filter(status=False).filter(skip=False).count()`
46. ``
47. `def skipped_deploys(self):`
48. `return self.log_set.filter(status=False).filter(skip=True).count()`
49. ``
50. `def latest_log_date(self):`
51. `return self.log_set.latest('created').created`
52. ``
53. `def latest_log_user(self):`
54. `return self.log_set.latest('created').user`
55. ``
56. `def hook_url(self):`
57. `return reverse('ftpdeploy_deploy', kwargs={'secret_key': self.secret_key})`
58. ``
59. `def save(self, **kwargs):`
60. `"""Check service status on save"""`
61. ``
62. `if self.check:`
63. `message = list()`
64. `fails, message = service_check(self).check_all()`
65. ``
66. `if fails[2]:`
67. `self.repo_hook = False`
68. `else:`
69. `self.repo_hook = True`
70. ``
71. `if True in fails:`
72. `self.status_message = '<br>'.join(message)`
73. `self.status = False`
74. `else:`
75. `self.status = True`
76. `self.status_message = ''`
77. ``
78. `super(Service, self).save()`
79. ``
80. `class Meta:`
81. `app_label = 'ftp_deploy'`
82. `db_table = 'ftp_deploy_service'`