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_filling_data(self):
     """fill data"""
     for document in self.documents:
         self.assertEquals(document.has_peer(u"emb"), False)
         file_doc = FileDocument(PROFILE_TEST, PROFILE_DIRECTORY)
         file_doc.load()
         document.fill_data((u"emb", file_doc))
 def setUp(self):
     # peer
     peer_document = FileDocument(PROFILE_TEST, PROFILE_DIRECTORY)
     peer_document.load()
     self.peer_desc = PeerDescriptor(PROFILE_TEST, document=peer_document)
     self.peer_desc.set_shared_files()
     # filter
     self.document = FilterDocument(PROFILE_TEST, PROFILE_DIRECTORY)
     self.document.load()
 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+"/data/subdir1")
     self.assert_(dict.has_key(container, "TOtO.txt"))
 def test_match_peer(self):
     # TODO: detail test
     filter_facade = create_filter_facade(PROFILE_TEST, PROFILE_DIRECTORY)
     filter_facade.load()
     document = FileDocument(PROFILE_TEST, PROFILE_DIRECTORY)
     document.load()
     peer_desc = PeerDescriptor(PROFILE_TEST, document=document)
     self.facade.fill_data((PROFILE_TEST, peer_desc))
     filter_facade.set_peer((PROFILE_TEST, peer_desc))
     filter_facade.activate(False)
     filter_facade.set_peer((PROFILE_TEST, peer_desc))
