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