From ee9a00b2f01f26b964827483404b69a25f9d7bf9 Mon Sep 17 00:00:00 2001 From: Vishnunarayan K I Date: Sat, 28 Sep 2019 19:06:29 +0530 Subject: [PATCH] docs: add docs for tests and mock --- docs/advanced/testing.rst | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 docs/advanced/testing.rst diff --git a/docs/advanced/testing.rst b/docs/advanced/testing.rst new file mode 100644 index 0000000..a41ace8 --- /dev/null +++ b/docs/advanced/testing.rst @@ -0,0 +1,59 @@ +Testing +******* + +We use pytest for testing. + +You can run specific tests by specifying the file.:: + + $ pytest tests/test_twistmoe.py + + +Mocks +***** + +The tool provides a framework for easy mocking of providers. +To use it, run the tool using the new provider. In this doc, we will use the example of twist.moe.:: + + $ anime -ll DEBUG dl 'shingeki no kyojin' --provider twist.moe --url -e 1 + .... + 2019-09-28 18:16:19 this anime_downloader.sites.helpers.request[521432] DEBUG HTML file temp_dir: /tmp/animedlszzxne7y + .... + + +In the above output, we can see the temp directory created by the tool. +Copy this temp directory to tests/test_sites and name it test_. + +After this you are ready to write the tests. The twist.moe test file is given below for reference. + +Remember to use the function :py:function:`configure_httpretty()` to configure the mock before making any requests. + +.. code:: python + + import pytest + + from anime_downloader.sites.twistmoe import TwistMoe + from test_sites.site import configure_httpretty + + + @pytest.fixture + def anime(): + return TwistMoe('https://twist.moe/a/shingeki-no-kyojin/first') + + configure_httpretty('twistmoe') + + def test_search(): + ret = TwistMoe.search('shingeki no kyojin') + assert len(ret) == 5 + assert ret[0].title == 'Shingeki no Kyojin' + + + def test_title(anime): + assert anime.title == 'shingeki-no-kyojin' + + + def test_length(anime): + assert len(anime) == 25 + + + def test_streamurl(anime): + assert anime[0].source().stream_url == 'https://eu1.twist.moe/anime/attackontitan/[Coalgirls]_Shingeki_no_Kyojin_01_(1920x1080_Blu-ray_FLAC)_[AEF12794].mp4'