def it_continues_if_symlink_creation_fails(system_mock: MagicMock, remote_dataset: RemoteDataset): stub_release_response = Release( "dataset-slug", "team-slug", "0.1.0", "release-name", "http://darwin-fake-url.com", datetime.now(), None, None, True, True, "json", ) def fake_download_zip(self, path): zip: Path = Path("tests/dataset.zip") shutil.copy(zip, path) return path latest: Path = remote_dataset.local_releases_path / "latest" with patch.object(Path, "symlink_to") as mock_symlink_to: with patch.object(RemoteDataset, "get_release", return_value=stub_release_response): with patch.object(Release, "download_zip", new=fake_download_zip): mock_symlink_to.side_effect = OSError() remote_dataset.pull() assert not latest.is_symlink()
def it_does_not_create_symlink_on_windows(mocker: MagicMock, remote_dataset: RemoteDataset): stub_release_response = Release( "dataset-slug", "team-slug", "0.1.0", "release-name", "http://darwin-fake-url.com", datetime.now(), None, None, True, True, "json", ) def fake_download_zip(self, path): zip: Path = Path("tests/dataset.zip") shutil.copy(zip, path) return path latest: Path = remote_dataset.local_releases_path / "latest" with patch.object(RemoteDataset, "get_release", return_value=stub_release_response): with patch.object(Release, "download_zip", new=fake_download_zip): remote_dataset.pull() assert not latest.is_symlink()
def it_gets_latest_release_when_not_given_one( system_mock: MagicMock, remote_dataset: RemoteDataset): stub_release_response = Release( "dataset-slug", "team-slug", "0.1.0", "release-name", "http://darwin-fake-url.com", datetime.now(), None, None, True, True, "json", ) def fake_download_zip(self, path): zip: Path = Path("tests/dataset.zip") shutil.copy(zip, path) return path with patch.object( RemoteDataset, "get_release", return_value=stub_release_response) as get_release_stub: with patch.object(Release, "download_zip", new=fake_download_zip): remote_dataset.pull() get_release_stub.assert_called_once()
def get_releases(self) -> List["Release"]: """ Get a sorted list of releases with the most recent first. Returns ------- List["Release"] Return a sorted list of available releases with the most recent first Raises ------ ConnectionError If it is unable to connect. """ try: releases_json: List[Dict[str, Any]] = self.client.get_exports( self.dataset_id, self.team) except NotFound: return [] releases = [ Release.parse_json(self.slug, self.team, payload) for payload in releases_json ] return sorted(filter(lambda x: x.available, releases), key=lambda x: x.version, reverse=True)
def get_releases(self): """Get a sorted list of releases with the most recent first Returns ------- list(Release) Return a sorted list of releases with the most recent first Raises ------ """ try: releases_json = self.client.get(f"/datasets/{self.dataset_id}/exports", team=self.team) except NotFound: return [] releases = [Release.parse_json(self.slug, self.team, payload) for payload in releases_json] return sorted(filter(lambda x: x.available, releases), key=lambda x: x.version, reverse=True)
def it_raises_if_release_format_is_not_json(system_mock: MagicMock, remote_dataset: RemoteDataset): a_release = Release( remote_dataset.slug, remote_dataset.team, "0.1.0", "release-name", "http://darwin-fake-url.com", datetime.now(), None, None, True, True, "xml", ) with pytest.raises(UnsupportedExportFormat): remote_dataset.pull(release=a_release)