[WIP] migrating tests
This commit is contained in:
parent
0579694203
commit
845910eaac
3 changed files with 80 additions and 42 deletions
|
|
@ -29,9 +29,9 @@ defmodule Pinchflat.Downloading.QualityOptionBuilder do
|
||||||
# TODO: test
|
# TODO: test
|
||||||
defp build_format_string(language_preference) do
|
defp build_format_string(language_preference) do
|
||||||
if language_preference do
|
if language_preference do
|
||||||
"bestvideo*+bestaudio[#{build_format_modifier(language_preference)}]/bestvideo*+bestaudio/best"
|
["bestvideo*+bestaudio[#{build_format_modifier(language_preference)}]/bestvideo*+bestaudio/best"]
|
||||||
else
|
else
|
||||||
"bestvideo*+bestaudio/best"
|
["bestvideo*+bestaudio/best"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -253,21 +253,14 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilderTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "build/1 when testing media quality and format options" do
|
describe "build/1 when testing media quality and format options" do
|
||||||
test "includes quality options" do
|
# There are more tests inside QualityOptionBuilderTest
|
||||||
resolutions = ["360", "480", "720", "1080", "2160", "4320"]
|
# This is essenitally just testing that we implement that module correctly
|
||||||
|
|
||||||
Enum.each(resolutions, fn resolution ->
|
test "includes video options for video profiles", %{media_item: media_item} do
|
||||||
resolution_atom = String.to_existing_atom(resolution <> "p")
|
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
||||||
|
|
||||||
media_profile = media_profile_fixture(%{preferred_resolution: resolution_atom})
|
assert {:format_sort, "res:1080,+codec:avc:m4a"} in res
|
||||||
source = source_fixture(%{media_profile_id: media_profile.id})
|
assert {:remux_video, "mp4"} in res
|
||||||
media_item = Repo.preload(media_item_fixture(source_id: source.id), source: :media_profile)
|
|
||||||
|
|
||||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
|
||||||
|
|
||||||
assert {:format_sort, "res:#{resolution},+codec:avc:m4a"} in res
|
|
||||||
assert {:remux_video, "mp4"} in res
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "includes quality options for audio only", %{media_item: media_item} do
|
test "includes quality options for audio only", %{media_item: media_item} do
|
||||||
|
|
@ -280,33 +273,6 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilderTest do
|
||||||
|
|
||||||
refute {:remux_video, "mp4"} in res
|
refute {:remux_video, "mp4"} in res
|
||||||
end
|
end
|
||||||
|
|
||||||
test "includes custom quality options if specified", %{media_item: media_item} do
|
|
||||||
Settings.set(video_codec_preference: "av01")
|
|
||||||
Settings.set(audio_codec_preference: "aac")
|
|
||||||
|
|
||||||
media_item = update_media_profile_attribute(media_item, %{preferred_resolution: :"1080p"})
|
|
||||||
|
|
||||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
|
||||||
|
|
||||||
assert {:format_sort, "res:1080,+codec:av01:aac"} in res
|
|
||||||
end
|
|
||||||
|
|
||||||
test "includes custom remux target for videos if specified", %{media_item: media_item} do
|
|
||||||
media_item = update_media_profile_attribute(media_item, %{media_container: "mkv"})
|
|
||||||
|
|
||||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
|
||||||
|
|
||||||
assert {:remux_video, "mkv"} in res
|
|
||||||
end
|
|
||||||
|
|
||||||
test "includes custom format target for audio if specified", %{media_item: media_item} do
|
|
||||||
media_item = update_media_profile_attribute(media_item, %{media_container: "flac", preferred_resolution: :audio})
|
|
||||||
|
|
||||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
|
||||||
|
|
||||||
assert {:audio_format, "flac"} in res
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "build/1 when testing sponsorblock options" do
|
describe "build/1 when testing sponsorblock options" do
|
||||||
|
|
|
||||||
72
test/pinchflat/downloading/quality_option_builder_test.exs
Normal file
72
test/pinchflat/downloading/quality_option_builder_test.exs
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
defmodule Pinchflat.Downloading.QualityOptionBuilderTest do
|
||||||
|
use Pinchflat.DataCase
|
||||||
|
import Pinchflat.ProfilesFixtures
|
||||||
|
|
||||||
|
alias Pinchflat.Profiles
|
||||||
|
alias Pinchflat.Settings
|
||||||
|
alias Pinchflat.Downloading.QualityOptionBuilder
|
||||||
|
|
||||||
|
# TODO: this basically tests the existing logic but doesn't test any of the new stuff. Add those tests.
|
||||||
|
describe "build/1 when testing audio profiles" do
|
||||||
|
setup do
|
||||||
|
{:ok, media_profile: media_profile_fixture(%{preferred_resolution: :audio})}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "includes quality options for audio only", %{media_profile: media_profile} do
|
||||||
|
assert res = QualityOptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
assert :extract_audio in res
|
||||||
|
assert {:format_sort, "+acodec:m4a"} in res
|
||||||
|
|
||||||
|
refute {:remux_video, "mp4"} in res
|
||||||
|
end
|
||||||
|
|
||||||
|
test "includes custom format target for audio if specified", %{media_profile: media_profile} do
|
||||||
|
{:ok, media_profile} =
|
||||||
|
Profiles.update_media_profile(media_profile, %{media_container: "flac", preferred_resolution: :audio})
|
||||||
|
|
||||||
|
assert res = QualityOptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
assert {:audio_format, "flac"} in res
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "build/1 when testing non-audio profiles" do
|
||||||
|
setup do
|
||||||
|
{:ok, media_profile: media_profile_fixture(%{preferred_resolution: :"480p"})}
|
||||||
|
end
|
||||||
|
|
||||||
|
test "includes quality options" do
|
||||||
|
resolutions = ["360", "480", "720", "1080", "2160", "4320"]
|
||||||
|
|
||||||
|
Enum.each(resolutions, fn resolution ->
|
||||||
|
resolution_atom = String.to_existing_atom(resolution <> "p")
|
||||||
|
media_profile = media_profile_fixture(%{preferred_resolution: resolution_atom})
|
||||||
|
|
||||||
|
assert res = QualityOptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
assert {:format_sort, "res:#{resolution},+codec:avc:m4a"} in res
|
||||||
|
assert {:remux_video, "mp4"} in res
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "includes custom quality options if specified", %{media_profile: media_profile} do
|
||||||
|
Settings.set(video_codec_preference: "av01")
|
||||||
|
Settings.set(audio_codec_preference: "aac")
|
||||||
|
|
||||||
|
{:ok, media_profile} = Profiles.update_media_profile(media_profile, %{preferred_resolution: :"1080p"})
|
||||||
|
|
||||||
|
assert res = QualityOptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
assert {:format_sort, "res:1080,+codec:av01:aac"} in res
|
||||||
|
end
|
||||||
|
|
||||||
|
test "includes custom remux target for videos if specified", %{media_profile: media_profile} do
|
||||||
|
{:ok, media_profile} = Profiles.update_media_profile(media_profile, %{media_container: "mkv"})
|
||||||
|
|
||||||
|
assert res = QualityOptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
assert {:remux_video, "mkv"} in res
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue