Exemple #1
0
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 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 setUp(self):
     """override one in unittest.TestCase"""
     self.repo = u"/home/emb/svn/solipsis/trunk/main/solipsis/services/profile/tests"
     doc = CacheDocument()
     doc.add_repository(self.repo)
     self.result = StringIO()
     self.facade = get_facade(doc, PrintView(doc, self.result))
 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 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 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 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))
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 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_multiple_repos(self):
     """coherency when several repos in use"""
     document = CacheDocument()
     # create 2 repos
     document.add_repository(REPO + "/data/profiles")
     document.tag_files((REPO + "/data/profiles", ["bruce.prf", ".svn"], u"first"))
     document.share_files((REPO + "/data/profiles", ["bruce.prf", "demi.prf"], True))
     document.add_repository(REPO + "/data/subdir1")
     document.tag_files((REPO + "/data/subdir1", ["date.doc", ".svn"], u"second"))
     document.share_files((REPO + "/data/subdir1", ["date.doc", "subsubdir"], True))
     # check sharing state
     self.assertEquals(document.get_container(
         abspath("data/profiles/bruce.prf"))._shared, True)
     self.assertEquals(document.get_container(
         abspath("data/profiles/demi.prf"))._shared, True)
     self.assertEquals(document.get_container(
         abspath("data/profiles/.svn"))._shared, False)
     self.assertEquals(document.get_container(
         abspath("data/subdir1/date.doc"))._shared, True)
     self.assertEquals(document.get_container(
         abspath("data/subdir1/subsubdir"))._shared, True)
     self.assertEquals(document.get_container(
         abspath("data/subdir1/.svn"))._shared, False)
     # check tag
     self.assertRaises(ValueError, document.add_repository, REPO + "/data/subdir1/subsubdir")
     self.assertRaises(ValueError, document.add_repository, REPO + "/data")
 def test_get_shared_files(self):
     document = CacheDocument()
     document.add_repository(REPO)
     document.add((abspath(u"data")))
     document.share_file((abspath(u"data"), True))
     document.share_file((abspath(u"data/.path"), True))
     document.share_files((abspath(u"data/profiles"),
                           ["bruce.prf", "demi.prf"],
                           True))
     document.share_files((REPO + "/data/subdir1",
                           ["date.doc"],
                           True))
     shared_files = [file_container.path for file_container
                     in document.get_shared_files()[REPO]]
     shared_files.sort()
     self.assertEquals(shared_files, [REPO + "/data/.path",
                                      REPO + "/data/date.txt",
                                      REPO + "/data/profiles/bruce.prf",
                                      REPO + "/data/profiles/demi.prf",
                                      REPO + "/data/routage",
                                      REPO + "/data/subdir1/date.doc"])
 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_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 setUp(self):
     """override one in unittest.TestCase"""
     self.document = CacheDocument()
     self.view = HtmlView(self.document)
