def setUp(self): """override one in unittest.TestCase""" self.documents = [CacheDocument(), FileDocument()] for document in self.documents: document.add_repository(REPO) self.abstract_doc = AbstractDocument() self.abstract_doc.add_repository(REPO)
def setUp(self): """override one in unittest.TestCase""" self.documents = [CacheDocument(PROFILE_TEST, PROFILE_DIRECTORY), FileDocument(PROFILE_TEST, PROFILE_DIRECTORY)] for document in self.documents: document.add_file(REPO) self.abstract_doc = AbstractDocument(PROFILE_TEST, PROFILE_DIRECTORY) self.abstract_doc.add_file(REPO)
def setUp(self): """override one in unittest.TestCase""" write_test_profile() self.documents = [CacheDocument(), FileDocument()] for document in self.documents: document.add_repository(TEST_DIR) self.abstract_doc = AbstractDocument() self.abstract_doc.add_repository(TEST_DIR)
class DocumentTest(unittest.TestCase): """test that all fields are correctly validated""" def setUp(self): """override one in unittest.TestCase""" self.documents = [CacheDocument(), FileDocument()] for document in self.documents: document.add_repository(REPO) self.abstract_doc = AbstractDocument() self.abstract_doc.add_repository(REPO) def test_config_parser(self): writer = CustomConfigParser() writer.add_section('TEST') writer.set('TEST', "Windows:path", "not a valid linux:path!") writer.write(open("generated/config.test", "w")) # standard reader reader = ConfigParser() reader.readfp(open("generated/config.test")) self.assert_(reader.has_section('TEST')) self.assert_(reader.has_option('TEST', "Windows")) self.assertEquals(reader.get('TEST', "Windows"), "path = not a valid linux:path!") # custom reader reader = CustomConfigParser() reader.readfp(open("generated/config.test")) self.assert_(reader.has_section('TEST')) self.assert_(reader.has_option('TEST', "Windows:path")) self.assertEquals(reader.get('TEST', "Windows:path"), "not a valid linux:path!") # PERSONAL TAB def test_title(self): """title as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_title) for document in self.documents: self.assertRaises(TypeError, document.set_title, "Mr") self.assertRaises(TypeError, document.set_title, [u"Mr", ]) document.set_title(u"Mr") def test_firstname(self): """firstname as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_firstname) for document in self.documents: self.assertRaises(TypeError, document.set_firstname, "manu") self.assertRaises(TypeError, document.set_firstname, [u"manu", ]) document.set_firstname(u"manu") def test_lastname(self): """lastname as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_lastname) for document in self.documents: self.assertRaises(TypeError, document.set_lastname, "breton") self.assertRaises(TypeError, document.set_lastname, [u"breton", ]) document.set_lastname(u"breton") def test_pseudo(self): """pseudo as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_pseudo) for document in self.documents: self.assertRaises(TypeError, document.set_pseudo, "emb") self.assertRaises(TypeError, document.set_pseudo, [u"manu", u"emb"]) document.set_pseudo(u"emb") def test_photo(self): """photo as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_photo) for document in self.documents: self.assertRaises(TypeError, document.set_photo, "./dummy/dummy.jpg") document.set_photo(unicode(unittest.__file__, ENCODING)) def test_email(self): """email as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_email) for document in self.documents: self.assertRaises(TypeError, document.set_email, "*****@*****.**") self.assertRaises(TypeError, document.set_email, [u"manu@ft", ]) document.set_email(u"*****@*****.**") def test_birthday(self): """birthday as datetime""" self.assertRaises(NotImplementedError, self.abstract_doc.get_birthday) for document in self.documents: document.set_birthday(u"12/01/2005") birthday = document.get_birthday() document.set_birthday("12 jan 2005") self.assertEquals(document.get_birthday(), birthday) document.set_birthday("2005/01/12") self.assertEquals(document.get_birthday(), birthday) document.set_birthday("12-01-2005") self.assertEquals(document.get_birthday(), birthday) document.set_birthday("12012005") self.assertEquals(document.get_birthday(), birthday) document.set_birthday("12/01") self.assertEquals(document.get_birthday(), birthday) def test_language(self): """language as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_language) for document in self.documents: self.assertRaises(TypeError, document.set_language, "fr") self.assertRaises(TypeError, document.set_language, [u"fr", u"sp"]) document.set_language(u"fr") def test_address(self): """address as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_address) for document in self.documents: self.assertRaises(TypeError, document.set_address, "12 rue V Hugo") self.assertRaises(TypeError, document.set_address, [u"12", u"rue V Hugo"]) document.set_address(u"12 rue V Hugo") def test_postcode(self): """postcode as int convertable""" self.assertRaises(NotImplementedError, self.abstract_doc.get_postcode) for document in self.documents: self.assertRaises(TypeError, document.set_postcode, "34.000") self.assertRaises(TypeError, document.set_postcode, "34 000") self.assertRaises(TypeError, document.set_postcode, "Herault") self.assertRaises(TypeError, document.set_birthday, ["34", ]) document.set_postcode(u"34000") document.set_postcode("34000") def test_city(self): """city as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_city) for document in self.documents: self.assertRaises(TypeError, document.set_city, "Paris") self.assertRaises(TypeError, document.set_city, [u"Paris", ]) document.set_city(u"Paris") def test_country(self): """country as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_country) for document in self.documents: self.assertRaises(TypeError, document.set_country, "France") self.assertRaises(TypeError, document.set_country, [u"France", ]) document.set_country(u"France") def test_description(self): """description as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_description) for document in self.documents: self.assertRaises(TypeError, document.set_description, "anything") self.assertRaises(TypeError, document.set_description, [u"anything", ]) document.set_description(u"anything") def test_download_repo(self): """download_repo as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_download_repo) for document in self.documents: self.assertRaises(TypeError, document.set_download_repo, "anything") self.assertRaises(TypeError, document.set_download_repo, [u"anything", ]) document.set_description(u"anything") # CUSTOM TAB def test_hobbies(self): """hobbies as unicode (multiple lines)""" self.assertRaises(NotImplementedError, self.abstract_doc.get_hobbies) for document in self.documents: self.assertRaises(TypeError, document.set_hobbies, "blabla\nbla bla bla\n") self.assertRaises(TypeError, document.set_hobbies, u"blabla\nbla bla bla\n") document.set_hobbies([u"blabla", u"bla bla bla", u""]) def test_custom_attributes(self): """custom_attributes as pair of key/unicode-value""" self.assertRaises(NotImplementedError, self.abstract_doc.get_custom_attributes) for document in self.documents: self.assertRaises(TypeError, document.add_custom_attributes, "homepage: manu.com") self.assertRaises(TypeError, document.add_custom_attributes, ("homepage", "manu.com", "yo")) self.assertRaises(TypeError, document.add_custom_attributes, ("homepage", "manu.com")) document.add_custom_attributes((u"homepage", u"manu.com")) self.assertRaises(TypeError, document.remove_custom_attributes, "homepage") document.remove_custom_attributes(u"homepage") # FILE TAB def test_reset_files(self): """reset files""" for document in self.documents: document.add((abspath(u"data"))) document.share_file((abspath(u"data"), True)) self.assertEquals(document.get_container(abspath(u"data"))._shared, True) document.reset_files() self.assertEquals(document.get_files(), {}) def test_repository(self): """repository valid path""" for document in self.documents: self.assertRaises(TypeError, document.add, abspath("data/dummy")) document.add(abspath(u"data")) document.remove(abspath(u"data")) def test_share_dir(self): """share dir giving unicode name""" for document in self.documents: document.add((abspath(u"data"))) self.assertRaises(TypeError, document.share_dirs, "data, True") self.assertRaises(TypeError, document.share_dirs, ("data", )) self.assertRaises(TypeError, document.share_dirs, ("data", True)) self.assertRaises(TypeError, document.share_dirs, (abspath(u"data"), True)) document.share_dirs(([abspath(u"data")], True)) document.share_dirs([[abspath(u"data")], True]) def test_share_files(self): """share files giving root & unicode names""" for document in self.documents: document.add((abspath(u"data"))) self.assertRaises(TypeError, document.share_files, "data, ['.path', 'routage'], True") self.assertRaises(TypeError, document.share_files, ("data", "['.path', 'routage'], True")) self.assertRaises(TypeError, document.share_files, ("data", "['.path', 'routage']", "True")) self.assertRaises(TypeError, document.share_files, (u"data", "['.path', 'routage']", True)) self.assertRaises(TypeError, document.share_files, ("data", ['.path', 'routage'], True)) document.share_files((abspath(u"data"), ['.path', 'routage'], True)) document.share_files([abspath(u"data"), ['.path', 'routage'], True]) def test_tag_file(self): """tag files giving root & unicode names""" for document in self.documents: document.add((abspath(u"data"))) self.assertRaises(TypeError, document.tag_files, "data, ['.path', 'routage'], tag desc") self.assertRaises(TypeError, document.tag_files, ("data", "['.path', 'routage'], tag desc")) self.assertRaises(TypeError, document.tag_files, ("data", "['.path', 'routage']", "tag desc")) self.assertRaises(TypeError, document.tag_files, ("data", ['.path', 'routage'], "tag desc")) self.assertRaises(TypeError, document.tag_files, (u"data", "['.path', 'routage']", "tag desc")) self.assertRaises(TypeError, document.tag_files, (u"data", ['.path', 'routage'], "tag desc")) document.tag_files((abspath(u"data"), ['.path', 'routage'], u"tag desc")) document.tag_files([abspath(u"data"), ['.path', 'routage'], u"tag desc"]) def test_add_file(self): """expand dir giving unicode name""" self.assertRaises(NotImplementedError, self.abstract_doc.get_files) for document in self.documents: document.add((abspath(u"data"))) self.assertRaises(TypeError, document.expand_dir, "data/dummy") self.assertRaises(TypeError, document.expand_dir, "data") document.expand_dir((abspath(u"data"))) def test_get_container(self): """retreive correct contaier""" for document in self.documents: document.tag_files((abspath(u"data/profiles"), ["bruce.prf", ".svn"], u"first")) document.share_files((abspath(u"data/profiles"), ["bruce.prf", "demi.prf"], True)) # check sharing state self.assertEquals(document.get_container( abspath(u"data/profiles/bruce.prf"))._shared, True) self.assertEquals(document.get_container( abspath(u"data/profiles/demi.prf"))._shared, True) self.assertEquals(document.get_container( abspath(u"data/profiles/.svn"))._shared, False) # check tag self.assertEquals(document.get_container( abspath(u"data/profiles/bruce.prf"))._tag, u"first") self.assertEquals(document.get_container( abspath(u"data/profiles/demi.prf"))._tag, DEFAULT_TAG) self.assertEquals(document.get_container( abspath(u"data/profiles/.svn"))._tag, u"first") 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_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") # OTHERS TAB def test_reset_peers(self): """reset peers""" self.assertRaises(NotImplementedError, self.abstract_doc.get_peers) self.assertRaises(NotImplementedError, self.abstract_doc.reset_peers) document = self.documents[0] document.add_peer(u"nico") self.assertEquals(document.has_peer(u"nico"), True) document.reset_peers() self.assertEquals(document.has_peer(u"nico"), False) self.assertEquals(document.get_peers(), {}) def test_adding_peer(self): self.assertRaises(NotImplementedError, self.abstract_doc.add_peer, "nico") """add peer""" document = self.documents[0] self.assertEquals(document.has_peer(u"nico"), False) document.add_peer(u"nico") self.assert_(document.has_peer(u"nico")) def test_getting_peer(self): """get peer""" self.assertRaises(NotImplementedError, self.abstract_doc.get_peer, "nico") for document in self.documents: document.add_peer(u"nico") peer_desc = document.get_peer(u"nico") self.assertEquals(peer_desc.peer_id, u"nico") def test_removing_peer(self): """remove peer""" self.assertRaises(NotImplementedError, self.abstract_doc.remove_peer, "nico") document = self.documents[0] document.add_peer(u"nico") self.assertEquals(document.has_peer(u"nico"), True) document.remove_peer(u"nico") self.assertEquals(document.has_peer(u"nico"), False) def test_filling_data(self): """fill data""" for document in self.documents: self.assertRaises(TypeError, document.fill_data, (u"pseudo", u"tag description")) self.assertEquals(document.has_peer(u"emb"), False) file_doc = FileDocument() file_doc.load(TEST_PROFILE) document.fill_data((u"emb", file_doc)) def test_peers_status(self): """change status""" document = self.documents[0] # friend document.make_friend(u"nico") self.assertEquals(PeerDescriptor.FRIEND, document.get_peer(u"nico").state) # blacklist document.blacklist_peer(u"nico") self.assertEquals(PeerDescriptor.BLACKLISTED, document.get_peer(u"nico").state) # anonmyous document.unmark_peer(u"nico") self.assertEquals(PeerDescriptor.ANONYMOUS, document.get_peer(u"nico").state)
class DocumentTest(unittest.TestCase): """test that all fields are correctly validated""" def setUp(self): """override one in unittest.TestCase""" self.documents = [CacheDocument(PROFILE_TEST, PROFILE_DIRECTORY), FileDocument(PROFILE_TEST, PROFILE_DIRECTORY)] for document in self.documents: document.add_file(REPO) self.abstract_doc = AbstractDocument(PROFILE_TEST, PROFILE_DIRECTORY) self.abstract_doc.add_file(REPO) def test_config_parser(self): writer = CustomConfigParser(ENCODING) writer.add_section('TEST') writer.set('TEST', "Windows:path", "not a valid linux:path!") writer.write(open("generated/config.test", "w")) # standard reader reader = ConfigParser() reader.readfp(open("generated/config.test")) self.assert_(reader.has_section('TEST')) self.assert_(reader.has_option('TEST', "Windows")) self.assertEquals(reader.get('TEST', "Windows"), "path = not a valid linux:path!") # custom reader reader = CustomConfigParser(ENCODING) reader.readfp(open("generated/config.test")) self.assert_(reader.has_section('TEST')) self.assert_(reader.has_option('TEST', "Windows:path")) self.assertEquals(reader.get('TEST', "Windows:path"), "not a valid linux:path!") # PERSONAL TAB def test_title(self): """title as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_title) for document in self.documents: self.assertRaises(TypeError, document.set_title, "Mr") self.assertRaises(TypeError, document.set_title, [u"Mr", ]) document.set_title(u"Mr") def test_firstname(self): """firstname as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_firstname) for document in self.documents: self.assertRaises(TypeError, document.set_firstname, "manu") self.assertRaises(TypeError, document.set_firstname, [u"manu", ]) document.set_firstname(u"manu") def test_lastname(self): """lastname as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_lastname) for document in self.documents: self.assertRaises(TypeError, document.set_lastname, "breton") self.assertRaises(TypeError, document.set_lastname, [u"breton", ]) document.set_lastname(u"breton") def test_photo(self): """photo as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_photo) for document in self.documents: self.assertRaises(TypeError, document.set_photo, "./dummy/dummy.jpg") document.set_photo(unicode(unittest.__file__, ENCODING)) def test_email(self): """email as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_email) for document in self.documents: self.assertRaises(TypeError, document.set_email, "*****@*****.**") self.assertRaises(TypeError, document.set_email, [u"manu@ft", ]) document.set_email(u"*****@*****.**") # CUSTOM TAB def test_custom_attributes(self): """custom_attributes as pair of key/unicode-value""" self.assertRaises(NotImplementedError, self.abstract_doc.get_custom_attributes) for document in self.documents: self.assertRaises(TypeError, document.add_custom_attributes, "homepage: manu.com") self.assertRaises(TypeError, document.add_custom_attributes, ("homepage", "manu.com", "yo")) self.assertRaises(TypeError, document.add_custom_attributes, ("homepage", "manu.com")) document.add_custom_attributes((u"homepage", u"manu.com")) self.assertRaises(TypeError, document.remove_custom_attributes, "homepage") document.remove_custom_attributes(u"homepage") # FILE TAB def test_reset_files(self): """reset files""" for document in self.documents: document.add((abspath("data"))) document.share_file((abspath("data"), True)) self.assertEquals(document.get_container(abspath("data"))._shared, True) document.reset_files() self.assertEquals(document.get_files(), {}) def test_repository(self): """repository valid path""" for document in self.documents: self.assertRaises(TypeError, document.add, abspath(u"data/dummy")) document.add(abspath("data")) document.remove(abspath("data")) def test_recursive_share(self): """share dir giving unicode name""" for document in self.documents: document.add((abspath("data"))) self.assertRaises(KeyError, document.recursive_share, ("data", True)) self.assertRaises(TypeError, document.recursive_share, (abspath(u"data"), True)) document.recursive_share((abspath("data"), True)) def test_share_files(self): """share files giving root & unicode names""" for document in self.documents: document.add((abspath("data"))) self.assertRaises(TypeError, document.share_files, "data, ['.path', 'routage'], True") self.assertRaises(TypeError, document.share_files, ("data", "['.path', 'routage'], True")) self.assertRaises(TypeError, document.share_files, ("data", "['.path', 'routage']", "True")) self.assertRaises(TypeError, document.share_files, ("data", "['.path', 'routage']", True)) document.share_files((abspath("data"), ['.path', 'routage'], True)) document.share_files([abspath("data"), ['.path', 'routage'], True]) def test_tag_file(self): """tag files giving root & unicode names""" for document in self.documents: document.add((abspath("data"))) self.assertRaises(TypeError, document.tag_files, "data, ['.path', 'routage'], tag desc") self.assertRaises(TypeError, document.tag_files, ("data", "['.path', 'routage'], tag desc")) self.assertRaises(TypeError, document.tag_files, ("data", "['.path', 'routage']", "tag desc")) self.assertRaises(TypeError, document.tag_files, ("data", ['.path', 'routage'], "tag desc")) self.assertRaises(TypeError, document.tag_files, ("data", "['.path', 'routage']", "tag desc")) self.assertRaises(TypeError, document.tag_files, ("data", ['.path', 'routage'], "tag desc")) document.tag_files((abspath("data"), ['.path', 'routage'], u"tag desc")) document.tag_files([abspath("data"), ['.path', 'routage'], u"tag desc"]) def test_add_file(self): """expand dir giving unicode name""" self.assertRaises(NotImplementedError, self.abstract_doc.get_files) for document in self.documents: document.add((abspath("data"))) self.assertRaises(TypeError, document.expand_dir, u"data/dummy") self.assertRaises(TypeError, document.expand_dir, u"data") document.expand_dir((abspath("data"))) def test_get_container(self): for document in self.documents: document.tag_files((abspath("data/profiles"), ["bruce.prf", ".svn"], u"first")) document.share_files((abspath("data/profiles"), ["bruce.prf", "demi.prf"], False)) # check sharing state self.assertEquals(document.get_container( abspath("data/profiles/bruce.prf"))._shared, False) self.assertEquals(document.get_container( abspath("data/profiles/demi.prf"))._shared, False) self.assertEquals(document.get_container( abspath("data/profiles/.svn"))._shared, True) # check tag self.assertEquals(document.get_container( abspath("data/profiles/bruce.prf"))._tag, u"first") self.assertEquals(document.get_container( abspath("data/profiles/demi.prf"))._tag, DEFAULT_TAG) self.assertEquals(document.get_container( abspath("data/profiles/.svn"))._tag, u"first") def test_get_shared_files(self): document = CacheDocument(PROFILE_TEST, PROFILE_DIRECTORY) document.add_file(REPO) document.expand_dir(abspath("data")) document.expand_dir(abspath("data/subdir1")) document.share_files((abspath("data"), [REPO + '/data/.path', REPO + '/data/.svn', REPO + '/data/date.txt', REPO + '/data/emptydir', REPO + '/data/profiles', REPO + '/data/subdir1/.svn', REPO + '/data/subdir1/subsubdir'], False)) document.share_files((abspath("data"), [REPO + '/data', REPO + "/data/.path", REPO + "/data/date.txt", REPO + "/data/routage", REPO + '/data/subdir1', REPO + "/data/subdir1/TOtO.txt", REPO + "/data/subdir1/date.doc"], True)) shared_files = [file_container.get_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/routage", REPO + "/data/subdir1/TOtO.txt", REPO + "/data/subdir1/date.doc"]) def test_multiple_repos(self): """coherency when several repos in use""" document = CacheDocument(PROFILE_TEST, PROFILE_DIRECTORY) # create 2 repos document.add_file(REPO + "/data/profiles") document.tag_files((REPO + "/data/profiles", ["bruce.prf", ".svn"], u"first")) document.share_files((REPO + "/data/profiles", ["bruce.prf", "demi.prf"], False)) document.add_file(REPO + "/data/subdir1") document.tag_files((REPO + "/data/subdir1", ["date.doc", ".svn"], u"second")) document.share_files((REPO + "/data/subdir1", ["date.doc", "subsubdir"], False)) # check sharing state self.assertEquals(document.get_container( abspath("data/profiles/bruce.prf"))._shared, False) self.assertEquals(document.get_container( abspath("data/profiles/demi.prf"))._shared, False) self.assertEquals(document.get_container( abspath("data/profiles/.svn"))._shared, True) self.assertEquals(document.get_container( abspath("data/subdir1/date.doc"))._shared, False) self.assertEquals(document.get_container( abspath("data/subdir1/subsubdir"))._shared, False) self.assertEquals(document.get_container( abspath("data/subdir1/.svn"))._shared, True) # check tag self.assertRaises(ValueError, document.add_file, REPO + "/data/subdir1/subsubdir") self.assertRaises(ValueError, document.add_file, REPO + "/data") # OTHERS TAB def test_reset_peers(self): """reset peers""" self.assertRaises(NotImplementedError, self.abstract_doc.get_peers) self.assertRaises(NotImplementedError, self.abstract_doc.reset_peers) document = self.documents[0] document.set_peer((u"nico", PeerDescriptor(PSEUDO))) self.assertEquals(document.has_peer(u"nico"), True) document.reset_peers() self.assertEquals(document.has_peer(u"nico"), False) self.assertEquals(document.get_peers(), {}) def test_getting_peer(self): """get peer""" self.assertRaises(NotImplementedError, self.abstract_doc.get_peer, "nico") for document in self.documents: document.set_peer((u"nico", PeerDescriptor(PSEUDO))) peer_desc = self.documents[0].get_peer(u"nico") self.assertEquals(peer_desc.pseudo, PSEUDO) def test_removing_peer(self): """remove peer""" self.assertRaises(NotImplementedError, self.abstract_doc.remove_peer, "nico") for document in self.documents: document.set_peer((u"nico", PeerDescriptor(PSEUDO))) self.assertEquals(document.has_peer(u"nico"), True) document.remove_peer(u"nico") self.assertEquals(document.has_peer(u"nico"), False) 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 test_peers_status(self): """change status""" for document in self.documents: self.assertRaises(AssertionError, document.make_friend, u"nico") self.assertRaises(AssertionError, document.blacklist_peer, u"nico") self.assertRaises(AssertionError, document.unmark_peer, u"nico") document.set_peer((u"nico", PeerDescriptor(PROFILE_TEST))) # friend document.make_friend(u"nico") self.assertEquals(PeerDescriptor.FRIEND, document.get_peer(u"nico").state) # blacklist document.blacklist_peer(u"nico") self.assertEquals(PeerDescriptor.BLACKLISTED, document.get_peer(u"nico").state) # anonmyous document.unmark_peer(u"nico") self.assertEquals(PeerDescriptor.ANONYMOUS, document.get_peer(u"nico").state)
class DocumentTest(unittest.TestCase): """test that all fields are correctly validated""" def setUp(self): """override one in unittest.TestCase""" self.documents = [CacheDocument(), FileDocument()] for document in self.documents: document.add_repository(REPO) self.abstract_doc = AbstractDocument() self.abstract_doc.add_repository(REPO) # PERSONAL TAB def test_title(self): """title as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_title) for document in self.documents: self.assertRaises(TypeError, document.set_title, "Mr") self.assertRaises(TypeError, document.set_title, [u"Mr", ]) document.set_title(u"Mr") def test_firstname(self): """firstname as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_firstname) for document in self.documents: self.assertRaises(TypeError, document.set_firstname, "manu") self.assertRaises(TypeError, document.set_firstname, [u"manu", ]) document.set_firstname(u"manu") def test_lastname(self): """lastname as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_lastname) for document in self.documents: self.assertRaises(TypeError, document.set_lastname, "breton") self.assertRaises(TypeError, document.set_lastname, [u"breton", ]) document.set_lastname(u"breton") def test_pseudo(self): """pseudo as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_pseudo) for document in self.documents: self.assertRaises(TypeError, document.set_pseudo, "emb") self.assertRaises(TypeError, document.set_pseudo, [u"manu", u"emb"]) document.set_pseudo(u"emb") def test_photo(self): """photo as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_photo) for document in self.documents: self.assertRaises(TypeError, document.set_photo, "./dummy/dummy.jpg") document.set_photo(unittest.__file__) def test_email(self): """email as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_email) for document in self.documents: self.assertRaises(TypeError, document.set_email, "*****@*****.**") self.assertRaises(TypeError, document.set_email, [u"manu@ft", ]) document.set_email(u"*****@*****.**") def test_birthday(self): """birthday as DateTime convertable""" self.assertRaises(NotImplementedError, self.abstract_doc.get_birthday) for document in self.documents: self.assertRaises(TypeError, document.set_birthday, "12 jan 2005") self.assertRaises(TypeError, document.set_birthday, "2005/01/12") self.assertRaises(TypeError, document.set_birthday, "12-01-2005") self.assertRaises(TypeError, document.set_birthday, "12012005") self.assertRaises(TypeError, document.set_birthday, "12/01") self.assertRaises(TypeError, document.set_birthday, ["12/01/05", ]) document.set_birthday(u"12/01/2005") document.set_birthday("12/01/2005") def test_language(self): """language as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_language) for document in self.documents: self.assertRaises(TypeError, document.set_language, "fr") self.assertRaises(TypeError, document.set_language, [u"fr", u"sp"]) document.set_language(u"fr") def test_address(self): """address as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_address) for document in self.documents: self.assertRaises(TypeError, document.set_address, "12 rue V Hugo") self.assertRaises(TypeError, document.set_address, [u"12", u"rue V Hugo"]) document.set_address(u"12 rue V Hugo") def test_postcode(self): """postcode as int convertable""" self.assertRaises(NotImplementedError, self.abstract_doc.get_postcode) for document in self.documents: self.assertRaises(TypeError, document.set_postcode, "34.000") self.assertRaises(TypeError, document.set_postcode, "34 000") self.assertRaises(TypeError, document.set_postcode, "Herault") self.assertRaises(TypeError, document.set_birthday, ["34", ]) document.set_postcode(u"34000") document.set_postcode("34000") def test_city(self): """city as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_city) for document in self.documents: self.assertRaises(TypeError, document.set_city, "Paris") self.assertRaises(TypeError, document.set_city, [u"Paris", ]) document.set_city(u"Paris") def test_country(self): """country as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_country) for document in self.documents: self.assertRaises(TypeError, document.set_country, "France") self.assertRaises(TypeError, document.set_country, [u"France", ]) document.set_country(u"France") def test_description(self): """description as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_description) for document in self.documents: self.assertRaises(TypeError, document.set_description, "anything") self.assertRaises(TypeError, document.set_description, [u"anything", ]) document.set_description(u"anything") # CUSTOM TAB def test_hobbies(self): """hobbies as unicode (multiple lines)""" self.assertRaises(NotImplementedError, self.abstract_doc.get_hobbies) for document in self.documents: self.assertRaises(TypeError, document.set_hobbies, "blabla\nbla bla bla\n") self.assertRaises(TypeError, document.set_hobbies, u"blabla\nbla bla bla\n") document.set_hobbies([u"blabla", u"bla bla bla", u""]) def test_custom_attributes(self): """custom_attributes as pair of key/unicode-value""" self.assertRaises(NotImplementedError, self.abstract_doc.get_custom_attributes) for document in self.documents: self.assertRaises(TypeError, document.add_custom_attributes, "homepage: manu.com") self.assertRaises(TypeError, document.add_custom_attributes, ("homepage", "manu.com", "yo")) self.assertRaises(TypeError, document.add_custom_attributes, ("homepage", "manu.com")) document.add_custom_attributes((u"homepage", u"manu.com")) self.assertRaises(TypeError, document.remove_custom_attributes, "homepage") document.remove_custom_attributes(u"homepage") # FILE TAB def test_reset_files(self): """reset files""" for document in self.documents: document.add((abspath(u"data"))) document.share_file((abspath(u"data"), True)) self.assertEquals(document.get_container(abspath(u"data"))._shared, True) document.reset_files() self.assertEquals(document.get_files(), {}) def test_repository(self): """repository valid path""" for document in self.documents: self.assertRaises(TypeError, document.add, abspath("data/dummy")) document.add(abspath(u"data")) document.remove(abspath(u"data")) def test_share_dir(self): """share dir giving unicode name""" for document in self.documents: document.add((abspath(u"data"))) self.assertRaises(TypeError, document.share_dirs, "data, True") self.assertRaises(TypeError, document.share_dirs, ("data", )) self.assertRaises(TypeError, document.share_dirs, ("data", True)) self.assertRaises(TypeError, document.share_dirs, (abspath(u"data"), True)) document.share_dirs(([abspath(u"data")], True)) document.share_dirs([[abspath(u"data")], True]) def test_share_files(self): """share files giving root & unicode names""" for document in self.documents: document.add((abspath(u"data"))) self.assertRaises(TypeError, document.share_files, "data, ['.path', 'routage'], True") self.assertRaises(TypeError, document.share_files, ("data", "['.path', 'routage'], True")) self.assertRaises(TypeError, document.share_files, ("data", "['.path', 'routage']", "True")) self.assertRaises(TypeError, document.share_files, (u"data", "['.path', 'routage']", True)) self.assertRaises(TypeError, document.share_files, ("data", ['.path', 'routage'], True)) document.share_files((abspath(u"data"), ['.path', 'routage'], True)) document.share_files([abspath(u"data"), ['.path', 'routage'], True]) def test_tag_file(self): """tag files giving root & unicode names""" for document in self.documents: document.add((abspath(u"data"))) self.assertRaises(TypeError, document.tag_files, "data, ['.path', 'routage'], tag desc") self.assertRaises(TypeError, document.tag_files, ("data", "['.path', 'routage'], tag desc")) self.assertRaises(TypeError, document.tag_files, ("data", "['.path', 'routage']", "tag desc")) self.assertRaises(TypeError, document.tag_files, ("data", ['.path', 'routage'], "tag desc")) self.assertRaises(TypeError, document.tag_files, (u"data", "['.path', 'routage']", "tag desc")) self.assertRaises(TypeError, document.tag_files, (u"data", ['.path', 'routage'], "tag desc")) document.tag_files((abspath(u"data"), ['.path', 'routage'], u"tag desc")) document.tag_files([abspath(u"data"), ['.path', 'routage'], u"tag desc"]) def test_add_file(self): """expand dir giving unicode name""" self.assertRaises(NotImplementedError, self.abstract_doc.get_files) for document in self.documents: document.add((abspath(u"data"))) self.assertRaises(TypeError, document.expand_dir, "data/dummy") self.assertRaises(TypeError, document.expand_dir, "data") document.expand_dir((abspath(u"data"))) def test_get_container(self): """retreive correct contaier""" for document in self.documents: document.tag_files((abspath(u"data/profiles"), ["bruce.prf", ".svn"], u"first")) document.share_files((abspath(u"data/profiles"), ["bruce.prf", "demi.prf"], True)) # check sharing state self.assertEquals(document.get_container( abspath(u"data/profiles/bruce.prf"))._shared, True) self.assertEquals(document.get_container( abspath(u"data/profiles/demi.prf"))._shared, True) self.assertEquals(document.get_container( abspath(u"data/profiles/.svn"))._shared, False) # check tag self.assertEquals(document.get_container( abspath(u"data/profiles/bruce.prf"))._tag, u"first") self.assertEquals(document.get_container( abspath(u"data/profiles/demi.prf"))._tag, DEFAULT_TAG) self.assertEquals(document.get_container( abspath(u"data/profiles/.svn"))._tag, u"first") 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") # OTHERS TAB def test_reset_peers(self): """reset files""" for document in self.documents: document.add_peer(u"nico") self.assert_(document.get_peers().has_key(u"nico")) document.reset_peers() self.assertEquals(document.get_peers(), {}) def test_adding_peer(self): self.assertRaises(NotImplementedError, self.abstract_doc.get_peers) """pseudo as unicode""" for document in self.documents: self.assertRaises(TypeError, document.add_peer, "nico") self.assertRaises(TypeError, document.add_peer, [u"nico", ]) document.add_peer(u"nico") def test_removing_peer(self): """pseudo as unicode""" for document in self.documents: self.assertRaises(TypeError, document.remove_peer, "nico") self.assertRaises(TypeError, document.remove_peer, [u"nico", ]) document.remove_peer(u"nico") def test_filling_data(self): """data as (pseudo, document)""" for document in self.documents: self.assertRaises(TypeError, document.fill_data, "pseudo: doc") self.assertRaises(TypeError, document.fill_data, ("pseudo", )) self.assertRaises(TypeError, document.fill_data, ("pseudo", "doc")) self.assertRaises(TypeError, document.fill_data, (u"pseudo", u"tag description")) self.assertRaises(TypeError, document.fill_data, ("pseudo", AbstractDocument())) document.fill_data((u"emb", AbstractDocument())) document.fill_data((u"emb", FileDocument())) document.fill_data((u"emb", CacheDocument())) def test_peers_status(self): """action changes to accurate state""" for document in self.documents: # friend self.assertRaises(TypeError, document.make_friend, "pseudo") document.make_friend(u"nico") self.assertEquals(PeerDescriptor.FRIEND, document.get_peers()[u"nico"][0].state) # blacklist self.assertRaises(TypeError, document.blacklist_peer, "pseudo") document.blacklist_peer(u"nico") self.assertEquals(PeerDescriptor.BLACKLISTED, document.get_peers()[u"nico"][0].state) # anonmyous self.assertRaises(TypeError, document.unmark_peer, "pseudo") document.unmark_peer(u"nico") self.assertEquals(PeerDescriptor.ANONYMOUS, document.get_peers()[u"nico"][0].state)
class DocumentTest(unittest.TestCase): """test that all fields are correctly validated""" def setUp(self): """override one in unittest.TestCase""" write_test_profile() self.documents = [CacheDocument(), FileDocument()] for document in self.documents: document.add_repository(TEST_DIR) self.abstract_doc = AbstractDocument() self.abstract_doc.add_repository(TEST_DIR) def test_config_parser(self): writer = CustomConfigParser(ENCODING) writer.add_section("TEST") writer.set("TEST", "Windows:path", "not a valid linux:path!") writer.write(open(os.path.join("generated", "config.test"), "w")) # standard reader reader = ConfigParser() reader.readfp(open(os.path.join("generated", "config.test"))) self.assert_(reader.has_section("TEST")) self.assert_(reader.has_option("TEST", "Windows")) self.assertEquals(reader.get("TEST", "Windows"), "path = not a valid linux:path!") # custom reader reader = CustomConfigParser(ENCODING) reader.readfp(open(os.path.join("generated", "config.test"))) self.assert_(reader.has_section("TEST")) self.assert_(reader.has_option("TEST", "Windows:path")) self.assertEquals(reader.get("TEST", "Windows:path"), "not a valid linux:path!") # PERSONAL TAB def test_pseudo(self): """pseudo as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_pseudo) for document in self.documents: self.assertRaises(TypeError, document.set_pseudo, "atao") self.assertRaises(TypeError, document.set_pseudo, [u"atao", ]) document.set_pseudo(u"atao") def test_title(self): """title as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_title) for document in self.documents: self.assertRaises(TypeError, document.set_title, "Mr") self.assertRaises(TypeError, document.set_title, [u"Mr", ]) document.set_title(u"Mr") def test_firstname(self): """firstname as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_firstname) for document in self.documents: self.assertRaises(TypeError, document.set_firstname, "manu") self.assertRaises(TypeError, document.set_firstname, [u"manu", ]) document.set_firstname(u"manu") def test_lastname(self): """lastname as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_lastname) for document in self.documents: self.assertRaises(TypeError, document.set_lastname, "breton") self.assertRaises(TypeError, document.set_lastname, [u"breton", ]) document.set_lastname(u"breton") def test_photo(self): """photo as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_photo) for document in self.documents: self.assertRaises(TypeError, document.set_photo, "./dummy/dummy.jpg") document.set_photo(force_unicode(unittest.__file__)) def test_email(self): """email as unicode""" self.assertRaises(NotImplementedError, self.abstract_doc.get_email) for document in self.documents: self.assertRaises(TypeError, document.set_email, "*****@*****.**") self.assertRaises(TypeError, document.set_email, [u"manu@ft", ]) document.set_email(u"*****@*****.**") # CUSTOM TAB def test_custom_attributes(self): """custom_attributes as pair of key", "unicode-value""" self.assertRaises(NotImplementedError, self.abstract_doc.get_custom_attributes) for document in self.documents: self.assertRaises(TypeError, document.add_custom_attributes, "homepage", "manu.com") document.add_custom_attributes(u"homepage", u"manu.com") self.assertRaises(TypeError, document.remove_custom_attributes, "homepage") document.remove_custom_attributes(u"homepage") # FILE TAB def test_reset_files(self): """reset files""" for document in self.documents: document.share_file(abspath("data"), True) self.assertEquals(document.get_container(abspath("data"))._shared, True) document.reset_files() self.assertEquals(document.get_files(), {}) def test_recursive_share(self): """share dir giving unicode name""" for document in self.documents: self.assertRaises(TypeError, document.recursive_share, abspath(u"data"), True) self.assertEquals(1, len(document.recursive_share("data", True))) self.assertEquals([], document.recursive_share(abspath("data"), True)) def test_share_files(self): """share files giving root & unicode names""" for document in self.documents: document.share_files(abspath("data"), [".path", "routage"], True) def test_set_container(self): path = os.path.join(abspath("data"), "date.txt") container = FileContainer(path, share=True, tag=u"Shared by set_container") for document in self.documents: self.assertEquals(document.get_container(path)._shared, False) self.assertEquals(document.get_container(path)._tag, DEFAULT_TAG) document.set_container(container) self.assertEquals(document.get_container(path)._shared, True) self.assertEquals(document.get_container(path)._tag, u"Shared by set_container") def test_add_repository(self): """expand dir giving unicode name""" for document in self.documents: self.assertRaises(TypeError, document.expand_dir, os.path.join(u"data", "dummy")) self.assertRaises(TypeError, document.expand_dir, u"data") document.expand_dir(abspath("data")) def test_get_container(self): for document in self.documents: tag_files(document, abspath(os.path.join("data", "profiles")), ["bruce.prf", ".svn"], u"first") document.share_files(abspath(os.path.join("data", "profiles")), ["bruce.prf", "demi.prf"], 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) # check tag self.assertEquals(document.get_container( abspath(os.sep.join(["data", "profiles", "bruce.prf"])))._tag, u"first") self.assertEquals(document.get_container( abspath(os.sep.join(["data", "profiles", "demi.prf"])))._tag, DEFAULT_TAG) self.assertEquals(document.get_container( abspath(os.sep.join(["data", "profiles", ".svn"])))._tag, u"first") 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"])) # OTHERS TAB def test_reset_peers(self): """reset peers""" document = self.documents[0] document.set_peer(u"nico", PeerDescriptor(PROFILE_TEST)) self.assertEquals(document.has_peer(u"nico"), True) document.reset_peers() self.assertEquals(document.has_peer(u"nico"), False) self.assertEquals(document.get_peers(), {}) def test_getting_peer(self): """get peer""" for document in self.documents: document.set_peer(PROFILE_BRUCE, PeerDescriptor(PROFILE_BRUCE)) peer_desc = self.documents[0].get_peer(PROFILE_BRUCE) self.assertEquals(peer_desc.node_id, PROFILE_BRUCE) def test_removing_peer(self): """remove peer""" for document in self.documents: document.set_peer(u"nico", PeerDescriptor(PROFILE_TEST)) self.assertEquals(document.has_peer(u"nico"), True) document.remove_peer(u"nico") self.assertEquals(document.has_peer(u"nico"), False) def test_filling(self): """fill data""" for document in self.documents: self.assertEquals(document.has_peer(u"emb"), False) bruce = get_bruce_profile() document.fill_data(u"emb", bruce.document) document.fill_blog(u"emb", bruce.blog) def test_peers_status(self): """change status""" bruce = get_bruce_profile() for document in self.documents: self.assertRaises(AssertionError, document.make_friend, bruce.node_id) self.assertRaises(AssertionError, document.blacklist_peer, bruce.node_id) self.assertRaises(AssertionError, document.unmark_peer, bruce.node_id) document.set_peer(bruce.node_id, bruce) # friend document.make_friend(bruce.node_id) self.assertEquals(PeerDescriptor.FRIEND, document.get_peer(bruce.node_id).state) # blacklist document.blacklist_peer(bruce.node_id) self.assertEquals(PeerDescriptor.BLACKLISTED, document.get_peer(bruce.node_id).state) # anonmyous document.unmark_peer(bruce.node_id) self.assertEquals(PeerDescriptor.ANONYMOUS, document.get_peer(bruce.node_id).state)