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 test_get_shared_files(self): document = CacheDocument() document.add_repository(TEST_DIR) document.expand_dir(abspath("data")) document.expand_dir(abspath(os.path.join("data", "subdir1"))) document.share_files(abspath("data"), [os.sep.join([TEST_DIR, "data", ".path"]), os.sep.join([TEST_DIR, "data", ".svn"]), os.sep.join([TEST_DIR, "data", "date.txt"]), os.sep.join([TEST_DIR, "data", "emptydir"]), os.sep.join([TEST_DIR, "data", "profiles"]), os.sep.join([TEST_DIR, "data", "subdir1", ".svn"]), os.sep.join([TEST_DIR, "data", "subdir1", "subsubdir"])], False) document.share_files(abspath("data"), [os.sep.join([TEST_DIR, "data"]), os.sep.join([TEST_DIR, "data", ".path"]), os.sep.join([TEST_DIR, "data", "date.txt"]), os.sep.join([TEST_DIR, "data", "routage"]), os.sep.join([TEST_DIR, "data", "subdir1"]), os.sep.join([TEST_DIR, "data", "subdir1", "TOtO.txt"]), os.sep.join([TEST_DIR, "data", "subdir1", "date.doc"])], True) shared_files = [file_container.get_path() for file_container in document.get_shared_files()[TEST_DIR]] shared_files.sort() self.assertEquals(shared_files, [os.sep.join([TEST_DIR, "data", ".path"]), os.sep.join([TEST_DIR, "data", "02_b_1280x1024.jpg"]), os.sep.join([TEST_DIR, "data", "Python-2.3.5.zip"]), os.sep.join([TEST_DIR, "data", "arc en ciel 6.gif"]), os.sep.join([TEST_DIR, "data", "date.txt"]), os.sep.join([TEST_DIR, "data", "pywin32-203.win32-py2.3.exe"]), os.sep.join([TEST_DIR, "data", "routage"]), os.sep.join([TEST_DIR, "data", "subdir1", "TOtO.txt"]), os.sep.join([TEST_DIR, "data", "subdir1", "date.doc"])])
def test_multiple_repos(self): """coherency when several repos in use""" document = CacheDocument() # create 2 repos document.add_repository(os.sep.join([TEST_DIR, "data", "profiles"])) tag_files(document, os.sep.join([TEST_DIR, "data", "profiles"]), ["bruce.prf", ".svn"], u"first") document.share_files(os.sep.join([TEST_DIR, "data", "profiles"]), ["bruce.prf", "demi.prf"], True) document.add_repository(os.sep.join([TEST_DIR, "data", "subdir1"])) tag_files(document, os.sep.join([TEST_DIR, "data", "subdir1"]), ["date.doc", ".svn"], u"second") document.share_files(os.sep.join([TEST_DIR, "data", "subdir1"]), ["date.doc", "subsubdir"], True) # check sharing state self.assertEquals(document.get_container( abspath(os.sep.join(["data", "profiles", "bruce.prf"])))._shared, True) self.assertEquals(document.get_container( abspath(os.sep.join(["data", "profiles", "demi.prf"])))._shared, True) self.assertEquals(document.get_container( abspath(os.sep.join(["data", "profiles", ".svn"])))._shared, False) self.assertEquals(document.get_container( abspath(os.sep.join(["data", "subdir1", "date.doc"])))._shared, True) self.assertEquals(document.get_container( abspath(os.sep.join(["data", "subdir1", "subsubdir"])))._shared, True) self.assertEquals(document.get_container( abspath(os.sep.join(["data", "subdir1", ".svn"])))._shared, False) # check tag self.assertRaises(ContainerException, document.add_repository, os.sep.join([TEST_DIR, "data", "subdir1", "subsubdir"])) self.assertRaises(ContainerException, document.add_repository, os.sep.join([TEST_DIR, "data"]))
def setUp(self): # filters self.peer_filter = PeerFilter("test peer", **{ "title": "Mr", "firstname": "Bob", "lastname": "b", "pseudo": "emb"}) self.file_filter = FileFilter("test file", **{ "name": "mp3"}) # properties doc = CacheDocument() doc.title = "Mr" doc.firstname = "Emmanuel" doc.lastname = "Breton" doc.pseudo = "emb" doc.photo = "none" doc.email = "*****@*****.**" doc.add_custom_attributes(u"book", u"Harry Potter") doc.add_custom_attributes(u"movie", u"Leon") doc.add_custom_attributes(u"sport", u"biking") self.peer_desc = PeerDescriptor("bob", document=doc) self.file_props = ToBeMatch(**{ "name": "Hero.mp3", "size": "3000"})