Ejemplo n.º 1
0
    def case1():
        """
        original head - bad
        original get - not reached
        common head - bad
        common get - not reached
        """
        responses.reset()
        responses.add(
            **{
                'method': responses.GET,
                'url': get_metadata_url(ugoira_id),
                'body': meta_body,
                'content_type': 'application/json',
                'status': 200,
                'match_querystring': True,
            })
        responses.add(**{
            'method': responses.HEAD,
            'url': big_zip_url,
            'status': 503,
        })
        responses.add(**{
            'method': responses.HEAD,
            'url': small_zip_url,
            'status': 503,
        })

        runner = CliRunner()
        result = runner.invoke(ugoira, [str(ugoira_id)])
        assert result.output.strip().startswith(
            'Downloading {} (0/1)\nError: '.format(ugoira_id))
Ejemplo n.º 2
0
    def case2():
        """
        original head - good
        original get - bad
        common head - bad
        common get - not reached
        """
        responses.reset()
        responses.add(
            **{
                'method': responses.GET,
                'url': get_metadata_url(ugoira_id),
                'body': meta_body,
                'content_type': 'application/json',
                'status': 200,
                'match_querystring': True,
            })
        responses.add(**{
            'method': responses.HEAD,
            'url': big_zip_url,
            'status': 200,
        })
        responses.add(**{
            'method': responses.GET,
            'url': big_zip_url,
            'status': 403,
        })
        responses.add(**{
            'method': responses.HEAD,
            'url': small_zip_url,
            'status': 403,
        })

        with pytest.raises(PixivError):
            download_ugoira_zip(ugoira_id)
Ejemplo n.º 3
0
    def case1():
        """
        original head - good
        original get - good
        common head - not reached
        common get - not reached
        """
        responses.reset()
        responses.add(
            **{
                'method': responses.GET,
                'url': get_metadata_url(ugoira_id),
                'body': meta_body,
                'content_type': 'application/json',
                'status': 200,
                'match_querystring': True,
            })
        responses.add(**{
            'method': responses.HEAD,
            'url': big_zip_url,
            'status': 200,
        })
        responses.add(
            **{
                'method': responses.GET,
                'url': big_zip_url,
                'body': big_image_zip,
                'content_type': 'application/zip',
                'status': 200,
            })

        data, frames = download_ugoira_zip(ugoira_id)
        assert data == big_image_zip
Ejemplo n.º 4
0
    def case2():
        """
        original head - good
        original get - bad
        common head - good
        common get - good
        """
        responses.reset()
        responses.add(
            **{
                'method': responses.GET,
                'url': get_metadata_url(ugoira_id),
                'body': meta_body,
                'content_type': 'application/json',
                'status': 200,
                'match_querystring': True,
            })
        responses.add(**{
            'method': responses.HEAD,
            'url': big_zip_url,
            'status': 200,
        })
        responses.add(**{
            'method': responses.GET,
            'url': big_zip_url,
            'status': 403,
        })
        responses.add(**{
            'method': responses.HEAD,
            'url': small_zip_url,
            'status': 200,
        })
        responses.add(
            **{
                'method': responses.GET,
                'url': small_zip_url,
                'body': small_image_zip,
                'content_type': 'application/zip',
                'status': 200,
            })

        runner = CliRunner()
        result = runner.invoke(ugoira, [str(ugoira_id)])
        assert result.exit_code == 0
        assert result.output.strip() == (
            'Downloading {} (0/1)\n'.format(ugoira_id) +
            'Download was completed successfully.'
            ' format is {} and output path is {}{}'.format(
                'gif',
                ugoira_id,
                '.gif',
            ))
Ejemplo n.º 5
0
    def test():
        responses.reset()
        responses.add(
            **{
                'method': responses.GET,
                'url': get_metadata_url(ugoira_id),
                'body': error_meta_body,
                'content_type': 'application/json',
                'status': 200,
                'match_querystring': True,
            })

        with pytest.raises(PixivError):
            download_ugoira_zip(ugoira_id)
Ejemplo n.º 6
0
    def test():
        responses.reset()
        responses.add(
            **{
                'method': responses.GET,
                'url': get_metadata_url(non_ugoira_id),
                'body': error_meta_body,
                'content_type': 'application/json',
                'status': 200,
                'match_querystring': True,
            })

        runner = CliRunner()
        result = runner.invoke(ugoira, [str(non_ugoira_id)])
        assert result.output.strip() == (
            'Downloading {} (0/1)\n'.format(non_ugoira_id) +
            'Error: Illust ID {} is not ugoira.'.format(non_ugoira_id))