Beispiel #1
0
    def test_get_new_files_success(self):
        """
        Test directory_source.get_new_files() success.
        """
        path = '/some/valid/path'
        file1_full_path = os.path.join(path, 'file1')
        file2_full_path = os.path.join(path, 'file2')
        file3_full_path = os.path.join(path, 'file3')

        os.listdir.expect_call(path).and_return(['file1', 'file2', 'file3'])

        stat_result = self._get_stat_result(size=1010, mtime=123)
        self._stat_mock.expect_call(file1_full_path).and_return(stat_result)

        stat_result = self._get_stat_result(size=1020, mtime=1234)
        self._stat_mock.expect_call(file2_full_path).and_return(stat_result)

        stat_result = self._get_stat_result(size=1030, mtime=12345)
        self._stat_mock.expect_call(file3_full_path).and_return(stat_result)

        known_files = {
                'file2': source.database.item(file2_full_path, 1020, 1234),
                }
        self.db_mock.get_dictionary.expect_call().and_return(known_files)

        s = source.directory_source(self.db_mock, path)
        expected = {
                'file1': source.database.item(file1_full_path, 1010, 123),
                'file3': source.database.item(file3_full_path, 1030, 12345),
                }
        self.assertEquals(expected, s.get_new_files(_stat_func=self._stat_mock))
        self.god.check_playback()
    def test_get_new_files_success(self):
        """
        Test directory_source.get_new_files() success.
        """
        path = '/some/valid/path'
        file1_full_path = os.path.join(path, 'file1')
        file2_full_path = os.path.join(path, 'file2')
        file3_full_path = os.path.join(path, 'file3')

        os.listdir.expect_call(path).and_return(['file1', 'file2', 'file3'])

        stat_result = self._get_stat_result(size=1010, mtime=123)
        self._stat_mock.expect_call(file1_full_path).and_return(stat_result)

        stat_result = self._get_stat_result(size=1020, mtime=1234)
        self._stat_mock.expect_call(file2_full_path).and_return(stat_result)

        stat_result = self._get_stat_result(size=1030, mtime=12345)
        self._stat_mock.expect_call(file3_full_path).and_return(stat_result)

        known_files = {
                'file2': source.database.item(file2_full_path, 1020, 1234),
                }
        self.db_mock.get_dictionary.expect_call().and_return(known_files)

        s = source.directory_source(self.db_mock, path)
        expected = {
                'file1': source.database.item(file1_full_path, 1010, 123),
                'file3': source.database.item(file3_full_path, 1030, 12345),
                }
        self.assertEquals(expected, s.get_new_files(_stat_func=self._stat_mock))
        self.god.check_playback()
Beispiel #3
0
    def test_get_new_files_invalid_path(self):
        """
        Test directory_source.get_new_files() on an invalid path.
        """
        path = '/some/invalid/path'
        os.listdir.expect_call(path).and_raises(OSError('Error'))

        s = source.directory_source(self.db_mock, path)
        self.assertRaises(OSError, s.get_new_files)
        self.god.check_playback()
    def test_get_new_files_invalid_path(self):
        """
        Test directory_source.get_new_files() on an invalid path.
        """
        path = '/some/invalid/path'
        os.listdir.expect_call(path).and_raises(OSError('Error'))

        s = source.directory_source(self.db_mock, path)
        self.assertRaises(OSError, s.get_new_files)
        self.god.check_playback()
Beispiel #5
0
    def test_get_new_files_stat_fails(self):
        """
        Test directory_source.get_new_files() when stat fails.
        """
        path = '/some/valid/path'
        os.listdir.expect_call(path).and_return(['file1', 'file2'])
        (self._stat_mock.expect_call(os.path.join(path, 'file1'))
                .and_raises(OSError('Error')))
        stat_result = self._get_stat_result(size=1010, mtime=123)
        file2_full_path = os.path.join(path, 'file2')
        self._stat_mock.expect_call(file2_full_path).and_return(stat_result)

        self.db_mock.get_dictionary.expect_call().and_return({})

        s = source.directory_source(self.db_mock, path)
        expected = {'file2': source.database.item(file2_full_path, 1010, 123)}
        self.assertEquals(expected, s.get_new_files(_stat_func=self._stat_mock))
        self.god.check_playback()
    def test_get_new_files_stat_fails(self):
        """
        Test directory_source.get_new_files() when stat fails.
        """
        path = '/some/valid/path'
        os.listdir.expect_call(path).and_return(['file1', 'file2'])
        (self._stat_mock.expect_call(os.path.join(path, 'file1'))
                .and_raises(OSError('Error')))
        stat_result = self._get_stat_result(size=1010, mtime=123)
        file2_full_path = os.path.join(path, 'file2')
        self._stat_mock.expect_call(file2_full_path).and_return(stat_result)

        self.db_mock.get_dictionary.expect_call().and_return({})

        s = source.directory_source(self.db_mock, path)
        expected = {'file2': source.database.item(file2_full_path, 1010, 123)}
        self.assertEquals(expected, s.get_new_files(_stat_func=self._stat_mock))
        self.god.check_playback()