Ejemplo n.º 1
0
def test_shares_scan():
    """ Test a full shares scan """

    config = Config("temp_config", DB_DIR)
    config.sections["transfers"]["shared"] = [("Shares", SHARES_DIR)]

    shares = Shares(None, config, queue.Queue(0))
    shares.rescan_shares()

    # Verify that modification time was saved for shares folder
    assert SHARES_DIR in list(config.sections["transfers"]["sharedmtimes"])

    # Verify that shared files were added
    assert ('dummy_file', 0, None, None) in list(config.sections["transfers"]["sharedfiles"].values())[0]
    assert ('nicotinetestdata.mp3', 80919, (128, 0), 5) in list(config.sections["transfers"]["sharedfiles"].values())[0]

    # Verify that search index was updated
    word_index = config.sections["transfers"]["wordindex"]
    nicotinetestdata_indexes = list(word_index["nicotinetestdata"])
    ogg_indexes = list(word_index["ogg"])

    assert set(word_index) == set(['nicotinetestdata', 'ogg', 'mp3', 'shares', 'file', 'dummy'])
    assert len(nicotinetestdata_indexes) == 2
    assert len(ogg_indexes) == 1

    # File ID associated with word "ogg" should return our nicotinetestdata.ogg file
    assert ogg_indexes[0] in nicotinetestdata_indexes
    assert config.sections["transfers"]["fileindex"][str(ogg_indexes[0])][0] == 'Shares\\nicotinetestdata.ogg'

    # Verify that dbs are cleared
    shares.clear_shares()
    assert len(list(config.sections["transfers"]["sharedfiles"])) == 0
Ejemplo n.º 2
0
def test_hidden_file_folder_scan():
    """ Test that hidden files and folders are excluded """

    config = Config("temp_config", DB_DIR)
    config.sections["transfers"]["shared"] = [("Shares", SHARES_DIR)]

    shares = Shares(None, config, queue.Queue(0))
    shares.rescan_shares()

    # Check folders
    mtimes = list(config.sections["transfers"]["sharedmtimes"])

    assert os.path.join(SHARES_DIR, ".abc") not in mtimes
    assert os.path.join(SHARES_DIR, ".xyz") not in mtimes
    assert os.path.join(SHARES_DIR, "folder1") in mtimes
    assert os.path.join(SHARES_DIR, "folder2") in mtimes
    assert os.path.join(SHARES_DIR, "folder2", ".poof") not in mtimes
    assert os.path.join(SHARES_DIR, "folder2", "test") in mtimes
    assert os.path.join(SHARES_DIR, "something") in mtimes

    # Check files
    files = config.sections["transfers"]["sharedfiles"]["Shares"]

    assert (".abc_file", 0, None, None) not in files
    assert (".hidden_file", 0, None, None) not in files
    assert (".xyz_file", 0, None, None) not in files
    assert ("dummy_file", 0, None, None) in files
    assert len(files) == 3
Ejemplo n.º 3
0
    def setUp(self):

        self.config = Config()
        self.config.data_dir = os.path.dirname(os.path.realpath(__file__))
        self.config.filename = os.path.join(self.config.data_dir, "temp_config")
        self.config.load_config()

        self.search = Search(None, self.config, deque(), None)
Ejemplo n.º 4
0
def test_shares_add_downloaded():
    """ Test that downloaded files are added to shared files """

    config = Config("temp_config", DB_DIR)
    config.sections["transfers"]["shared"] = [("Downloaded", SHARES_DIR)]
    config.sections["transfers"]["sharedownloaddir"] = True

    shares = Shares(None, config, queue.Queue(0), None)
    shares.add_file_to_shared(os.path.join(SHARES_DIR, 'nicotinetestdata.mp3'))

    assert ('nicotinetestdata.mp3', 80919, (128, 0), 5) in list(config.sections["transfers"]["sharedfiles"].values())[0]
    assert ('Downloaded\\nicotinetestdata.mp3', 80919, (128, 0), 5) in config.sections["transfers"]["fileindex"].values()
Ejemplo n.º 5
0
def config():
    config = Config()
    config.data_dir = os.path.dirname(os.path.realpath(__file__))
    config.filename = os.path.join(config.data_dir, "temp_config")

    config.load_config()
    return config
