Debian Codegraph @

tests/properties/tests.py

raw
1 from django.test import TestCase
2
3 from .models import Person
4
5
6 class PropertyTests(TestCase):
7 @classmethod
8 def setUpTestData(cls):
9 cls.a = Person.objects.create(first_name="John", last_name="Lennon")
10
11 def test_getter(self):
12 self.assertEqual(self.a.full_name, "John Lennon")
13
14 def test_setter(self):
15 # The "full_name" property hasn't provided a "set" method.
16 with self.assertRaises(AttributeError):
17 setattr(self.a, "full_name", "Paul McCartney")
18
19 # And cannot be used to initialize the class.
20 with self.assertRaises(AttributeError):
21 Person(full_name="Paul McCartney")
22
23 # But "full_name_2" has, and it can be used to initialize the class.
24 a2 = Person(full_name_2="Paul McCartney")
25 a2.save()
26 self.assertEqual(a2.first_name, "Paul")