class MatchTest(unittest.TestCase):

    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_creation(self):
        match = PeerMatch(self.peer_desc, self.document)
        self.assertEquals(match.title.get_match(), "Mr")
        self.assertEquals(match.firstname, False)
        self.assertEquals(match.lastname.get_match(), "breton")
        self.assertEquals(match.photo, False)
        self.assertEquals(match.email, False)
        self.assertEquals(match.customs['color'].get_match(), u'blue')
        self.assertEquals(match.files, {})

    def test_activated(self):
        # activate
        self.document.get_email().activate()
        match = PeerMatch(self.peer_desc, self.document)
        self.assertEquals(match.email.get_match(), u'*****@*****.**')

    def test_files(self):
        # add filter for dummy.txt
        self.document.add_file((u'Any', FilterValue(value=u'.*\..*', activate=True)))
        match = PeerMatch(self.peer_desc, self.document)
        match_files = [file_container.match for file_container in match.files[u'Any']]
        self.assertEquals(match_files, ['TOtO.txt', 'dummy.txt'])
Пример #2
0
            peer_desc = PeerDescriptor(blog.pseudo, blog=blog)
            self.set_peer((peer_id, peer_desc))
        else:
            peer_desc = self.get_peer(peer_id)
        peer_desc.set_blog(blog)
        self.last_downloaded_desc = peer_desc
        return peer_desc
            
    def fill_shared_files(self, (peer_id, files)):
        """connect shared files with shared files"""
        if not isinstance(files, SharedFiles):
            raise TypeError("data expected as SharedFiles")
        assert self.has_peer(peer_id), "no profile for %s in %s"\
               % (peer_id, self.__class__)
        peer_desc = self.get_peer(peer_id)
        peer_desc.set_shared_files(files)
        self.last_downloaded_desc = peer_desc
        return peer_desc

class SaverMixin:
    """Take in charge saving & loading of document. Leave funciton
    import_document to be redefined."""

    def __init__(self, pseudo, directory):
        # point out file where document is saved
        self.pseudo = pseudo
        self._dir = directory

    def __repr__(self):
        return self.pseudo