Exemple #1
0
def test_tag(api: Api, resp: RequestsMock) -> None:
    full_url = routes.tag(api.job_type, api.url)

    resp.add(
        responses.GET,
        url=full_url,
        json=[{
            "label": "My Tag",
            "id": 0
        }, {
            "label": "Other Tag",
            "id": 42
        }],
    )

    tags = api.tag()

    assert len(tags) == 2
    assert tags[0].id == 0

    resp.replace(responses.GET, url=full_url, json=[])

    tags = api.tag()

    assert len(tags) == 0
Exemple #2
0
def test_profile(api: Api, resp: RequestsMock) -> None:
    full_url = routes.profile(api.job_type, api.url)

    resp.add(
        responses.GET,
        url=full_url,
        json=[
            {
                "name": "HD-1080p",
                "id": 0,
                "cuttoff": 1
            },
            {
                "name": "4K",
                "id": 42
            },
        ],
    )

    profiles = api.profile()

    assert len(profiles) == 2
    assert profiles[0].id == 0

    resp.replace(responses.GET, url=full_url, json=[])

    profiles = api.profile()

    assert len(profiles) == 0
Exemple #3
0
def test_language(resp: RequestsMock) -> None:
    with Api(job_type=JobType.Lidarr, url="http://host/",
             api_key="aaa") as api:
        assert len(api.language()) == 0

    with Api(job_type=JobType.Radarr, url="http://host/",
             api_key="aaa") as api:
        assert len(api.language()) == 0

    with Api(job_type=JobType.Sonarr, url="http://host/",
             api_key="aaa") as api:

        full_url = routes.language(api.job_type, api.url)

        resp.add(
            responses.GET,
            url=full_url,
            json=[
                {
                    "name":
                    "English",
                    "id":
                    0,
                    "languages": [{
                        "allowed": True,
                        "language": {
                            "id": 0,
                            "name": "Unknown"
                        }
                    }],
                },
                {
                    "name": "Forign",
                    "id": 42
                },
            ],
        )

        languages = api.language()

        assert len(languages) == 2
        assert languages[1].id == 42
        assert not hasattr(languages[0], "languages")

        resp.replace(responses.GET, url=full_url, json=[])

        languages = api.language()

        assert len(languages) == 0
Exemple #4
0
def test_metadata_profile(resp: RequestsMock) -> None:
    with Api(job_type=JobType.Sonarr, url="http://host/",
             api_key="aaa") as api:
        assert len(api.metadata()) == 0

    with Api(job_type=JobType.Radarr, url="http://host/",
             api_key="aaa") as api:
        assert len(api.metadata()) == 0

    with Api(job_type=JobType.Lidarr, url="http://host/",
             api_key="aaa") as api:

        full_url = routes.metadata(api.job_type, api.url)

        resp.add(
            responses.GET,
            url=full_url,
            json=[
                {
                    "name":
                    "One",
                    "id":
                    0,
                    "releaseStatuses": [{
                        "allowed": True,
                        "releaseStatus": {
                            "id": 0,
                            "name": "Unknown"
                        }
                    }],
                },
                {
                    "name": "Two",
                    "id": 42
                },
            ],
        )

        metadata = api.metadata()

        assert len(metadata) == 2
        assert metadata[1].id == 42
        assert not hasattr(metadata[0], "releaseStatuses")

        resp.replace(responses.GET, url=full_url, json=[])

        metadata = api.metadata()

        assert len(metadata) == 0
Exemple #5
0
def test_status(api: Api, resp: RequestsMock) -> None:
    full_url = routes.status(api.job_type, api.url)

    resp.add(responses.GET,
             url=full_url,
             json={
                 "version": "3",
                 "ignore": True
             })

    status = api.status()

    assert status.version == "3"
    assert not hasattr(status, "ignore")

    resp.replace(responses.GET, url=full_url, json={})

    with pytest.raises(ValidationError):
        api.status()