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
 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
 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 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):
     # 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 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 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 read_document(file_obj):
    """use FileDocument to load document from 'file_obj'"""
    from solipsis.services.profile.file_document import FileDocument
    encoding = load_encoding(file_obj)
    config = CustomConfigParser(encoding)
    config.readfp(file_obj)
    file_obj.close()
    doc = FileDocument()
    doc.encoding = encoding
    doc.config = config
    return doc
 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))
 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 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)
 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 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 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 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 read_document(stream):
    """use FileDocument to load document"""
    from solipsis.services.profile.file_document import FileDocument
    encoding = stream.readline()[1:]
    config = CustomConfigParser(encoding)
    config.readfp(stream)
    stream.close()
    try:
        pseudo = unicode(config.get(SECTION_PERSONAL,
                                    "pseudo", "Anonymous"),
                         ENCODING)
    except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
        print "Could not retreive pseudo"
        pseudo = u"Anonymous"
    doc = FileDocument(pseudo)
    doc.encoding = encoding
    doc.config = config
    return doc
 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_import(self):
     # file -> cache
     new_doc = CacheDocument()
     new_doc.import_document(self.document)
     self._assertContent(new_doc)
     # cache -> cache
     cache_doc = CacheDocument()
     cache_doc.import_document(new_doc)
     self._assertContent(cache_doc)
     # cache -> file
     file_doc = FileDocument()
     file_doc.import_document(cache_doc)
     self._assertContent(file_doc)
     # file -> file
     other_doc = FileDocument()
     other_doc.import_document(file_doc)
     self._assertContent(other_doc)
 def save(self, path):
     """fill document with information from .profile file"""
     from solipsis.services.profile.file_document import FileDocument
     doc = FileDocument()
     doc.import_document(self)
     doc.save(path)
 def save(self):
     """fill document with information from .profile file"""
     from solipsis.services.profile.file_document import FileDocument
     doc = FileDocument(self.pseudo, self._dir)
     doc.import_document(self)
     doc.save()
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)
 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 get_bruce_profile():
    """return PeerDescriptor filled with:
    
    node_id = PROFILE_BRUCE
    
    Blog:
    `````
      'Hi Buddy'

    Files:
    ``````
      data/
      |-- date.txt           Shared
      |-- ...
      `-- subdir1
          |-- date.doc       Shared
          `-- ...
    """
    # write bruce blog
    bruce_blog = Blogs()
    bruce_blog.add_blog(u"Hi Buddy", u"bruce")
    # write bruce profile
    bruce_doc = FileDocument()
    bruce_doc.set_pseudo(u"bruce")
    bruce_doc.set_title(u"Mr")
    bruce_doc.set_firstname(u"bruce")
    bruce_doc.set_lastname(u"willis")
    bruce_doc.set_photo(QUESTION_MARK())
    bruce_doc.set_email(u"*****@*****.**")
    bruce_doc.add_custom_attributes(u"Homepage", u"bruce.com")
    bruce_doc.add_custom_attributes(u'Color', u'gray')
    bruce_doc.add_custom_attributes(u'Movie', u'6th Sense')
    bruce_doc.add_custom_attributes(u'Actor', u'Robin Williams')
    bruce_doc.add_repository(TEST_DIR)
    bruce_doc.share_file(os.path.join(DATA_DIR, "date.txt"))
    bruce_doc.share_file(os.sep.join([DATA_DIR,
                                      "subdir1",
                                      "date.doc"]))
    return PeerDescriptor(PROFILE_BRUCE, document=bruce_doc, blog=bruce_blog)
 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_default(self):
     document = FileDocument()
     self.assertEquals(u"", document.get_title())
     self.assertEquals(u"Name", document.get_firstname())
     self.assertEquals(u"Lastname", document.get_lastname())
     self.assertEquals(QUESTION_MARK(),
                       document.get_photo())
     self.assertEquals(u"email", document.get_email())
     self.assertEquals({},
                       document.get_custom_attributes())
     # assert correct sharing
     self.assertEquals({}, document.get_shared_files())
     self.assertEquals({}, document.get_files())
     # peers
     self.assertEquals({}, document.get_peers())
     # load
     document.load_defaults()
     self.assertEquals({'City': u'', 'Country': u'',
                        'Favourite Book': u'', 'Favourite Movie': u'',
                        'Sport': u'', 'Studies': u''},
                       document.get_custom_attributes())
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)
 def to_stream(self):
     """fill document with information from .profile file"""
     from solipsis.services.profile.file_document import FileDocument
     doc = FileDocument()
     doc.import_document(self)
     return doc.to_stream()
