Updated tests
This commit is contained in:
parent
cc6b91ba03
commit
e84b1dc66d
8 changed files with 26 additions and 26 deletions
|
|
@ -41,7 +41,7 @@ defmodule Pinchflat.Sources do
|
||||||
case source.cookie_behaviour do
|
case source.cookie_behaviour do
|
||||||
:disabled -> false
|
:disabled -> false
|
||||||
:all_operations -> true
|
:all_operations -> true
|
||||||
:indexing_only -> operation == :indexing
|
:when_needed -> operation == :indexing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,13 +86,13 @@
|
||||||
help="Unchecking still indexes media but it won't be downloaded until you enable this option"
|
help="Unchecking still indexes media but it won't be downloaded until you enable this option"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<.input
|
<.input
|
||||||
field={f[:cookie_behaviour]}
|
field={f[:cookie_behaviour]}
|
||||||
options={friendly_cookie_behaviours()}
|
options={friendly_cookie_behaviours()}
|
||||||
type="select"
|
type="select"
|
||||||
label="Cookie Behaviour"
|
label="Cookie Behaviour"
|
||||||
help="Uses your YouTube cookies for this source (if configured). 'When Needed' tries to minimize cookie usage except for certain indexing and downloading tasks. See docs"
|
help="Uses your YouTube cookies for this source (if configured). 'When Needed' tries to minimize cookie usage except for certain indexing and downloading tasks. See docs"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<section x-show="advancedMode">
|
<section x-show="advancedMode">
|
||||||
<.input
|
<.input
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ defmodule Pinchflat.Downloading.MediaDownloaderTest do
|
||||||
assert {:ok, _} = MediaDownloader.download_for_media_item(media_item)
|
assert {:ok, _} = MediaDownloader.download_for_media_item(media_item)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not set use_cookies if the source only uses cookies when indexing" do
|
test "does not set use_cookies if the source uses cookies when needed" do
|
||||||
expect(YtDlpRunnerMock, :run, 3, fn
|
expect(YtDlpRunnerMock, :run, 3, fn
|
||||||
_url, :get_downloadable_status, _opts, _ot, addl ->
|
_url, :get_downloadable_status, _opts, _ot, addl ->
|
||||||
assert {:use_cookies, false} in addl
|
assert {:use_cookies, false} in addl
|
||||||
|
|
@ -177,7 +177,7 @@ defmodule Pinchflat.Downloading.MediaDownloaderTest do
|
||||||
{:ok, ""}
|
{:ok, ""}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
source = source_fixture(%{cookie_behaviour: :indexing_only})
|
source = source_fixture(%{cookie_behaviour: :when_needed})
|
||||||
media_item = media_item_fixture(%{source_id: source.id})
|
media_item = media_item_fixture(%{source_id: source.id})
|
||||||
|
|
||||||
assert {:ok, _} = MediaDownloader.download_for_media_item(media_item)
|
assert {:ok, _} = MediaDownloader.download_for_media_item(media_item)
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ defmodule Pinchflat.FastIndexing.FastIndexingHelpersTest do
|
||||||
assert [%MediaItem{}] = FastIndexingHelpers.index_and_kickoff_downloads(source)
|
assert [%MediaItem{}] = FastIndexingHelpers.index_and_kickoff_downloads(source)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not set use_cookies if the source only uses cookies when indexing" do
|
test "does not set use_cookies if the source uses cookies when needed" do
|
||||||
expect(HTTPClientMock, :get, fn _url -> {:ok, "<yt:videoId>test_1</yt:videoId>"} end)
|
expect(HTTPClientMock, :get, fn _url -> {:ok, "<yt:videoId>test_1</yt:videoId>"} end)
|
||||||
|
|
||||||
stub(YtDlpRunnerMock, :run, fn _url, :get_media_attributes, _opts, _ot, addl ->
|
stub(YtDlpRunnerMock, :run, fn _url, :get_media_attributes, _opts, _ot, addl ->
|
||||||
|
|
@ -176,7 +176,7 @@ defmodule Pinchflat.FastIndexing.FastIndexingHelpersTest do
|
||||||
{:ok, media_attributes_return_fixture()}
|
{:ok, media_attributes_return_fixture()}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
source = source_fixture(%{cookie_behaviour: :indexing_only})
|
source = source_fixture(%{cookie_behaviour: :when_needed})
|
||||||
|
|
||||||
assert [%MediaItem{}] = FastIndexingHelpers.index_and_kickoff_downloads(source)
|
assert [%MediaItem{}] = FastIndexingHelpers.index_and_kickoff_downloads(source)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -110,13 +110,13 @@ defmodule Pinchflat.Metadata.MetadataFileHelpersTest do
|
||||||
Helpers.download_and_store_thumbnail_for(media_item)
|
Helpers.download_and_store_thumbnail_for(media_item)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not set use_cookies if the source only uses cookies when indexing" do
|
test "does not set use_cookies if the source uses cookies when needed" do
|
||||||
expect(YtDlpRunnerMock, :run, fn _url, :download_thumbnail, _opts, _ot, addl ->
|
expect(YtDlpRunnerMock, :run, fn _url, :download_thumbnail, _opts, _ot, addl ->
|
||||||
assert {:use_cookies, false} in addl
|
assert {:use_cookies, false} in addl
|
||||||
{:ok, ""}
|
{:ok, ""}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
source = source_fixture(%{cookie_behaviour: :indexing_only})
|
source = source_fixture(%{cookie_behaviour: :when_needed})
|
||||||
media_item = Repo.preload(media_item_fixture(%{source_id: source.id}), :source)
|
media_item = Repo.preload(media_item_fixture(%{source_id: source.id}), :source)
|
||||||
|
|
||||||
Helpers.download_and_store_thumbnail_for(media_item)
|
Helpers.download_and_store_thumbnail_for(media_item)
|
||||||
|
|
|
||||||
|
|
@ -259,7 +259,7 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not set use_cookies if the source only uses cookies when indexing" do
|
test "does not set use_cookies if the source uses cookies when needed" do
|
||||||
expect(YtDlpRunnerMock, :run, 2, fn
|
expect(YtDlpRunnerMock, :run, 2, fn
|
||||||
_url, :get_source_details, _opts, _ot, _addl ->
|
_url, :get_source_details, _opts, _ot, _addl ->
|
||||||
{:ok, source_details_return_fixture()}
|
{:ok, source_details_return_fixture()}
|
||||||
|
|
@ -270,7 +270,7 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||||
end)
|
end)
|
||||||
|
|
||||||
profile = media_profile_fixture(%{download_source_images: true})
|
profile = media_profile_fixture(%{download_source_images: true})
|
||||||
source = source_fixture(media_profile_id: profile.id, cookie_behaviour: :indexing_only)
|
source = source_fixture(media_profile_id: profile.id, cookie_behaviour: :when_needed)
|
||||||
|
|
||||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||||
end
|
end
|
||||||
|
|
@ -343,7 +343,7 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not set use_cookies if the source only uses cookies when indexing" do
|
test "does not set use_cookies if the source uses cookies when needed" do
|
||||||
expect(YtDlpRunnerMock, :run, 2, fn
|
expect(YtDlpRunnerMock, :run, 2, fn
|
||||||
_url, :get_source_details, _opts, _ot, addl ->
|
_url, :get_source_details, _opts, _ot, addl ->
|
||||||
assert {:use_cookies, false} in addl
|
assert {:use_cookies, false} in addl
|
||||||
|
|
@ -353,7 +353,7 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||||
{:ok, "{}"}
|
{:ok, "{}"}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
source = source_fixture(%{series_directory: nil, cookie_behaviour: :indexing_only})
|
source = source_fixture(%{series_directory: nil, cookie_behaviour: :when_needed})
|
||||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -316,13 +316,13 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do
|
||||||
SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source)
|
SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "sets use_cookies if the source only uses cookies when indexing" do
|
test "sets use_cookies if the source uses cookies when needed" do
|
||||||
expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, addl_opts ->
|
expect(YtDlpRunnerMock, :run, fn _url, :get_media_attributes_for_collection, _opts, _ot, addl_opts ->
|
||||||
assert {:use_cookies, true} in addl_opts
|
assert {:use_cookies, true} in addl_opts
|
||||||
{:ok, source_attributes_return_fixture()}
|
{:ok, source_attributes_return_fixture()}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
source = source_fixture(%{cookie_behaviour: :indexing_only})
|
source = source_fixture(%{cookie_behaviour: :when_needed})
|
||||||
|
|
||||||
SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source)
|
SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -71,13 +71,13 @@ defmodule Pinchflat.SourcesTest do
|
||||||
refute Sources.use_cookies?(source, :downloading)
|
refute Sources.use_cookies?(source, :downloading)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns true if the action is indexing and the source is set to :indexing_only" do
|
test "returns true if the action is indexing and the source is set to :when_needed" do
|
||||||
source = source_fixture(%{cookie_behaviour: :indexing_only})
|
source = source_fixture(%{cookie_behaviour: :when_needed})
|
||||||
assert Sources.use_cookies?(source, :indexing)
|
assert Sources.use_cookies?(source, :indexing)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "returns false if the action is downloading and the source is set to :indexing_only" do
|
test "returns false if the action is downloading and the source is set to :when_needed" do
|
||||||
source = source_fixture(%{cookie_behaviour: :indexing_only})
|
source = source_fixture(%{cookie_behaviour: :when_needed})
|
||||||
refute Sources.use_cookies?(source, :downloading)
|
refute Sources.use_cookies?(source, :downloading)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -421,7 +421,7 @@ defmodule Pinchflat.SourcesTest do
|
||||||
assert {:ok, %Source{}} = Sources.create_source(valid_attrs)
|
assert {:ok, %Source{}} = Sources.create_source(valid_attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "does not set use_cookies if the source only uses cookies when indexing" do
|
test "does not set use_cookies if the source uses cookies when needed" do
|
||||||
expect(YtDlpRunnerMock, :run, fn _url, :get_source_details, _opts, _ot, addl ->
|
expect(YtDlpRunnerMock, :run, fn _url, :get_source_details, _opts, _ot, addl ->
|
||||||
refute Keyword.get(addl, :use_cookies)
|
refute Keyword.get(addl, :use_cookies)
|
||||||
|
|
||||||
|
|
@ -431,7 +431,7 @@ defmodule Pinchflat.SourcesTest do
|
||||||
valid_attrs = %{
|
valid_attrs = %{
|
||||||
media_profile_id: media_profile_fixture().id,
|
media_profile_id: media_profile_fixture().id,
|
||||||
original_url: "https://www.youtube.com/channel/abc123",
|
original_url: "https://www.youtube.com/channel/abc123",
|
||||||
cookie_behaviour: :indexing_only
|
cookie_behaviour: :when_needed
|
||||||
}
|
}
|
||||||
|
|
||||||
assert {:ok, %Source{}} = Sources.create_source(valid_attrs)
|
assert {:ok, %Source{}} = Sources.create_source(valid_attrs)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue