Test coverage report: user_media.tests.test_app.models

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