Exemplo n.º 6
0
 def on_import(self, evt):
     """match current filter with given profile"""
     dlg = wx.FileDialog(
         self, message="Match profile ...",
         defaultDir=get_prefs("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 + PROFILE_EXT)
         get_facade().fill_data(loader.get_pseudo(), loader)
         get_filter_facade().fill_data(loader.get_pseudo(), loader)
Exemplo n.º 7
0
 def on_import(self, evt):
     """match current filter with given profile"""
     dlg = wx.FileDialog(
         self, message="Match 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()
         pseudo = loader.pseudo
         get_facade().fill_data((pseudo, loader))
         get_filter_facade().fill_data((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.del_file(REPO)
     self.assertEquals(new_doc.get_files(), {})
     new_doc.add_file(REPO+"/data/profiles")
     new_doc.add_file(REPO+"/data/subdir1")
     self.assertEquals(new_doc.get_files()[REPO+"/data/profiles"]._shared, True)
     self.assert_(new_doc.get_files()[REPO+"/data/subdir1"] != None)
     new_doc.save()
     check_doc = FileDocument(PROFILE_TATA, PROFILE_DIRECTORY)
     check_doc.load()
     self.assertEquals(check_doc.get_files()[REPO+"/data/profiles"]._shared, True)
     self.assert_(check_doc.get_files()[REPO+"/data/subdir1"] != None)
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)
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
 def load(self):
     """fill document with information from .profile file"""
     from solipsis.services.profile.file_document import FileDocument
     doc = FileDocument(self.pseudo, self._dir)
     result = doc.load()
     self.import_document(doc)
     return result
Exemplo n.º 12
0
 def load(self, path):
     """fill document with information from .profile file"""
     from solipsis.services.profile.file_document import FileDocument
     doc = FileDocument()
     result = doc.load(path)
     self.import_document(doc)
     return result
Exemplo n.º 13
0
def load_document(pseudo, directory=PROFILE_DIR):
    """build FileDocumentn from file"""
    assert isinstance(pseudo, unicode), "pseudo must be a unicode"
    from solipsis.services.profile.file_document import FileDocument
    doc = FileDocument(pseudo, directory)
    if not doc.load():
        print "Could not find document"
    return doc
 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())
Exemplo n.º 15
0
def load_document(pseudo, directory=None):
    """build FileDocumentn from file"""
    assert isinstance(pseudo, unicode), "pseudo must be a unicode"
    if directory is None:
        directory = get_prefs("profile_dir")
    from solipsis.services.profile.file_document import FileDocument
    doc = FileDocument(pseudo, directory)
    if not doc.load():
        print "Could not find document"
    return doc
 def test_default(self):
     document = FileDocument(u"dummy", 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({},
                       document.get_custom_attributes())
     # assert correct sharing
     self.assertEquals([], document.get_shared(REPO))
     self.assertEquals({}, document.get_files())
     # peers
     self.assertEquals({}, document.get_peers())
     # load
     document.load()
     self.assertEquals({'City': u'', 'Country': u'',
                        'Favourite Book': u'', 'Favourite Movie': u'',
                        'Sport': u'', 'Studies': u''},
                       document.get_custom_attributes())
 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)
         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.load_defaults()
     self.document.add_custom_attributes((u"homepage", u"manu.com"))
     self.document.add_custom_attributes((u'color', u'blue'))
     self.document.remove_custom_attributes(u'Sport')
     # set files
     self.document.add(abspath("data"))
     self.document.expand_dir(abspath("data"))
     self.document.expand_dir(abspath("data/subdir1"))
     self.document.recursive_share((abspath("data"), False))
     self.assertEquals(self.document.get_files()[REPO][abspath("data")]._shared, False)
     self.document.share_files((abspath("data"), ["routage", "emptydir", "subdir1"], True))
     self.document.share_files((abspath("data/subdir1/subsubdir"), ["null", "dummy.txt"], True))
     self.document.tag_files((abspath("data"), ["date.txt"], u"tagos"))
     self.document.tag_files((abspath("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.assertEquals(self.document.get_files()[REPO][abspath("data")]._shared, False)
     self.document.save()
     # check content
     self.assertEquals(self.document.get_files()[REPO][abspath("data")]._shared, False)
     self._assertContent(self.document)
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_file(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 + PROFILE_EXT)):
            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'', '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 + '/data/subdir1/subsubdir/null': u'empty',
                          REPO + '/data/subdir1': u'none',
                          REPO + '/data/subdir1/subsubdir/dummy.txt': u'empty',
                          REPO + '/data/routage': u'none',
                          REPO + '/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("data")]._shared, False)
        self.assertEquals(files[REPO][abspath("data/routage")]._shared, True)
        self.assertEquals(files[REPO][abspath("data/emptydir")]._shared, True)
        self.assertEquals(files[REPO][abspath("data/subdir1")]._shared, True)
        self.assertEquals(files[REPO][abspath("data/subdir1/")]._shared, True)
        self.assertEquals(files[REPO][abspath("data/subdir1/subsubdir")]._shared, False)
        self.assertEquals(files[REPO][abspath("data/subdir1/subsubdir/null")]._shared, True)
        self.assertEquals(files[REPO][abspath("data/subdir1/subsubdir/dummy.txt")]._shared, True)
        self.assertEquals(files[REPO].has_key(abspath("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)
            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.load_defaults()
        self.document.add_custom_attributes((u"homepage", u"manu.com"))
        self.document.add_custom_attributes((u'color', u'blue'))
        self.document.remove_custom_attributes(u'Sport')
        # set files
        self.document.add(abspath("data"))
        self.document.expand_dir(abspath("data"))
        self.document.expand_dir(abspath("data/subdir1"))
        self.document.recursive_share((abspath("data"), False))
        self.assertEquals(self.document.get_files()[REPO][abspath("data")]._shared, False)
        self.document.share_files((abspath("data"), ["routage", "emptydir", "subdir1"], True))
        self.document.share_files((abspath("data/subdir1/subsubdir"), ["null", "dummy.txt"], True))
        self.document.tag_files((abspath("data"), ["date.txt"], u"tagos"))
        self.document.tag_files((abspath("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.assertEquals(self.document.get_files()[REPO][abspath("data")]._shared, False)
        self.document.save()
        # check content
        self.assertEquals(self.document.get_files()[REPO][abspath("data")]._shared, False)
        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):
        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+"/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.del_file(REPO)
        self.assertEquals(new_doc.get_files(), {})
        new_doc.add_file(REPO+"/data/profiles")
        new_doc.add_file(REPO+"/data/subdir1")
        self.assertEquals(new_doc.get_files()[REPO+"/data/profiles"]._shared, True)
        self.assert_(new_doc.get_files()[REPO+"/data/subdir1"] != None)
        new_doc.save()
        check_doc = FileDocument(PROFILE_TATA, PROFILE_DIRECTORY)
        check_doc.load()
        self.assertEquals(check_doc.get_files()[REPO+"/data/profiles"]._shared, True)
        self.assert_(check_doc.get_files()[REPO+"/data/subdir1"] != None)
        
        
    def test_default(self):
        document = FileDocument(u"dummy", 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({},
                          document.get_custom_attributes())
        # assert correct sharing
        self.assertEquals([], document.get_shared(REPO))
        self.assertEquals({}, document.get_files())
        # peers
        self.assertEquals({}, document.get_peers())
        # load
        document.load()
        self.assertEquals({'City': u'', 'Country': u'',
                           'Favourite Book': u'', 'Favourite Movie': u'',
                           'Sport': u'', 'Studies': u''},
                          document.get_custom_attributes())
        
    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_custom_attributes(), {'City': u'', 'Studies': u'',
                                                            'color': u'blue', 'Country': u'',
                                                            'Favourite Book': u'', 'Favourite Movie': u'',
                                                            'homepage': u'manu.com'})
        self.assertEquals(str(self.document.get_files()),
                          "{'/home/emb/svn/solipsis/trunk/main/solipsis/services/profile/tests': {Dc:tests(?Y,'none',#4) : [{Dc:data(?-,'none',#4) : [Fc:.path(?-,'none'), {Dc:profiles(?-,'none',#0) : []}, {Dc:subdir1(?Y,'none',#3) : [Fc:date.doc(?-,'none'), Fc:TOtO.txt(?Y,'none'), {Dc:subsubdir(?-,'none',#2) : [Fc:null(?Y,'empty'), Fc:dummy.txt(?Y,'empty')]}, {Dc:.svn(?-,'none',#0) : []}]}, Fc:routage(?Y,'none'), {Dc:emptydir(?Y,'none',#0) : []}, {Dc:.svn(?-,'none',#0) : []}, Fc:date.txt(?-,'tagos')]}]}}")
        self.assertEquals(str(self.document.get_peers()),
                          "{u'bruce': bruce (%s)}"% PeerDescriptor.FRIEND)