Example #1
0
    def test_list_files_path_to_non_existing_file_in_zip_should_throw_NotFound(
            self):
        file_path = self.create_archive_file('zip')
        new_folder = os.path.join(file_path, "non_existing_file.txt")

        with self.assertRaises(NotFound):
            list_files(new_folder)
Example #2
0
    def test_list_files_path_to_file_in_zip(self, generate_file_response):
        file_path = self.create_archive_file('zip')
        sub_path_file = '0.txt'
        new_folder = os.path.join(file_path, sub_path_file)

        new_folder = normalize_path(new_folder)

        list_files(new_folder)

        generate_file_response.assert_called_once_with(mock.ANY,
                                                       'text/plain',
                                                       False,
                                                       name=sub_path_file)
Example #3
0
    def test_list_files_path_to_file_in_tar(self, generate_file_response):
        file_path = self.create_archive_file('tar')
        sub_path_file = './0.txt'  # TODO: bug in shutil for tar is adding an extra './'
        new_folder = os.path.join(file_path, sub_path_file)

        new_folder = normalize_path(new_folder)

        list_files(new_folder)

        generate_file_response.assert_called_once_with(mock.ANY,
                                                       'text/plain',
                                                       False,
                                                       name=sub_path_file)
Example #4
0
    def test_list_files_zip_file_with_default_args_should_return_response(
            self):
        file_path = self.create_archive_file('zip')
        resp = list_files(file_path)
        self.assertEqual(resp.status_code, 200)
        file_names = ["0.txt", "1.txt", "2.txt"]

        for el in resp.data:
            data_name = el['name']
            data_type = el['type']
            data_size = el['size']
            data_modified = el['modified']

            self.assertIn(data_name, file_names)
            file_names.remove(data_name)
            self.assertEqual(data_type, "file")
            self.assertEqual(data_size, 1)
            self.assertEqual(type(data_modified), datetime.datetime)
Example #5
0
    def test_list_files_tarfile_with_default_args_should_return_response(self):
        file_path = self.create_archive_file('tar')
        resp = list_files(file_path)
        self.assertEqual(resp.status_code, 200)
        file_names = ["./0.txt", "./1.txt", "./2.txt"
                      ]  # TODO: bug in shutil for tar is adding an extra './'

        for el in resp.data:
            data_name = el['name']
            data_type = el['type']
            data_size = el['size']
            data_modified = el['modified']

            self.assertIn(data_name, file_names)
            file_names.remove(data_name)
            self.assertEqual(data_type, "file")
            self.assertEqual(data_size, 1)
            self.assertEqual(type(data_modified), datetime.datetime)
Example #6
0
    def test_list_files_dir_with_default_args_should_raise_NotFound(self):
        path = self.datadir
        self.create_files()

        with self.assertRaises(NotFound):
            list_files(path)