Test coverage report: permission.validation

# permission.validation: 15 total statements, 80.0% covered

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

Source file: /home/alisue/Dropbox/Codes/django-permission/permission/validation.py

Stats: 8 executed, 2 missed, 5 excluded, 55 ignored

1. `#!/usr/bin/env python`
2. `# vim: set fileencoding=utf-8 :`
3. `"""`
4. `Validation method called in ``registry.register`` method`
5. ``
6. ``
7. `AUTHOR:`
8. `lambdalisue[Ali su ae] (lambdalisue@hashnote.net)`
9. ``
10. `License:`
11. `The MIT License (MIT)`
12. ``
13. `Copyright (c) 2012 Alisue allright reserved.`
14. ``
15. `Permission is hereby granted, free of charge, to any person obtaining a copy`
16. `of this software and associated documentation files (the "Software"), to`
17. `deal in the Software without restriction, including without limitation the`
18. `rights to use, copy, modify, merge, publish, distribute, sublicense, and/or`
19. `sell copies of the Software, and to permit persons to whom the Software is`
20. `furnished to do so, subject to the following conditions:`
21. ``
22. `The above copyright notice and this permission notice shall be included in`
23. `all copies or substantial portions of the Software.`
24. ``
25. `THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR`
26. `IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,`
27. `FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE`
28. `AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER`
29. `LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING`
30. `FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS`
31. `IN THE SOFTWARE.`
32. ``
33. `"""`
34. `from __future__ import with_statement`
35. `from django.db import models`
36. `from django.db.models.base import ModelBase`
37. ``
38. `from permission.handlers import PermissionHandler`
39. `from permission.exceptions import ValidationError`
40. ``
41. `__all__ = ('validate',)`
42. ``
43. `def validate(cls, model):`
44. `"""`
45. `Does basic PermissionHandler option validation. Calls custom validation`
46. `classmethod in the end if it is provided in cls. The signature of the`
47. `custom validation classmethod should be: def validate(cls, model).`
48. ``
49. `"""`
50. `# Before we can introspect models, they need to be fully loaded so that`
51. `# inter-relations are set up correctly. We force that here.`
52. `models.get_apps()`
53. ``
54. `# validate model class`
55. `if not isinstance(model, ModelBase):`
56. `# this mean the model is not subclass of models.Model`
57. `raise ValidationError(`
58. `'The model "%s" must be a subclass of ``models.Model``.' % model.__class__.__name__`
59. `)`
60. ``
61. `# validate handler class`
62. `if not issubclass(cls, PermissionHandler):`
63. `raise ValidationError(`
64. `'The handler "%s" must be a subclass of '`
65. `'``fluidpermission.handlers.PermissionHandler``.' % cls.__class__.__name__`
66. `)`
67. ``
68. `# call custom validation classmethod`
69. `if hasattr(cls, 'validate'):`
70. `cls.validate(model)`