def store_location (self, instance): if instance.entity_has_foreign_key: pk = instance.entity_pk_value entity = instance.entity_foreign_key_entity instance = tesql.orm.Session.default.get(entity, pk) return self.store_location(instance) location = self.make_location(instance) fileobj = open(location, 'w') write_object(instance.entity_as_dictionary, fileobj) tesql.orm.Session.default.modify(instance, changed=False) for entity in tesql.orm.Entity.entities.itervalues(): if entity.entity_has_foreign_key: fk = entity while fk.entity_has_foreign_key: fk = fk.entity_foreign_key_entity if fk == type(instance): if tesql.orm.Session.default.has(entity, instance.entity_pk_value): inst = tesql.orm.Session.default.get(entity, instance.entity_pk_value) write_object(inst.entity_as_dictionary, fileobj) tesql.orm.Session.default.modify(inst, changed=False) fileobj.close()
def test_read_object_simple (self): obj = make_object('Key1', 'Simple Text') write_object(obj, self.fileobj) self.fileobj.seek(0) nobj = read_object(self.fileobj) self.assertEqual(obj, nobj)
def test_read_object_key_empty (self): obj = make_object('Section', {}) write_object(obj, self.fileobj) self.fileobj.seek(0) nobj = read_object(self.fileobj) self.assertEqual(obj, nobj)
def test_read_object_empty_empty (self): obj = make_object('', {}) write_object(obj, self.fileobj) self.fileobj.seek(0) nobj = read_object(self.fileobj, as_dictionary=True) self.assertEqual(obj, nobj)
def test_read_empty_empty (self): obj = make_object('', {}) write_object(obj, self.fileobj) self.fileobj.seek(0) nobj = DictionaryObject().read(self.fileobj) self.assertEqual(obj, nobj)
def write(self, dictionary, fileobj, prefix=""): if dictionary.name: fileobj.write("\n[%s]\n" % (prefix + dictionary.name)) fileobj.write("\n") for obj in dictionary.itervalues(): write_object(obj, fileobj, prefix=(prefix + dictionary.name + "."))
def test_read_object_multiline_empty (self): obj = make_object('Key3', 'MultiLine\n\nw/ empty line') write_object(obj, self.fileobj) self.fileobj.seek(0) nobj = read_object(self.fileobj) self.assertEqual(obj, nobj)
def test_read_object_multiline (self): obj = make_object('Key2', 'MultiLine text\nSecondLine') write_object(obj, self.fileobj) self.fileobj.seek(0) nobj = read_object(self.fileobj) self.assertEqual(obj, nobj)
def test_write_object_empty_strings_simple (self): obj = make_object('', {}) obj.append('Key1', 'Value1') obj.append('Key2', 'Value2') obj.append('Key3', 'Value3') write_object(obj, self.fileobj) self.assertEqual(self.fileobj.getvalue(), '\nKey1: Value1\nKey2: Value2\nKey3: Value3\n')
def test_read_object_empty_strings_simple (self): obj = make_object('', {}) obj.append('Key1', 'Value1') obj.append('Key2', 'Value2') obj.append('Key3', 'Value3') write_object(obj, self.fileobj) self.fileobj.seek(0) nobj = read_object(self.fileobj, as_dictionary=True) self.assertEqual(obj, nobj)
def test_read_key_strings_simple (self): obj = make_object('Section', {}) obj.append('Key1', 'Value1') obj.append('Key2', 'Value2') obj.append('Key3', 'Value3') write_object(obj, self.fileobj) self.fileobj.seek(0) nobj = DictionaryObject().read(self.fileobj) self.assertEqual(obj, nobj)
def store_location (self, instance): location = self.make_location(instance) fileobj = open(location, 'w') write_object(instance.entity_as_dictionary, fileobj) fileobj.close()
def test_write_object_empty_empty (self): obj = make_object('', {}) write_object(obj, self.fileobj) self.assertEqual(self.fileobj.getvalue(), '\n')
def test_write_object_key_empty (self): obj = make_object('Section', {}) write_object(obj, self.fileobj) self.assertEqual(self.fileobj.getvalue(), '\n[Section]\n\n')
def test_write_object_multiline (self): obj = make_object('Key2', 'MultiLine text\nSecondLine') write_object(obj, self.fileobj) self.assertEqual(self.fileobj.getvalue(), 'Key2: MultiLine text\n SecondLine\n')
def test_write_object_multiline_empty (self): obj = make_object('Key3', 'MultiLine\n\nw/ empty line') write_object(obj, self.fileobj) self.assertEqual(self.fileobj.getvalue(), 'Key3: MultiLine\n .\n w/ empty line\n')
def test_write_object_simple (self): obj = make_object('Key1', 'Simple Text') write_object(obj, self.fileobj) self.assertEqual(self.fileobj.getvalue(), 'Key1: Simple Text\n')