Test coverage report: miniblog.blogs.models

# miniblog.blogs.models: 22 total statements, 92.9% covered

Generated: Thu 2012-03-01 08:22 CST

Source file: /home/alisue/Dropbox/Codes/django-permission/tests/src/miniblog/blogs/models.py

Stats: 13 executed, 1 missed, 8 excluded, 57 ignored

1. `# vim: set fileencoding=utf-8 :`
2. `"""`
3. `Mini blog models`
4. ``
5. `AUTHOR:`
6. `lambdalisue[Ali su ae] (lambdalisue@hashnote.net)`
7. ``
8. `License:`
9. `The MIT License (MIT)`
10. ``
11. `Copyright (c) 2012 Alisue allright reserved.`
12. ``
13. `Permission is hereby granted, free of charge, to any person obtaining a copy`
14. `of this software and associated documentation files (the "Software"), to`
15. `deal in the Software without restriction, including without limitation the`
16. `rights to use, copy, modify, merge, publish, distribute, sublicense, and/or`
17. `sell copies of the Software, and to permit persons to whom the Software is`
18. `furnished to do so, subject to the following conditions:`
19. ``
20. `The above copyright notice and this permission notice shall be included in`
21. `all copies or substantial portions of the Software.`
22. ``
23. `THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR`
24. `IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,`
25. `FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE`
26. `AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER`
27. `LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING`
28. `FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS`
29. `IN THE SOFTWARE.`
30. ``
31. `"""`
32. `from __future__ import with_statement`
33. `from django.db import models`
34. `from django.utils.text import ugettext_lazy as _`
35. ``
36. `class EntryBase(models.Model):`
37. `"""A base abstract model of Entry"""`
38. `title = models.CharField(_('title'), max_length=50, unique=True)`
39. `body = models.TextField(_('body'))`
40. ``
41. `created_at = models.DateTimeField(_('date and time created'),`
42. `auto_now_add=True)`
43. `updated_at = models.DateTimeField(_('date and time updated'),`
44. `auto_now=True)`
45. ``
46. `class Meta:`
47. `abstract = True`
48. ``
49. `def __unicode__(self):`
50. `return self.title`
51. ``
52. `@models.permalink`
53. `def get_absolute_url(self):`
54. `return ('blogs-entry-detail', (), {'slug': self.title})`
55. ``
56. `def clean(self):`
57. `"""custom validation"""`
58. `from django.core.exceptions import ValidationError`
59. `if self.title in ('create', 'update', 'delete'):`
60. `raise ValidationError(`
61. `"""The title cannot be 'create', 'update' or 'delete'""")`
62. ``
63. `class Entry(EntryBase):`
64. `"""mini blog entry model`
65. ``
66. `>>> entry = Entry()`
67. ``
68. `# Attribute test`
69. `>>> assert hasattr(entry, 'title')`
70. `>>> assert hasattr(entry, 'body')`
71. `>>> assert hasattr(entry, 'created_at')`
72. `>>> assert hasattr(entry, 'updated_at')`
73. ``
74. `# Function test`
75. `>>> assert callable(getattr(entry, '__unicode__'))`
76. `>>> assert callable(getattr(entry, 'get_absolute_url'))`
77. `"""`
78. `pass`
79. ``