user_media.tests.test_app.models: 12 total statements, 100.0% covered

Generated: Sat 2012-10-13 07:27 SGT

Source file: /Users/martin/Repos/django-user-media/user_media/tests/test_app/models.py

Stats: 6 executed, 0 missed, 6 excluded, 33 ignored

  1. """
  2. Dummy models needed for the tests of the `django-user-media` application.
  3. """
  4. from django.contrib.contenttypes import generic
  5. from django.db import models
  6. class DummyModel(models.Model):
  7. """
  8. Dummy model for tests of the `django-user-media` application.
  9. Since `UserMediaImage` objects can belong to a content object, we need this
  10. DummyModel in order to have objects to which a `UserMediaImage` can belong
  11. to.
  12. Note the `images` generic relation. It is useful to implement this on your
  13. content object in order to have easier access to the images that have been
  14. tied to this content object.
  15. """
  16. user = models.ForeignKey('auth.User')
  17. images = generic.GenericRelation(
  18. 'user_media.UserMediaImage',
  19. )
  20. def get_absolute_url(self):
  21. return '/?foo=bar'
  22. @property
  23. def image(self):
  24. """
  25. Provides easier access to the image of this content object.
  26. The generic relation `images` makes it easy to access all images of
  27. this content object but usually your object is only supposed to have
  28. one single image. Therefore this property makes it easier to access
  29. that image.
  30. """
  31. try:
  32. return self.images.all()[0]
  33. except IndexError: # pragma: nocover
  34. return None