Ejemplo n.º 6
0
def test_shares_scan():
    """ Test a full shares scan """

    config = Config("temp_config", DB_DIR)
    config.sections["transfers"]["shared"] = [("Shares", SHARES_DIR)]

    shares = Shares(None, config, queue.Queue(0))
    shares.rescan_public_shares(thread=False)

    # Verify that modification time was saved for shares folder
    assert SHARES_DIR in list(shares.share_dbs["mtimes"])

    # Verify that shared files were added
    assert ('dummy_file', 0, None, None) in shares.share_dbs["files"]["Shares"]
    assert ('nicotinetestdata.mp3', 80919, (128, 0),
            5) in shares.share_dbs["files"]["Shares"]

    # Verify that expected folder is empty
    assert len(shares.share_dbs["files"]["Shares\\folder2"]) == 0

    # Verify that search index was updated
    word_index = shares.share_dbs["wordindex"]
    nicotinetestdata_indexes = list(word_index["nicotinetestdata"])
    ogg_indexes = list(word_index["ogg"])

    assert set(word_index) == set([
        'nicotinetestdata', 'ogg', 'mp3', 'shares', 'file', 'dummy', 'folder1',
        'folder2', 'nothing', 'something', 'test'
    ])
    assert len(nicotinetestdata_indexes) == 2
    assert len(ogg_indexes) == 1

    # File ID associated with word "ogg" should return our nicotinetestdata.ogg file
    assert ogg_indexes[0] in nicotinetestdata_indexes
    assert shares.share_dbs["fileindex"][str(
        ogg_indexes[0])][0] == 'Shares\\nicotinetestdata.ogg'

    shares.close_shares("normal")
Ejemplo n.º 7
0
class SearchTest(unittest.TestCase):

    def setUp(self):

        self.config = Config()
        self.config.data_dir = os.path.dirname(os.path.realpath(__file__))
        self.config.filename = os.path.join(self.config.data_dir, "temp_config")
        self.config.load_config()

        self.search = Search(None, self.config, deque(), None)

    def test_do_search(self):
        """ Test the do_search function, including the outgoing search term and search history """

        old_searchid = self.search.get_current_search_id()

        # Try a search with special characters removed

        self.config.sections["searches"]["remove_special_chars"] = True
        searchid, searchterm_with_excluded, searchterm_without_excluded = self.search.do_search(SEARCH_TEXT,
                                                                                                SEARCH_MODE)

        self.assertEqual(searchid, self.search.get_current_search_id())
        self.assertEqual(searchid, old_searchid + 1)
        self.assertEqual(searchterm_with_excluded, "70 gwen test a b c d auto yes -mp3 -nothanks -no")
        self.assertEqual(searchterm_without_excluded, "70 gwen test a b c d auto yes")
        self.assertEqual(self.config.sections["searches"]["history"][0], searchterm_with_excluded)

        # Try a search without special characters removed

        self.config.sections["searches"]["remove_special_chars"] = False
        searchid, searchterm_with_excluded, searchterm_without_excluded = self.search.do_search(SEARCH_TEXT,
                                                                                                SEARCH_MODE)

        self.assertEqual(searchterm_with_excluded, '70 gwen "test" a:b;c+d +++---}[ [[ @@ auto yes -mp3 -nothanks -no')
        self.assertEqual(searchterm_without_excluded, '70 gwen "test" a:b;c+d +++---}[ [[ @@ auto yes')
        self.assertEqual(self.config.sections["searches"]["history"][0], searchterm_with_excluded)
        self.assertEqual(self.config.sections["searches"]["history"][1],
                         "70 gwen test a b c d auto yes -mp3 -nothanks -no")

    def test_search_id_increment(self):
        """ Test that search ID increments work properly """

        old_searchid = self.search.get_current_search_id()

        searchid = self.search.increment_search_id()
        self.assertEqual(old_searchid, searchid - 1)
        self.assertEqual(searchid, self.search.get_current_search_id())

    def test_wishlist_add(self):
        """ Test that items are added to the wishlist properly """

        old_searchid = self.search.get_current_search_id()

        # First item

        searchid = self.search.add_wish(SEARCH_TEXT)
        self.assertEqual(self.config.sections["server"]["autosearch"][0], SEARCH_TEXT)
        self.assertEqual(searchid, old_searchid + 1)
        self.assertEqual(searchid, self.search.get_current_search_id())

        # Second item

        new_item = SEARCH_TEXT + "1"
        self.search.add_wish(new_item)
        self.assertEqual(self.config.sections["server"]["autosearch"][0], SEARCH_TEXT)
        self.assertEqual(self.config.sections["server"]["autosearch"][1], new_item)