Ejemplo n.º 1
0
    def test_add_three_files_in_folder(self):
        new_files = ['some_file_test2.txt', 'some_file2_test2.txt', 'some_file3_test2.txt']
        self.addFile(new_files)

        sleep(TEST_WAIT)
        self.first_receiver.tell.assert_called_with(local_files_message(AllItemsIn(new_files)))
        self.second_receiver.tell.assert_called_with(local_files_message(AllItemsIn(new_files)))
Ejemplo n.º 2
0
    def test_dont_report_removed_local_file(self):
        local_files = ["/lulu.txt", "/lala.txt"]
        self.filesDiff.tell(local_files_message(local_files))

        sleep(TEST_WAIT)
        self.filesDiff.tell(local_files_message(["/lulu.txt"]))
        self.filesDiff.tell(remote_files_message(TEST_REMOTE_IP, TEST_REMOTE_PORT, local_files))
        sleep(TEST_WAIT)
        self.receiver.tell.assert_not_called()
Ejemplo n.º 3
0
    def test_add_one_file_in_folder(self):
        self.first_receiver.assert_not_called()
        self.second_receiver.assert_not_called()

        new_file = ['some_file_test1.txt']
        self.addFile(new_file)
        sleep(TEST_WAIT)

        self.first_receiver.tell.assert_called_once_with(local_files_message(new_file))
        self.second_receiver.tell.assert_called_once_with(local_files_message(new_file))
Ejemplo n.º 4
0
    def test_call_all_receivers(self):
        first_receiver = MagicMock(spec=ActorRef)
        second_receiver = MagicMock(spec=ActorRef)
        self.lfs = LocalFiles.start([first_receiver, second_receiver],
                                    self.tmp_share_dir,
                                    TEST_RELOAD_LOCAL_FILES_SEC)

        new_files = ['/some_file_test1.txt']
        self.addFiles(new_files)
        sleep(TEST_WAIT)

        first_receiver.tell.assert_called_once_with(
            local_files_message(new_files))
        second_receiver.tell.assert_called_once_with(
            local_files_message(new_files))
Ejemplo n.º 5
0
    def test_report_files_in_subdirectory(self):
        os.makedirs(self.tmp_share_dir + "/sub_dir")
        new_files = ['/sub_dir/sub_file']
        self.addFiles(new_files)
        sleep(TEST_WAIT)

        self.receiver.tell.assert_called_once_with(
            local_files_message(new_files))
Ejemplo n.º 6
0
    def test_report_missing_file(self):
        files = ["lala.txt", "li_li.txt"]
        self.filesDiff.tell(local_files_message(["lulu.txt"]))
        self.filesDiff.tell(remote_files_message(TEST_REMOTE_IP, TEST_REMOTE_PORT, files))

        sleep(TEST_WAIT)
        self.receiver.tell.assert_any_call(missing_file_message(TEST_REMOTE_IP, TEST_REMOTE_PORT, files[0]))
        self.receiver.tell.assert_any_call(missing_file_message(TEST_REMOTE_IP, TEST_REMOTE_PORT, files[1]))
Ejemplo n.º 7
0
    def test_report_missing_file(self):
        files = ["/lala.txt", "/li_li.txt"]
        self.filesDiff.tell(local_files_message(["/lulu.txt"]))
        self.filesDiff.tell(remote_files_message(TEST_REMOTE_IP, TEST_REMOTE_PORT, files))

        sleep(TEST_WAIT)
        self.receiver.tell.assert_any_call(missing_file_message(TEST_REMOTE_IP, TEST_REMOTE_PORT, files[0]))
        self.receiver.tell.assert_any_call(missing_file_message(TEST_REMOTE_IP, TEST_REMOTE_PORT, files[1]))
Ejemplo n.º 8
0
    def test_broadcast_with_updated_files(self):
        files = ["/ann_file_1.txt", "/ann_file_2.txt"]
        self.announcer.tell(local_files_message(files))

        sleep(TEST_WAIT)
        received = self.mockedSocket.received_data()
        expected = broadcast_message(TEST_PORT, files)
        self.assertTrue(
            expected in received, "\n expected: [%s]"
            "\n received: [%s]" % (expected, received))
Ejemplo n.º 9
0
    def test_broadcast_with_updated_files(self):
        files = ["ann_file_1.txt", "ann_file_2.txt"]
        self.announcer.tell(local_files_message(files))

        sleep(TEST_WAIT)
        received = self.mockedSocket.received()
        expected = broadcast_message(TEST_PORT, files)
        self.assertTrue(expected in received,
                        "\n expected: [%s]"
                        "\n received: [%s]" % (expected, received))
Ejemplo n.º 10
0
    def test_add_files_in_folder(self):
        new_files = [
            '/some_file_test2.txt', '/some_file2_test2.txt',
            '/some_file3_test2.txt'
        ]
        self.addFiles(new_files)

        sleep(TEST_WAIT)
        self.receiver.tell.assert_called_with(
            local_files_message(AllItemsIn(new_files)))
Ejemplo n.º 11
0
 def check_file_updates(self):
     files = self.local_files()
     if cmp(files, self.cached_files):
         self.cached_files = files
         for recv in self.receiver:
             recv.tell(local_files_message(files))
Ejemplo n.º 12
0
 def check_file_updates(self):
     files = os.listdir(self.localDirectory)
     if cmp(files, self.localFiles):
         self.localFiles = files
         for recv in self.receiver:
             recv.tell(local_files_message(files))