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 run(): """launch gui of profile""" #set up GUI import gettext gettext.install("app") # replace with the appropriate catalog name app = wx.PySimpleApp(0) wx.InitAllImageHandlers() profile_frame = ProfileFrame(None, -1, "") #set up facade facade = get_facade() file_doc = FileDocument() file_doc.load(os.path.join(PROFILE_DIR, PROFILE_FILE)) cache_doc = CacheDocument() cache_doc.import_document(file_doc) gui_view = GuiView(cache_doc, profile_frame) html_view = HtmlView(cache_doc, profile_frame.preview_tab.html_preview, True) facade.add_document(file_doc) facade.add_document(cache_doc) facade.add_view(gui_view) facade.add_view(html_view) facade.refresh_html_preview() #launch gui app.SetTopWindow(profile_frame) profile_frame.Show() app.MainLoop()
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 Enable(self): """ All real actions involved in initializing the service should be defined here, not in the constructor. This includes e.g. opening sockets, collecting data from directories, etc. """ # init windows main_window = self.service_api.GetMainWindow() self.profile_frame = ProfileFrame(main_window, -1, "") # create views & doc file_doc = FileDocument() file_doc.load(os.path.join(PROFILE_DIR, PROFILE_FILE)) cache_doc = CacheDocument() cache_doc.import_document(file_doc) gui_view = GuiView(cache_doc, self.profile_frame) html_view = HtmlView(cache_doc, self.profile_frame.preview_tab.html_preview, True) self.facade.add_document(file_doc) self.facade.add_document(cache_doc) self.facade.add_view(gui_view) self.facade.add_view(html_view) self.facade.refresh_html_preview() # Set up main GUI hooks menu = wx.Menu() for action, method in self.MAIN_ACTION.iteritems(): item_id = wx.NewId() menu.Append(item_id, _(action)) def _clicked(event): """call profile from main menu""" method() wx.EVT_MENU(main_window, item_id, _clicked) self.service_api.SetMenu(self.GetTitle(), menu) # launch network self.network.start_listening()
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_and_load(self): self.document.load(TEST_PROFILE) self.document.share_file((REPO+"/data/subdir1/TOtO.txt", True)) self.document.save("data/profiles/tata") new_doc = FileDocument() new_doc.load("data/profiles/tata") container = new_doc.get_container(REPO+u"/data/subdir1") self.assert_(dict.has_key(container, "TOtO.txt"))
def _on_complete_profile(self): """callback when finished downloading profile""" self.file.seek(0) file_doc = FileDocument() file_doc.read(self.file) self.file.close() self.file = None self.factory.callback(file_doc)
def test_filling_data(self): """fill data""" for document in self.documents: self.assertRaises(TypeError, document.fill_data, (u"pseudo", u"tag description")) self.assertEquals(document.has_peer(u"emb"), False) file_doc = FileDocument() file_doc.load(TEST_PROFILE) document.fill_data((u"emb", file_doc))
def setUp(self): """override one in unittest.TestCase""" # bruce doc = FileDocument() self.assert_(doc.load(TEST_BRUCE)) self.bruce_doc = CacheDocument() self.bruce_doc.import_document(doc) # demi self.demi_doc = FileDocument() self.assert_(self.demi_doc.load(TEST_DEMI))
def setUp(self): """override one in unittest.TestCase""" # bruce doc = FileDocument(PROFILE_BRUCE, PROFILE_DIRECTORY) self.assert_(doc.load()) self.bruce_doc = CacheDocument(PROFILE_BRUCE, PROFILE_DIRECTORY) self.bruce_doc.import_document(doc) # demi self.demi_doc = FileDocument(PROFILE_DEMI, PROFILE_DIRECTORY) self.assert_(self.demi_doc.load())
def EnableBasic(self): """enable non graphic part""" # TODO: expose interface of facade to netClient # create views & doc file_doc = FileDocument() file_doc.load(os.path.join(PROFILE_DIR, PROFILE_FILE)) cache_doc = CacheDocument() cache_doc.import_document(file_doc) print_view = PrintView(cache_doc) self.facade.add_document(cache_doc) self.facade.add_view(print_view) # launch network self.network.start_listening()
def test_save_and_load(self): self.document.load() self.document.share_file((REPO+"/data/subdir1/TOtO.txt", True)) sav_doc = FileDocument(PROFILE_TATA, PROFILE_DIRECTORY) sav_doc.import_document(self.document) sav_doc.save() new_doc = FileDocument(PROFILE_TATA, PROFILE_DIRECTORY) new_doc.load() container = new_doc.get_container(REPO+u"/data/subdir1") self.assert_(dict.has_key(container, "TOtO.txt"))
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() loader = FileDocument() loader.load(path) self.facade.add_peer(loader.get_pseudo()) self.facade.fill_data((loader.get_pseudo(), loader))
def test_load_and_save(self): self.document.load() new_doc = CacheDocument(PROFILE_TATA, PROFILE_DIRECTORY) new_doc.import_document(self.document) new_doc.remove_repository(REPO) self.assertEquals(new_doc.get_files(), {}) new_doc.add_repository(REPO+u"/data/profiles") new_doc.add_repository(REPO+u"/data/subdir1") self.assertEquals(new_doc.get_files()[REPO+u"/data/profiles"]._shared, False) self.assert_(new_doc.get_files()[REPO+u"/data/subdir1"] != None) new_doc.save() check_doc = FileDocument(PROFILE_TATA, PROFILE_DIRECTORY) check_doc.load() self.assertEquals(check_doc.get_files()[REPO+u"/data/profiles"]._shared, False) self.assert_(check_doc.get_files()[REPO+u"/data/subdir1"] != None)
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(path) loader.load() blogs = load_blogs(path) pseudo = loader.pseudo get_facade().fill_data((pseudo, loader)) get_facade().get_peer(pseudo).set_blog(blogs)
class ProfileTest(unittest.TestCase): """test interactactions between profiles""" def setUp(self): """override one in unittest.TestCase""" # bruce doc = FileDocument() self.assert_(doc.load(TEST_BRUCE)) self.bruce_doc = CacheDocument() self.bruce_doc.import_document(doc) # demi self.demi_doc = FileDocument() self.assert_(self.demi_doc.load(TEST_DEMI)) def test_bruce(self): """import bruce data""" self.assertEquals("Bruce", self.bruce_doc.get_firstname()) self.assertEquals("Willis", self.bruce_doc.get_lastname()) self.assertEquals("john", self.bruce_doc.get_pseudo()) self.assertEquals("*****@*****.**", self.bruce_doc.get_email()) self.assertEquals("01/06/1947", self.bruce_doc.get_birthday()) self.assertEquals("English", self.bruce_doc.get_language()) self.assertEquals("Hill", self.bruce_doc.get_address()) self.assertEquals("920", self.bruce_doc.get_postcode()) self.assertEquals("Los Angeles", self.bruce_doc.get_city()) self.assertEquals("US", self.bruce_doc.get_country()) self.assertEquals("Lots of movies, quite famous, doesn't look much but very effective", self.bruce_doc.get_description()) self.assertEquals([u'cinema', u'theatre', u'cop', u'action'], self.bruce_doc.get_hobbies()) self.assertEquals({'music': u'jazz', 'film': u'Die Hard'}, self.bruce_doc.get_custom_attributes())
def test_default(self): document = FileDocument(PROFILE_TEST, PROFILE_DIRECTORY) self.assertEquals(u"", document.get_title()) self.assertEquals(u"Name", document.get_firstname()) self.assertEquals(u"Lastname", document.get_lastname()) self.assertEquals(u'/home/emb/svn/solipsis/trunk/main/solipsis/services/profile/images/question_mark.gif', document.get_photo()) self.assertEquals(u"email", document.get_email()) self.assertEquals({'City': u'', 'Country': u'', 'Favourite Book': u'', 'Favourite Movie': u'', 'Sport': u'', 'Studies': u''}, document.get_custom_attributes()) # assert correct sharing self.assertEquals([], document.get_shared(REPO)) self.assertEquals({}, document.get_files()) # peers self.assertEquals({}, document.get_peers())
def setUp(self): """override one in unittest.TestCase""" self.document = FileDocument() self.document.add_repository(REPO) # first test to call must write test file to get correct # execution of the others if not os.path.exists(TEST_PROFILE): self.test_save()
def save_profile(self, path=None): """save .profile.solipsis""" # get file document if "file" in self.documents: file_doc = self.documents["file"] else: file_doc = FileDocument() # refresh file document to be sure to save updated data if "cache" in self.documents: file_doc.import_document(self.documents["cache"]) else: print "no cache available" # save if not path: # FIXME: needed for coherency between blog and profile. Refactor path = file_doc.file_root if path and path.endswith('.prf'): path = path[:-4] file_doc.save(path) # save blog self.blogs.save(path)
class ProfileTest(unittest.TestCase): """test interactactions between profiles""" def setUp(self): """override one in unittest.TestCase""" # bruce doc = FileDocument(PROFILE_BRUCE, PROFILE_DIRECTORY) self.assert_(doc.load()) self.bruce_doc = CacheDocument(PROFILE_BRUCE, PROFILE_DIRECTORY) self.bruce_doc.import_document(doc) # demi self.demi_doc = FileDocument(PROFILE_DEMI, PROFILE_DIRECTORY) self.assert_(self.demi_doc.load()) def test_bruce(self): """import bruce data""" self.assertEquals("Bruce", self.bruce_doc.get_firstname()) self.assertEquals("Willis", self.bruce_doc.get_lastname()) self.assertEquals("*****@*****.**", self.bruce_doc.get_email()) self.assertEquals({'City': u'', 'Country': u'', 'Favourite Book': u'', 'music': u'jazz', 'Favourite Movie': u'', 'Sport': u'', 'Studies': u'', 'film': u'Die Hard'}, self.bruce_doc.get_custom_attributes()) def test_peer_status(self): self.assertEquals(self.demi_doc.has_peer(self.bruce_doc.pseudo), False) self.demi_doc.fill_data((self.bruce_doc.pseudo, self.bruce_doc)) self.assertEquals(self.demi_doc.has_peer(self.bruce_doc.pseudo), True) self.demi_doc.make_friend(self.bruce_doc.pseudo) self.assertEquals(self.demi_doc.has_peer(self.bruce_doc.pseudo), True) self.demi_doc.unmark_peer(self.bruce_doc.pseudo) self.assertEquals(self.demi_doc.has_peer(self.bruce_doc.pseudo), False)
class FileTest(unittest.TestCase): """test that all fields are correctly validated""" def setUp(self): """override one in unittest.TestCase""" self.document = FileDocument() self.document.add_repository(REPO) # first test to call must write test file to get correct # execution of the others if not os.path.exists(TEST_PROFILE): self.test_save() def _assertContent(self, doc): """check validity of content""" self.assertEquals("Mr", doc.get_title()) self.assertEquals("manu", doc.get_firstname()) self.assertEquals("breton", doc.get_lastname()) self.assertEquals("emb", doc.get_pseudo()) self.assertEquals(unittest.__file__, doc.get_photo()) self.assertEquals("*****@*****.**", doc.get_email()) self.assertEquals("12/01/2005", doc.get_birthday()) self.assertEquals("fr", doc.get_language()) self.assertEquals("12 rue V Hugo", doc.get_address()) self.assertEquals("34000", doc.get_postcode()) self.assertEquals("Paris", doc.get_city()) self.assertEquals("France", doc.get_country()) self.assertEquals("anything", doc.get_description()) self.assertEquals([u'blabla', u'bla bla bla', u''], doc.get_hobbies()) self.assertEquals({'repositories': REPO, 'color': u'blue', 'homepage': u'manu.com'}, doc.get_custom_attributes()) # assert correct sharing self.assertEquals({REPO + u'/data/subdir1/subsubdir/null': u'empty', REPO + u'/data/subdir1': u'none', REPO + u'/data/subdir1/subsubdir/dummy.txt': u'empty', REPO + u'/data/routage': u'none', REPO + u'/data/emptydir': u'none'}, doc.get_shared(REPO)) files = doc.get_files() self.assertEquals(files.has_key(REPO), True) self.assertEquals(files[REPO][abspath(u"data")]._shared, False) self.assertEquals(files[REPO][abspath(u"data/routage")]._shared, True) self.assertEquals(files[REPO][abspath(u"data/emptydir")]._shared, True) self.assertEquals(files[REPO][abspath(u"data/subdir1")]._shared, True) self.assertEquals(files[REPO][abspath(u"data/subdir1/")]._shared, True) self.assertEquals(files[REPO].has_key(abspath(u"data/subdir1/date.doc")), False) self.assertEquals(files[REPO][abspath(u"data/subdir1/subsubdir")]._shared, False) self.assertEquals(files[REPO][abspath(u"data/subdir1/subsubdir/null")]._shared, True) self.assertEquals(files[REPO][abspath(u"data/subdir1/subsubdir/dummy.txt")]._shared, True) self.assertEquals(files[REPO].has_key(abspath(u"data/subdir1/subsubdir/default.solipsis")), False) # peers peers = doc.get_peers() self.assertEquals(peers.has_key(u'nico'), True) self.assertEquals(peers[u'nico'][0].state, PeerDescriptor.FRIEND) self.assertEquals(peers[u'nico'][1], None) # PERSONAL TAB def test_save(self): """Fill a full set of data""" 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(unittest.__file__) 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 self.document.add_peer(u"nico") self.document.make_friend(u"nico") # check content self._assertContent(self.document) # write file self.document.save(TEST_PROFILE) def test_load(self): """import data""" self.document.load(TEST_PROFILE) self._assertContent(self.document) def test_import(self): """import file document into cache document""" self.document.load(TEST_PROFILE) new_doc = CacheDocument() new_doc.import_document(self.document) self._assertContent(new_doc) def test_save_and_load(self): """save & load""" self.document.load(TEST_PROFILE) self.document.share_file((REPO+"/data/subdir1/TOtO.txt", True)) self.document.save("tata.prf") new_doc = FileDocument() new_doc.load("tata.prf") container = new_doc.get_container(REPO+u"/data/subdir1") self.assert_(dict.has_key(container, "TOtO.txt")) def test_load_and_save(self): """load & save""" self.document.load(TEST_PROFILE) new_doc = CacheDocument() new_doc.import_document(self.document) new_doc.remove_repository(REPO) self.assertEquals(new_doc.get_files(), {}) new_doc.add_repository(REPO+u"/data/profiles") new_doc.add_repository(REPO+u"/data/subdir1") self.assertEquals(new_doc.get_files()[REPO+u"/data/profiles"]._shared, False) self.assert_(new_doc.get_files()[REPO+u"/data/subdir1"] != None) new_doc.save("toto.prf") def test_default(self): """load default""" self.document.load(u"dummy") self.assertEquals(u"Mr", self.document.get_title()) self.assertEquals(u"Emmanuel", self.document.get_firstname()) self.assertEquals(u"Breton", self.document.get_lastname()) self.assertEquals(u"emb", self.document.get_pseudo()) self.assertEquals(u'/home/emb/svn/solipsis/trunk/main/solipsis/services/profile/images/question_mark.gif', self.document.get_photo()) self.assertEquals(u"*****@*****.**", self.document.get_email()) self.assertEquals(u"01/04/2005", self.document.get_birthday()) self.assertEquals(u"fr", self.document.get_language()) self.assertEquals(u"", self.document.get_address()) self.assertEquals(u"75", self.document.get_postcode()) self.assertEquals(u"", self.document.get_city()) self.assertEquals(u"", self.document.get_country()) self.assertEquals(u"Developer/Designer of this handful plugin", self.document.get_description()) self.assertEquals([], self.document.get_hobbies()) self.assertEquals({'repositories': REPO}, self.document.get_custom_attributes()) # assert correct sharing self.assertEquals({}, self.document.get_shared(REPO)) self.assertEquals({REPO: DirContainer(REPO)}, self.document.get_files()) # peers self.assertEquals({}, self.document.get_peers()) def test_view(self): """load & printView""" self.document.load(TEST_PROFILE) result = StringIO() view = PrintView(self.document, result, do_import=True) self.assertEquals(result.getvalue(), """Mr manu breton emb /usr/lib/python2.3/unittest.pyc [email protected] 12/01/2005 fr 12 rue V Hugo 34000 Paris France anything [u'blabla', u'bla bla bla', u''] {'color': u'blue', 'homepage': u'manu.com', 'repositories': u'/home/emb/svn/solipsis/trunk/main/solipsis/services/profile/tests'} {u'/home/emb/svn/solipsis/trunk/main/solipsis/services/profile/tests': {Dc:tests(?-,'none',#0) : [{Dc:data(?-,'none',#3) : [{Dc:emptydir(?Y,'none',#-1) : []}, Fc:routage(?Y,'none'), Fc:date.txt(?-,'tagos'), {Dc:subdir1(?Y,'none',#-1) : [{Dc:subsubdir(?-,'none',#2) : [Fc:null(?Y,'empty'), Fc:dummy.txt(?Y,'empty')]}]}]}]}} {u'nico': [nico (%s), None]} """% PeerDescriptor.FRIEND) result.close()
class FileTest(unittest.TestCase): """test that all fields are correctly validated""" def setUp(self): """override one in unittest.TestCase""" self.document = FileDocument(PROFILE_TEST, PROFILE_DIRECTORY) self.document.add_repository(REPO) # first test to call must write test file to get correct # execution of the others if not os.path.exists(os.path.join(PROFILE_DIRECTORY, PROFILE_TEST)): self.test_save() def _assertContent(self, doc): """check validity of content""" self.assertEquals("Mr", doc.get_title()) self.assertEquals("manu", doc.get_firstname()) self.assertEquals("breton", doc.get_lastname()) self.assertEquals(QUESTION_MARK(), doc.get_photo()) self.assertEquals("*****@*****.**", doc.get_email()) self.assertEquals({'City': u'', 'color': u'blue', 'Country': u'', 'Favourite Book': u'', 'homepage': u'manu.com', 'Favourite Movie': u'', 'Sport': u'', 'Studies': u''}, doc.get_custom_attributes()) # assert correct sharing shared_dict = {} for container in doc.get_shared(REPO): shared_dict[container.get_path()] = container expected_files = {REPO + u'/data/subdir1/subsubdir/null': u'empty', REPO + u'/data/subdir1': u'none', REPO + u'/data/subdir1/subsubdir/dummy.txt': u'empty', REPO + u'/data/routage': u'none', REPO + u'/data/emptydir': u'none'} for expected, tag in expected_files.iteritems(): self.assert_(shared_dict.has_key(expected)) self.assertEquals(shared_dict[expected]._tag, tag) files = doc.get_files() self.assertEquals(files.has_key(REPO), True) self.assertEquals(files[REPO][abspath(u"data")]._shared, False) self.assertEquals(files[REPO][abspath(u"data/routage")]._shared, True) self.assertEquals(files[REPO][abspath(u"data/emptydir")]._shared, True) self.assertEquals(files[REPO][abspath(u"data/subdir1")]._shared, True) self.assertEquals(files[REPO][abspath(u"data/subdir1/")]._shared, True) self.assertEquals(files[REPO].has_key(abspath(u"data/subdir1/date.doc")), False) self.assertEquals(files[REPO][abspath(u"data/subdir1/subsubdir")]._shared, False) self.assertEquals(files[REPO][abspath(u"data/subdir1/subsubdir/null")]._shared, True) self.assertEquals(files[REPO][abspath(u"data/subdir1/subsubdir/dummy.txt")]._shared, True) self.assertEquals(files[REPO].has_key(abspath(u"data/subdir1/subsubdir/default.solipsis")), False) # peers peers = doc.get_peers() self.assertEquals(peers.has_key(u'bruce'), True) self.assertEquals(peers[u'bruce'].state, PeerDescriptor.FRIEND) self.assertEquals(peers[u'bruce'].connected, False) # PERSONAL TAB 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_load(self): self.document.load() self._assertContent(self.document) def test_import(self): self.document.load() new_doc = CacheDocument(PROFILE_TEST, PROFILE_DIRECTORY) new_doc.import_document(self.document) self._assertContent(new_doc) def test_save_and_load(self): self.document.load() self.document.share_file((REPO+"/data/subdir1/TOtO.txt", True)) sav_doc = FileDocument(PROFILE_TATA, PROFILE_DIRECTORY) sav_doc.import_document(self.document) sav_doc.save() new_doc = FileDocument(PROFILE_TATA, PROFILE_DIRECTORY) new_doc.load() container = new_doc.get_container(REPO+u"/data/subdir1") self.assert_(dict.has_key(container, "TOtO.txt")) def test_load_and_save(self): self.document.load() new_doc = CacheDocument(PROFILE_TATA, PROFILE_DIRECTORY) new_doc.import_document(self.document) new_doc.remove_repository(REPO) self.assertEquals(new_doc.get_files(), {}) new_doc.add_repository(REPO+u"/data/profiles") new_doc.add_repository(REPO+u"/data/subdir1") self.assertEquals(new_doc.get_files()[REPO+u"/data/profiles"]._shared, False) self.assert_(new_doc.get_files()[REPO+u"/data/subdir1"] != None) new_doc.save() check_doc = FileDocument(PROFILE_TATA, PROFILE_DIRECTORY) check_doc.load() self.assertEquals(check_doc.get_files()[REPO+u"/data/profiles"]._shared, False) self.assert_(check_doc.get_files()[REPO+u"/data/subdir1"] != None) def test_default(self): document = FileDocument(PROFILE_TEST, PROFILE_DIRECTORY) self.assertEquals(u"", document.get_title()) self.assertEquals(u"Name", document.get_firstname()) self.assertEquals(u"Lastname", document.get_lastname()) self.assertEquals(u'/home/emb/svn/solipsis/trunk/main/solipsis/services/profile/images/question_mark.gif', document.get_photo()) self.assertEquals(u"email", document.get_email()) self.assertEquals({'City': u'', 'Country': u'', 'Favourite Book': u'', 'Favourite Movie': u'', 'Sport': u'', 'Studies': u''}, document.get_custom_attributes()) # assert correct sharing self.assertEquals([], document.get_shared(REPO)) self.assertEquals({}, document.get_files()) # peers self.assertEquals({}, document.get_peers()) def test_view(self): self.document.load() self.assertEquals(self.document.get_title(), "Mr") self.assertEquals(self.document.get_firstname(), "manu") self.assertEquals(self.document.get_lastname(), "breton") self.assertEquals(self.document.get_photo(), QUESTION_MARK()) self.assertEquals(self.document.get_email(), "*****@*****.**") self.assertEquals(self.document.get_download_repo(), "/home/emb/.solipsis/download") self.assertEquals(self.document.get_custom_attributes(), {'City': u'', 'Studies': u'', 'color': u'blue', 'Country': u'', 'Favourite Book': u'', 'Favourite Movie': u'', 'Sport': u'', 'homepage': u'manu.com'}) self.assertEquals(str(self.document.get_files()), "{u'/home/emb/svn/solipsis/trunk/main/solipsis/services/profile/tests': {Dc:tests(?-,'none',#0) : [{Dc:data(?-,'none',#3) : [{Dc:emptydir(?Y,'none',#-1) : []}, Fc:routage(?Y,'none'), Fc:date.txt(?-,'tagos'), {Dc:subdir1(?Y,'none',#-1) : [{Dc:subsubdir(?-,'none',#2) : [Fc:null(?Y,'empty'), Fc:dummy.txt(?Y,'empty')]}]}]}]}}") self.assertEquals(str(self.document.get_peers()), "{u'bruce': bruce (%s)}"% PeerDescriptor.FRIEND)
def _on_new_profile(self, pseudo, profile): """store and display file object corresponding to profile""" stream = StringIO(profile) document = FileDocument() document.read(stream) self.facade.fill_data((pseudo, document))
def test_default(self): document = FileDocument() self.assertEquals(u"Mr", document.get_title()) self.assertEquals(u"Emmanuel", document.get_firstname()) self.assertEquals(u"Breton", document.get_lastname()) self.assertEquals(u"emb", document.get_pseudo()) self.assertEquals(u'/home/emb/svn/solipsis/trunk/main/solipsis/services/profile/images/question_mark.gif', document.get_photo()) self.assertEquals(u"*****@*****.**", document.get_email()) self.assertEquals(u"01/04/2005", document.get_birthday()) self.assertEquals(u"fr", document.get_language()) self.assertEquals(u"", document.get_address()) self.assertEquals(u"75", document.get_postcode()) self.assertEquals(u"", document.get_city()) self.assertEquals(u"", document.get_country()) self.assertEquals(u"Developer/Designer of this handful plugin", document.get_description()) self.assertEquals([], document.get_hobbies()) self.assertEquals({}, document.get_custom_attributes()) # assert correct sharing self.assertEquals([], document.get_shared(REPO)) self.assertEquals({}, document.get_files()) # peers self.assertEquals({}, document.get_peers())