class HtmlTest(unittest.TestCase):
    """test that all fields are correctly validated"""

    def setUp(self):
        """override one in unittest.TestCase"""
        self.document = CacheDocument()
        self.view = HtmlView(self.document)

    def assert_template(self):
        """diff result from view with expeceted template"""
        self.view.import_document(self.document)
        result = difflib.ndiff(
            [line.strip() for line in self.print_template().splitlines()],
            [line.strip() for line in self.view.get_view(True).splitlines()],
            charjunk=lambda x: x in [" ", "\t"],
        )
        result = list(result)
        for index, line in enumerate(result):
            if not line.startswith("  "):
                print self.view.get_view()
                print "*************"
                print "\n".join(result[index - 2 : index + 10])
            self.assert_(line.startswith("  "))

    def print_template(self):
        """fill template with values"""
        return TEMPLATE % (
            self.document.get_photo(),
            self.document.get_pseudo(),
            self.document.get_title(),
            self.document.get_firstname(),
            self.document.get_lastname(),
            self.document.get_email(),
            self.document.get_birthday(),
            self.document.get_language(),
            self.document.get_address(),
            self.document.get_postcode(),
            self.document.get_city(),
            self.document.get_country(),
            self.document.get_description(),
            self.print_hobbies(),
            self.print_custom(),
            self.print_files(),
            self.print_peers(),
        )

    def print_hobbies(self):
        html = [" <span>%s</span> |" % item for item in self.document.get_hobbies()] or ""
        return "".join(html)

    def print_custom(self):
        html = [
            "<div><b>%s</b>: <span>%s</span></div>" % (key, value)
            for key, value in self.document.get_custom_attributes().iteritems()
        ]
        return "".join(html)

    def print_files(self):
        html = []
        repos = self.document.get_repositories()
        repos.sort()
        for repo in repos:
            html.append(
                """
    <dt>%s</dt>
    <dd>%d shared files</dd>
"""
                % (repo, len(self.document.get_shared(repo)))
            )
        # concatenate all description of directories & return result
        return "".join(html)

    def print_peers(self):
        html = []
        peers = self.document.get_peers()
        keys = peers.keys()
        keys.sort()
        for key in keys:
            peers_desc = peers[key]
            doc = peers_desc.document
            html.append(
                """<tr>
      <td>%s</td>
      <td>%s</td>
      <td>%s</td>
    </tr>"""
                % (peers_desc.state, doc and doc.get_pseudo() or "--", peers_desc.peer_id)
            )
        return "".join(html)

    # PERSONAL TAB
    def test_personal(self):
        """personal info"""
        self.document.set_title(u"Mr")
        self.document.set_firstname(u"Bruce")
        self.document.set_lastname(u"Willis")
        self.document.set_pseudo(u"john")
        self.document.set_photo(u"/home/emb/svn/solipsis/trunk/main/solipsis/services/profile/images/profile_male.gif")
        self.document.set_email(u"*****@*****.**")
        self.document.set_birthday(u"1/6/1947")
        self.document.set_language(u"English")
        self.document.set_address(u"Hill")
        self.document.set_postcode(u"920")
        self.document.set_city(u"Los Angeles")
        self.document.set_country(u"US")
        self.document.set_description(u"Lots of movies, quite famous, doesn't look much but very effective")
        self.assert_template()

    # CUSTOM TAB
    def test_hobbies(self):
        self.document.set_hobbies([u"cinema", u"theatre", u"cop", u"action"])
        self.assert_template()

    def test_custom(self):
        self.document.add_custom_attributes([u"zic", u"jazz"])
        self.document.add_custom_attributes([u"cinema", u"Die Hard"])
        self.assert_template()

    # FILE TAB
    def test_files(self):
        self.document.add_repository(abspath(u"."))
        self.document.expand_dir(abspath(u"data"))
        self.document.share_files((abspath(u"data"), ["routage"], True))
        self.document.share_file((abspath(u"data/emptydir"), True))
        self.assert_template()

    # OTHERS TAB
    def test_ordered_peer(self):
        self.document.add_peer(u"nico")
        self.document.make_friend(u"emb")
        self.document.make_friend(u"star")
        self.document.make_friend(u"albert")
        self.assert_template()

    def test_adding_peer(self):
        self.document.add_peer(u"nico")
        self.assert_template()

    def test_filling_data(self):
        self.document.fill_data((u"emb", FileDocument()))
        self.assert_template()

    def test_peers_status(self):
        self.document.blacklist_peer(u"nico")
        self.assert_template()
 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_import(self):
     self.document.load(TEST_PROFILE)
     new_doc = CacheDocument()
     new_doc.import_document(self.document)
     self._assertContent(new_doc)
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_peer_status(self):
         self.assertEquals(self.demi_doc.has_peer(self.bruce_doc.get_pseudo()), False)
         self.demi_doc.fill_data((self.bruce_doc.get_pseudo(), self.bruce_doc))
         self.assertEquals(self.demi_doc.has_peer(self.bruce_doc.get_pseudo()), False)
         self.demi_doc.make_friend(self.bruce_doc.get_pseudo())
         self.assertEquals(self.demi_doc.has_peer(self.bruce_doc.get_pseudo()), True)
         self.demi_doc.unmark_peer(self.bruce_doc.get_pseudo())
         self.assertEquals(self.demi_doc.has_peer(self.bruce_doc.get_pseudo()), False)