def test_save(self):
     # write bruce blog
     try:
         bruce_blog = load_blogs(PROFILE_BRUCE, PROFILE_DIRECTORY)
     except ValueError:
         bruce_blog = Blogs(PROFILE_BRUCE, PROFILE_DIRECTORY, pseudo=PROFILE_BRUCE)
         bruce_blog.add_blog("Hi Buddy", PROFILE_BRUCE)
         bruce_blog.save()
     # write data
     self.document.set_title(u"Mr")
     self.document.set_firstname(u"manu")
     self.document.set_lastname(u"breton")
     self.document.set_photo(QUESTION_MARK())
     self.document.set_email(u"*****@*****.**")
     self.document.add_custom_attributes((u"homepage", u"manu.com"))
     self.document.add_custom_attributes((u'color', u'blue'))
     # set files
     self.document.add(abspath(u"data"))
     self.document.expand_dir(abspath(u"data"))
     self.document.share_files((abspath(u"data"), ["routage", u"emptydir", u"subdir1"], True))
     self.document.expand_dir(abspath(u"data/subdir1"))
     self.document.share_files((abspath(u"data/subdir1/subsubdir"), ["null", "dummy.txt"], True))
     self.document.tag_files((abspath(u"data"), ["date.txt"], u"tagos"))
     self.document.tag_files((abspath(u"data/subdir1/subsubdir"), ["null", "dummy.txt"], u"empty"))
     # set peers
     bruce_doc = FileDocument(PROFILE_BRUCE, PROFILE_DIRECTORY)
     bruce_doc.load()
     self.document.fill_data((u"bruce", bruce_doc))
     self.document.fill_blog((u"bruce", load_blogs(PROFILE_BRUCE, PROFILE_DIRECTORY)))
     self.document.make_friend(u"bruce")
     # write file
     self.document.save()
     # check content
     self._assertContent(self.document)
 def test_unicode(self):
     # blog
     unicode_blog = Blogs(PROFILE_UNICODE, PROFILE_DIRECTORY)
     unicode_blog.add_blog(u"Enchanté", PROFILE_UNICODE)
     unicode_blog.save()
     # doc
     unicode_doc = FileDocument(PROFILE_UNICODE, PROFILE_DIRECTORY)
     # write data
     unicode_doc.set_title(u"Mr")
     unicode_doc.set_firstname(u"Zoé")
     unicode_doc.set_lastname(u"Bréton")
     unicode_doc.set_photo(QUESTION_MARK())
     unicode_doc.set_email(u"*****@*****.**")
     unicode_doc.load_defaults()
     unicode_doc.add_custom_attributes((u"été", u"chôô"))
     unicode_doc.remove_custom_attributes(u'Sport')
     # save
     unicode_doc.save()
     # check content
     blog = load_blogs(PROFILE_UNICODE, PROFILE_DIRECTORY)
     self.assertEquals(blog.blogs[0].text, u"Enchanté")
     doc = FileDocument(PROFILE_UNICODE, PROFILE_DIRECTORY)
     doc.load()
     self.assertEquals(u"Mr", doc.get_title())
     self.assertEquals(u"Zoé", doc.get_firstname())
     self.assertEquals(u"Bréton", doc.get_lastname())
     self.assertEquals(QUESTION_MARK(), doc.get_photo())
     self.assertEquals(u"*****@*****.**", doc.get_email())
     self.assertEquals({'City': u'', 'été': u'chôô', 'Country': u'',
                        'Favourite Book': u'',
                        'Favourite Movie': u'', 'Studies': u''},
                       doc.get_custom_attributes())
 def test_load(self):
     loaded_blog = load_blogs(PROFILE_TEST, directory=PROFILE_DIRECTORY)
     self.assertEquals(loaded_blog.count_blogs(), 2)
     self.assertEquals(loaded_blog.get_blog(0).text, "first blog")
     self.assertEquals(loaded_blog.get_blog(0).count_blogs(), 1)
     self.assertEquals(loaded_blog.get_blog(1).text, "second blog")
     self.assertEquals(loaded_blog.get_blog(1).count_blogs(), 0)
 def load_profile(self, path, profile_frame=None):
     """load .profile.solipsis"""
     # clean
     for view in self.views.values():
         view.reset_files()
     # check path
     if path and path.endswith('.prf'):
         path = path[:-4]
     # rebuild & load doc
     file_doc = FileDocument()
     file_doc.load(path)
     cache_doc = CacheDocument()
     cache_doc.import_document(file_doc)
     self.reset_document(cache_doc)
     self.add_document(file_doc)
     # rebuild view
     if profile_frame:
         gui_view = GuiView(cache_doc, profile_frame)
         html_view = HtmlView(cache_doc, profile_frame.preview_tab.html_preview, True)
         self.reset_view(gui_view)
         self.add_view(html_view)
     else:
         print_view = PrintView(cache_doc)
         self.reset_view(print_view)
     for view in self.views.values():
         view.import_document(cache_doc)
     # load blogs
     self.blogs = load_blogs(path)
     self.update_blogs()
 def test_save(self):
     self.document.set_title(u"Mr")
     self.document.set_firstname(u"manu")
     self.document.set_lastname(u"breton")
     self.document.set_pseudo(u"emb")
     self.document.set_photo(unicode(unittest.__file__, ENCODING))
     self.document.set_email(u"*****@*****.**")
     self.document.set_birthday(u"12/01/2005")
     self.document.set_language(u"fr")
     self.document.set_address(u"12 rue V Hugo")
     self.document.set_postcode(u"34000")
     self.document.set_city(u"Paris")
     self.document.set_country(u"France")
     self.document.set_description(u"anything")
     self.document.set_hobbies([u"blabla", u"bla bla bla", u""])
     self.document.add_custom_attributes((u"homepage", u"manu.com"))
     self.document.add_custom_attributes((u'color', u'blue'))
     # set files
     self.document.add(abspath(u"data"))
     self.document.expand_dir(abspath(u"data"))
     self.document.share_files((abspath(u"data"), ["routage", u"emptydir", u"subdir1"], True))
     self.document.expand_dir(abspath(u"data/subdir1"))
     self.document.share_files((abspath(u"data/subdir1/subsubdir"), ["null", "dummy.txt"], True))
     self.document.tag_files((abspath(u"data"), ["date.txt"], u"tagos"))
     self.document.tag_files((abspath(u"data/subdir1/subsubdir"), ["null", "dummy.txt"], u"empty"))
     # set peers
     bruce_doc = FileDocument()
     bruce_doc.load(BRUCE_PROFILE)
     self.document.make_friend(u"bruce")
     self.document.fill_data((u"bruce", bruce_doc))
     self.document.fill_blog((u"bruce", load_blogs(BRUCE_PROFILE)))
     # write file
     self.document.save(TEST_PROFILE)
     # check content
     self._assertContent(self.document)
 def test_retro_compatibility(self):
     loaded_blog = load_blogs(PROFILE_010, directory=PROFILE_DIRECTORY)
     self.assertEquals(loaded_blog.count_blogs(), 4)
     self.assertEquals(loaded_blog.get_blog(0).text, u"Hi there! Watch my next movie... it's going to be real fun")
     self.assertEquals(loaded_blog.get_blog(0).count_blogs(), 0)
     self.assertEquals(loaded_blog.get_blog(1).text, u"I won't tell you much but this I can say: it's going to be terrific!")
     self.assertEquals(loaded_blog.get_blog(2).text, u'Watch here for its name... coming soon')
     self.assertEquals(loaded_blog.get_blog(3).text, u"A Godess' world.  What do you think?")
 def on_add(self, evt):
     """save profile .prf"""
     dlg = wx.FileDialog(
         self, message="Add profile ...",
         defaultDir=get_prefs("profile_dir"),
         defaultFile="",
         wildcard="Solipsis file (*.prf)|*.prf",
         style=wx.OPEN)
     if dlg.ShowModal() == wx.ID_OK:
         directory, pseudo = os.path.split(dlg.GetPath()[:-4])
         loader = FileDocument(pseudo, directory)
         loader.load()
         blogs = load_blogs(pseudo, directory)
         pseudo = loader.pseudo
         get_facade().fill_data((pseudo, loader))
         get_facade().get_peer(pseudo).set_blog(blogs)
 def on_add(self, evt):
     """save profile .prf"""
     dlg = wx.FileDialog(
         self, message="Add profile ...",
         defaultDir=PROFILE_DIR,
         defaultFile="",
         wildcard="Solipsis file (*.prf)|*.prf",
         style=wx.OPEN)
     if dlg.ShowModal() == wx.ID_OK:
         path = dlg.GetPath()[:-4]
         loader = FileDocument()
         loader.load(path)
         blogs = load_blogs(path)
         pseudo = loader.get_pseudo()
         self.facade.fill_data((pseudo, loader))
         self.facade.get_peer(pseudo).set_blog(blogs)
 def get_peer(self, peer_id):
     """retreive stored value (friendship, path) for peer_id"""
     try:
         infos = self.config.get(SECTION_OTHERS, peer_id).split(",")
         pseudo, state, p_id, creation_date = infos
         if p_id != peer_id:
             print "file corrupted: %s (%s) != %s" \
                   % (p_id, creation_date, peer_id)
             return PeerDescriptor(pseudo)
         file_doc = None
         blogs = None
         file_doc = FileDocument(pseudo, self._dir)
         if file_doc.load():
             try: 
                 blogs = load_blogs(pseudo, file_doc._dir)
             except ValueError, err:
                 print str(err)
         return PeerDescriptor(pseudo,
                               document=file_doc,
                               blog=blogs,
                               state=state,
                               connected=False)
 def test_load(self):
     loaded_blog = load_blogs(FILE_TEST + BLOG_EXT)
     self.assertEquals(loaded_blog.count_blogs(), 1)
     self.assertEquals(loaded_blog.get_blog(0).text, u"This is a test")
     self.assertEquals(loaded_blog.get_blog(0).count_blogs(), 0)