def write_test_profile():
    """write testing profile & blogs into test.prf & test.blog
    
    node_id = PROFILE_BRUCE
    
    Blog:
    `````
      'This is a test'

    Files:
    ``````
      data/
      |-- date.txt                  - tagos
      |-- emptydir           Shared
      |-- profiles
      |   `-- ...
      |-- routage            Shared
      `-- subdir1            Shared
          |-- TOtO.txt
          |-- date.doc
          `-- subsubdir
              |-- dummy.txt  Shared - tag2
              |-- null       Shared - tag1
              `-- ..."""
    # write filter
    filter_document = FilterDocument()
    filter_document.set_pseudo(FilterValue(value=".*", activate=True))
    filter_document.set_title(FilterValue(value="Mr", activate=True))
    filter_document.set_lastname(FilterValue(value="b.*", activate=True))
    filter_document.add_custom_attributes('color', FilterValue(value="blue", activate=True))
    filter_document.add_repository("MP3", FilterValue(value=".*\.mp3", activate=True))
    if os.path.exists(FILE_TEST + FILTER_EXT):
        os.remove(FILE_TEST + FILTER_EXT)
    filter_document.save(FILE_TEST + FILTER_EXT)
    # write blog
    blog = Blogs()
    blog.add_blog(u"This is a test", PSEUDO)
    if os.path.exists(FILE_TEST + BLOG_EXT):
        os.remove(FILE_TEST + BLOG_EXT)
    blog.save(FILE_TEST + BLOG_EXT)
    # write profile
    document = FileDocument()
    document.set_pseudo(PSEUDO)
    document.set_title(u"Mr")
    document.set_firstname(u"manu")
    document.set_lastname(u"breton")
    document.set_photo(QUESTION_MARK())
    document.set_email(u"*****@*****.**")
    document.load_defaults()
    document.add_custom_attributes(u"homepage", u"manu.com")
    document.add_custom_attributes(u'color', u'blue')
    document.remove_custom_attributes(u'Sport')
    document.add_repository(TEST_DIR)
    document.expand_dir(DATA_DIR)
    document.expand_dir(os.path.join(DATA_DIR,
                                     "subdir1"))
    document.share_files(DATA_DIR,
                         ["routage", "emptydir", "subdir1"])
    document.share_files(os.sep.join([DATA_DIR,
                                      "subdir1",
                                      "subsubdir"]),
                         ["null", "dummy.txt"])
    document.tag_file(os.path.join(DATA_DIR,
                                   "date.txt"),
                      u"tagos")
    document.tag_file(os.sep.join([DATA_DIR,
                                   "subdir1",
                                   "subsubdir",
                                   "null"]),
                      u"tag1")
    document.tag_file(os.sep.join([DATA_DIR,
                                   "subdir1",
                                   "subsubdir",
                                   "dummy.txt"]),
                      u"tag2")
    # set peers
    bruce = get_bruce_profile()
    bruce_doc = bruce.document
    bruce_blog = bruce.blog
    document.fill_data(PROFILE_BRUCE, bruce_doc)
    document.fill_blog(PROFILE_BRUCE, bruce_blog)
    document.make_friend(PROFILE_BRUCE)
    # write file
    if os.path.exists(FILE_TEST + PROFILE_EXT):
        os.remove(FILE_TEST + PROFILE_EXT)
    document.save(FILE_TEST + PROFILE_EXT)