def test_session_set_attribute(): m = mock.Mock() s = Session(m) download_dir = "download - dir" s.download_dir = download_dir assert s.download_dir == download_dir m.set_session.assert_called_once_with(download_dir=download_dir)
def __init__(self, *, protocol: str = 'http', username: str = None, password: str = None, host: str = '127.0.0.1', port: int = 9091, path: str = '/transmission/', timeout: Union[int, float] = DEFAULT_TIMEOUT, logger=LOGGER): if isinstance(logger, logging.Logger): self.logger = logger else: raise TypeError('logger must be instance of `logging.Logger`, ' 'default: logging.getLogger(\'transmission-rpc\')') self._query_timeout = timeout url = yarl.URL.build(scheme=protocol, user=username, password=password, host=host, port=port, path=urljoin(path, 'rpc')) self.url = str(url) self._sequence = 0 self.session: Session = Session() self.session_id = 0 self.server_version = None self.protocol_version: Optional[int] = None self._http_session = requests.Session() self.get_session() self.torrent_get_arguments = get_arguments('torrent-get', self.rpc_version)
def _update_session(self, data): """ Update session data. """ if self.session: self.session.from_request(data) else: self.session = Session(self, data)
def _update_session(self, data: Dict[str, Any]) -> None: """ Update session data. """ if self.session: self.session.from_request(data) else: self.session = Session(self, data)
def _update_session(self, data: Dict[str, Any]) -> None: """ Update session data. """ if self.session: self.session._update(data) # pylint: disable=W0212 else: self.session = Session(self, data)
def test_session_update_dict(): m = mock.Mock() s = Session(m) assert not dict(s.items()) data = {"a": 1, "b": "2", "c": 3} s.update(data) m.set_session.assert_called_once_with(**data) assert dict(s.items()) == data assert set(s.keys()) == set(data.keys())
def __init__( self, *, protocol: "Literal['http', 'https']" = "http", username: str = None, password: str = None, host: str = "127.0.0.1", port: int = 9091, path: str = "/transmission/", timeout: Union[int, float] = DEFAULT_TIMEOUT, logger: logging.Logger = LOGGER, ): if isinstance(logger, logging.Logger): self.logger = logger else: raise TypeError( "logger must be instance of `logging.Logger`, " "default: logging.getLogger('transmission-rpc')" ) self._query_timeout: _Timeout = timeout import urllib.parse username = ( quote(username or "", safe="$-_.+!*'(),;&=", encoding="utf8") if username else "" ) password = ( ":" + quote(password or "", safe="$-_.+!*'(),;&=", encoding="utf8") if password else "" ) auth = f"{username}{password}@" if (username or password) else "" url = urllib.parse.urlunparse( (protocol, f"{auth}{host}:{port}", urljoin(path, "rpc"), None, None, None) ) self.url = str(url) self._sequence = 0 self.session: Session = Session(self) self.session_id = "0" self.server_version: Optional[Tuple[int, int, Optional[str]]] = None self.protocol_version: Optional[int] = None self._http_session = requests.Session() self.get_session() self.torrent_get_arguments = get_arguments("torrent-get", self.rpc_version)
def __init__( self, *, protocol: "Literal['http', 'https']" = "http", username: str = None, password: str = None, host: str = "127.0.0.1", port: int = 9091, path: str = "/transmission/", timeout: Union[int, float] = DEFAULT_TIMEOUT, logger: logging.Logger = LOGGER, ): if isinstance(logger, logging.Logger): self.logger = logger else: raise TypeError( "logger must be instance of `logging.Logger`, " "default: logging.getLogger('transmission-rpc')" ) self._query_timeout: _Timeout = timeout url = yarl.URL.build( scheme=protocol, user=username, password=password, host=host, port=port, path=urljoin(path, "rpc"), ) self.url = str(url) self._sequence = 0 self.session: Session = Session(self) self.session_id = "0" self.server_version: Optional[Tuple[int, int, Optional[str]]] = None self.protocol_version: Optional[int] = None self._http_session = requests.Session() self.get_session() self.torrent_get_arguments = get_arguments("torrent-get", self.rpc_version)
def test_session_init(): fields = {"a-b": 1} s = Session(mock.Mock(), fields=fields) assert dict(s.items()) == {"a_b": 1}
def test_session_get_attribute(): fields = {"a-b": 1} s = Session(mock.Mock(), fields=fields) assert s.a_b == 1