File: test_aiooncue.py

package info (click to toggle)
python-aiooncue 0.3.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 204 kB
  • sloc: python: 592; makefile: 79; sh: 2
file content (48 lines) | stat: -rw-r--r-- 1,446 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# pylint: disable=protected-access

"""Tests for `aiooncue` package."""

from unittest.mock import Mock, patch
import pytest

import aiohttp


from aiooncue import (
    LOGIN_INVALID_PASSWORD,
    LOGIN_INVALID_USERNAME,
    LoginFailedException,
    Oncue,
    ServiceFailedException,
)

@pytest.mark.asyncio
async def test_login():
    """Tests login"""

    # Successful Login
    api = Oncue("username", "password", Mock())
    with patch.object(api, "_get") as mock_get:
        mock_get.return_value = {"sessionkey": "123"}
        await api.async_login()
    assert api._sessionkey == "123"
    assert api._auth_invalid == 0

    # Relogin and return an invalid username, this should not make the auth_invalid
    with patch.object(api, "_get") as mock_get:
        mock_get.return_value = {"code": LOGIN_INVALID_USERNAME, "sessionkey": "321"}
        with pytest.raises(ServiceFailedException):
            await api.async_login()
    assert api._auth_invalid == 0

    # Relogin and return an invalid password, this should make the auth_invalid
    with patch.object(api, "_get") as mock_get:
        mock_get.return_value = {
            "code": LOGIN_INVALID_PASSWORD,
            "sessionkey": "321",
            "message": "bad username",
        }
        with pytest.raises(LoginFailedException):
            await api.async_login()
    assert api._auth_invalid == f"bad username ({LOGIN_INVALID_PASSWORD})"