/tests/modeltests/properties/tests.py

https://code.google.com/p/mango-py/ · Python · 20 lines · 13 code · 5 blank · 2 comment · 0 complexity · 3b3b24db4361d2bb10766c0c8996565b MD5 · raw file

  1. from django.test import TestCase
  2. from models import Person
  3. class PropertyTests(TestCase):
  4. def setUp(self):
  5. self.a = Person(first_name='John', last_name='Lennon')
  6. self.a.save()
  7. def test_getter(self):
  8. self.assertEqual(self.a.full_name, 'John Lennon')
  9. def test_setter(self):
  10. # The "full_name" property hasn't provided a "set" method.
  11. self.assertRaises(AttributeError, setattr, self.a, 'full_name', 'Paul McCartney')
  12. # But "full_name_2" has, and it can be used to initialise the class.
  13. a2 = Person(full_name_2 = 'Paul McCartney')
  14. a2.save()
  15. self.assertEqual(a2.first_name, 'Paul')