def test_delete__ok(self, client, podcast, user, mocked_s3, dbs): client.login(user) url = self.url.format(id=podcast.id) response = client.delete(url) assert response.status_code == 200 assert await_(Podcast.async_get(dbs, id=podcast.id)) is None mocked_s3.delete_files_async.assert_called_with( [f"{podcast.publish_id}.xml"], remote_path=settings.S3_BUCKET_RSS_PATH )
def test_generate__upload_failed__fail(self, podcast, mocked_s3, dbs): mocked_s3.upload_file.side_effect = lambda *_, **__: "" generate_rss_task = tasks.GenerateRSSTask(db_session=dbs) result_code = await_(generate_rss_task.run(podcast.id)) assert result_code == FinishCode.ERROR podcast_1 = await_(Podcast.async_get(dbs, id=podcast.id)) assert podcast_1.rss_link is None
def test_create__ok(self, client, user, podcast_data, dbs): podcast_data = { "name": podcast_data["name"], "description": podcast_data["description"], } client.login(user) response = client.post(self.url, json=podcast_data) response_data = self.assert_ok_response(response, status_code=201) podcast = await_(Podcast.async_get(dbs, id=response_data["id"])) assert podcast is not None assert response_data == _podcast(podcast)
def test_sign_up__ok(self, client, user_invite, dbs): request_data = self._sign_up_data(user_invite) response = client.post(self.url, json=request_data) response_data = self.assert_ok_response(response, status_code=201) user = await_(User.async_get(dbs, email=request_data["email"])) assert user is not None, f"User wasn't created with {request_data=}" assert_tokens(response_data, user) await_(dbs.refresh(user_invite)) assert user_invite.user_id == user.id assert user_invite.is_applied assert await_(Podcast.async_get(dbs, created_by_id=user.id)) is not None
def test_delete__episodes_deleted_too__ok(self, client, podcast, user, mocked_s3, dbs): episode_1 = await_(Episode.async_create(dbs, **get_episode_data(podcast))) episode_2 = await_(Episode.async_create(dbs, **get_episode_data(podcast, "published"))) await_(dbs.commit()) client.login(user) url = self.url.format(id=podcast.id) response = client.delete(url) assert response.status_code == 200 assert await_(Podcast.async_get(dbs, id=podcast.id)) is None assert await_(Episode.async_get(dbs, id=episode_1.id)) is None assert await_(Episode.async_get(dbs, id=episode_2.id)) is None mocked_s3.delete_files_async.assert_called_with([episode_2.file_name])
def test_generate__single_podcast__ok(self, user, mocked_s3, dbs): podcast_1: Podcast = await_( Podcast.async_create(dbs, **get_podcast_data())) podcast_2: Podcast = await_( Podcast.async_create(dbs, **get_podcast_data())) episode_data = get_episode_data(podcast_1, creator=user) episode_data["status"] = Episode.Status.NEW episode_new = await_(Episode.async_create(dbs, **episode_data)) episode_data = get_episode_data(podcast_1, creator=user) episode_data["status"] = Episode.Status.DOWNLOADING episode_downloading = await_(Episode.async_create(dbs, **episode_data)) episode_data = get_episode_data(podcast_1, creator=user) episode_data["status"] = Episode.Status.PUBLISHED episode_data["published_at"] = datetime.now() episode_published = await_(Episode.async_create(dbs, **episode_data)) episode_data = get_episode_data(podcast_2, creator=user) episode_data["status"] = Episode.Status.PUBLISHED episode_podcast_2 = await_(Episode.async_create(dbs, **episode_data)) await_(dbs.commit()) expected_file_path = mocked_s3.tmp_upload_dir / f"{podcast_1.publish_id}.xml" generate_rss_task = tasks.GenerateRSSTask(db_session=dbs) result_code = await_(generate_rss_task.run(podcast_1.id)) assert result_code == FinishCode.OK assert os.path.exists( expected_file_path), f"File {expected_file_path} didn't uploaded" with open(expected_file_path) as file: generated_rss_content = file.read() assert episode_published.title in generated_rss_content assert episode_published.description in generated_rss_content assert episode_published.file_name in generated_rss_content for episode in [episode_new, episode_downloading, episode_podcast_2]: assert episode.source_id not in generated_rss_content, f"{episode} in RSS {podcast_1}" podcast_1 = await_(Podcast.async_get(dbs, id=podcast_1.id)) assert podcast_1.rss_link == str(expected_file_path)