Exemplo n.º 1
0
    def test_zip_files_successful(self):
        fake_zipfile_manager = StrictMock(zipfile.ZipFile,
                                          runtime_attrs=["write"],
                                          default_context_manager=True)
        fake_zipfile_manager.write = lambda x, arcname: True
        self.mock_callable(
            fake_zipfile_manager,
            'write').to_return_value(None).and_assert_called_exactly(4)
        self.mock_constructor(zipfile, "ZipFile").for_call(
            self.fake_download_path, 'w').to_return_value(fake_zipfile_manager)

        fake_zipfile_manager.__enter__ = lambda: fake_zipfile_manager

        scandir_iterator = StrictMock(FakeIterator,
                                      default_context_manager=True,
                                      runtime_attrs=["__iter__"])

        fake_song_path = pathlib.Path(
            str(self.fake_song_path).replace(".mp3", ""))
        scandir_iterator.__iter__ = self._fake_iter
        self.mock_callable(os, "scandir").for_call(
            fake_song_path).to_return_value(scandir_iterator)

        download_path = utils.zip_files(self.fake_model,
                                        self.fake_song_path.stem)

        # we want to know if we can resolve the same path we expect
        self.assertEqual(download_path.resolve(),
                         self.fake_download_path.resolve())
Exemplo n.º 2
0
    def test_zip_files_failure(self):
        fake_zipfile_manager = StrictMock(zipfile.ZipFile,
                                          runtime_attrs=["write"],
                                          default_context_manager=True)
        fake_zipfile_manager.write = lambda x, arcname: True
        self.mock_constructor(zipfile, "ZipFile").for_call(
            self.fake_download_path, 'w').to_return_value(fake_zipfile_manager)

        fake_zipfile_manager.__enter__ = lambda: fake_zipfile_manager

        scandir_iterator = StrictMock(FakeIterator,
                                      default_context_manager=True,
                                      runtime_attrs=["__iter__"])

        fake_song_path = pathlib.Path(
            str(self.fake_song_path).replace(".mp3", ""))
        scandir_iterator.__iter__ = self._fake_iter
        self.mock_callable(
            os, "scandir").for_call(fake_song_path).to_raise(FileNotFoundError)
        # we want to know if we can resolve the same path we expect
        self.assertIsNone(
            utils.zip_files(self.fake_model, self.fake_song_path.stem))