def test_entity_default_by_object_make_location (self): s = Related() s.bind(self.path) class Person (Entity): pk = Field(Integer, primary_key=True) firstname = Field(String) surname = Field(String) class Account (Entity): homedir = Field(String) person = Field(OneToOne, entity=Person, primary_key=True) p1 = Person(pk=1, firstname='Homer', surname='Simpson') p2 = Person(pk=2, firstname='Bart', surname='Simpson') self.assertEqual(s.make_location(p1), os.path.join(self.path, 'Person', '1.conf')) self.assertEqual(s.make_location(p2), os.path.join(self.path, 'Person', '2.conf')) self.assertTrue(os.path.isdir(os.path.join(self.path, 'Person'))) a1 = Account(homedir='/home/hsimpson', person=p1) a2 = Account(homedir='/home/bsimpson', person=p2) self.assertEqual(s.make_location(a1), os.path.join(self.path, 'Person', '1.conf')) self.assertEqual(s.make_location(a2), os.path.join(self.path, 'Person', '2.conf')) self.assertTrue(os.path.isdir(os.path.join(self.path, 'Person')))
def test_entity_default_by_class_pk_make_location (self): s = Related() s.bind(self.path) class Person (Entity): pk = Field(Integer, primary_key=True) firstname = Field(String) surname = Field(String) self.assertEqual(s.make_location(Person, pk=1), os.path.join(self.path, 'Person', '1.conf')) self.assertTrue(os.path.isdir(os.path.join(self.path, 'Person'))) class Account (Entity): homedir = Field(String) person = Field(OneToOne, entity=Person, primary_key=True) self.assertEqual(s.make_location(Account, pk=1), os.path.join(self.path, 'Person', '1.conf')) self.assertTrue(os.path.isdir(os.path.join(self.path, 'Person')))