From e9d0f52a5cab829e4cedc499335366b9e146da4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Tue, 14 May 2019 21:50:30 +0200 Subject: [PATCH] pantalaimon: Isort the tree. --- pantalaimon/client.py | 21 ++++++-------- pantalaimon/config.py | 8 ++---- pantalaimon/daemon.py | 21 ++++++-------- pantalaimon/main.py | 16 ++++------- pantalaimon/panctl.py | 17 +++++------ pantalaimon/ui.py | 29 ++++++++----------- tests/conftest.py | 65 +++++++++++++++++++++++++++++++++++++++++++ tests/store_test.py | 65 +------------------------------------------ 8 files changed, 109 insertions(+), 133 deletions(-) create mode 100644 tests/conftest.py diff --git a/pantalaimon/client.py b/pantalaimon/client.py index 07d1811..f68a3f0 100644 --- a/pantalaimon/client.py +++ b/pantalaimon/client.py @@ -3,22 +3,17 @@ from pprint import pformat from typing import Any, Dict, Optional from aiohttp.client_exceptions import ClientConnectionError -from nio import (AsyncClient, ClientConfig, EncryptionError, - KeysQueryResponse, MegolmEvent, - RoomEncryptedEvent, SyncResponse, - KeyVerificationEvent, LocalProtocolError, - KeyVerificationStart, KeyVerificationKey, KeyVerificationMac) -from nio.store import SqliteStore +from nio import (AsyncClient, ClientConfig, EncryptionError, KeysQueryResponse, + KeyVerificationEvent, KeyVerificationKey, KeyVerificationMac, + KeyVerificationStart, LocalProtocolError, MegolmEvent, + RoomEncryptedEvent, SyncResponse) from nio.crypto import Sas +from nio.store import SqliteStore from pantalaimon.log import logger -from pantalaimon.thread_messages import ( - DevicesMessage, - InviteSasSignal, - ShowSasSignal, - SasDoneSignal, - DaemonResponse -) +from pantalaimon.thread_messages import (DaemonResponse, DevicesMessage, + InviteSasSignal, SasDoneSignal, + ShowSasSignal) class PanClient(AsyncClient): diff --git a/pantalaimon/config.py b/pantalaimon/config.py index 5747cbf..40c9c38 100644 --- a/pantalaimon/config.py +++ b/pantalaimon/config.py @@ -1,13 +1,11 @@ import configparser import os - +from ipaddress import IPv4Address, IPv6Address, ip_address from typing import Union +from urllib.parse import ParseResult, urlparse -from ipaddress import ip_address, IPv4Address, IPv6Address -from urllib.parse import urlparse, ParseResult - -import logbook import attr +import logbook class PanConfigParser(configparser.ConfigParser): diff --git a/pantalaimon/daemon.py b/pantalaimon/daemon.py index ecec19b..4e3af51 100755 --- a/pantalaimon/daemon.py +++ b/pantalaimon/daemon.py @@ -10,24 +10,19 @@ import aiohttp import attr import keyring from aiohttp import ClientSession, web -from aiohttp.client_exceptions import (ContentTypeError, - ClientConnectionError) +from aiohttp.client_exceptions import ClientConnectionError, ContentTypeError from multidict import CIMultiDict -from nio import (EncryptionError, LoginResponse, SendRetryError) +from nio import EncryptionError, LoginResponse, SendRetryError from pantalaimon.client import PanClient from pantalaimon.log import logger from pantalaimon.store import ClientInfo, PanStore -from pantalaimon.thread_messages import ( - DeviceVerifyMessage, - DeviceUnverifyMessage, - ExportKeysMessage, - ImportKeysMessage, - DeviceConfirmSasMessage, - SasMessage, - AcceptSasMessage, - DaemonResponse, -) +from pantalaimon.thread_messages import (AcceptSasMessage, DaemonResponse, + DeviceConfirmSasMessage, + DeviceUnverifyMessage, + DeviceVerifyMessage, + ExportKeysMessage, ImportKeysMessage, + SasMessage) @attr.s diff --git a/pantalaimon/main.py b/pantalaimon/main.py index 3a0b7f3..5daa858 100644 --- a/pantalaimon/main.py +++ b/pantalaimon/main.py @@ -1,23 +1,19 @@ import asyncio - import os import signal +from typing import Optional import click import janus - -from typing import Optional - -from appdirs import user_data_dir, user_config_dir +from aiohttp import web +from appdirs import user_config_dir, user_data_dir from logbook import StderrHandler -from aiohttp import web - -from pantalaimon.ui import GlibT -from pantalaimon.thread_messages import DaemonResponse -from pantalaimon.daemon import ProxyDaemon from pantalaimon.config import PanConfig, PanConfigError, parse_log_level +from pantalaimon.daemon import ProxyDaemon from pantalaimon.log import logger +from pantalaimon.thread_messages import DaemonResponse +from pantalaimon.ui import GlibT def create_dirs(data_dir, conf_dir): diff --git a/pantalaimon/panctl.py b/pantalaimon/panctl.py index 4ebbbb6..a2e92d7 100644 --- a/pantalaimon/panctl.py +++ b/pantalaimon/panctl.py @@ -1,22 +1,19 @@ """Cli utility to control pantalaimon.""" -import attr -import asyncio import argparse +import asyncio import sys - -from typing import List from itertools import zip_longest +from typing import List -from prompt_toolkit import PromptSession -from prompt_toolkit.eventloop.defaults import use_asyncio_event_loop -from prompt_toolkit.patch_stdout import patch_stdout +import attr +from gi.repository import GLib +from prompt_toolkit import HTML, PromptSession, print_formatted_text from prompt_toolkit.completion import Completer, Completion, PathCompleter from prompt_toolkit.document import Document -from prompt_toolkit import print_formatted_text, HTML - +from prompt_toolkit.eventloop.defaults import use_asyncio_event_loop +from prompt_toolkit.patch_stdout import patch_stdout from pydbus import SessionBus -from gi.repository import GLib use_asyncio_event_loop() diff --git a/pantalaimon/ui.py b/pantalaimon/ui.py index dbeb2f1..33a98e4 100644 --- a/pantalaimon/ui.py +++ b/pantalaimon/ui.py @@ -1,27 +1,20 @@ -import attr +from queue import Empty +import attr from gi.repository import GLib +from nio.store import TrustState from pydbus import SessionBus from pydbus.generic import signal -from queue import Empty -from nio.store import TrustState - -from pantalaimon.store import PanStore -from pantalaimon.thread_messages import ( - DeviceVerifyMessage, - DeviceUnverifyMessage, - DevicesMessage, - AcceptSasMessage, - DeviceConfirmSasMessage, - ImportKeysMessage, - ExportKeysMessage, - ShowSasSignal, - InviteSasSignal, - SasDoneSignal, - DaemonResponse -) from pantalaimon.log import logger +from pantalaimon.store import PanStore +from pantalaimon.thread_messages import (AcceptSasMessage, DaemonResponse, + DeviceConfirmSasMessage, + DevicesMessage, DeviceUnverifyMessage, + DeviceVerifyMessage, + ExportKeysMessage, ImportKeysMessage, + InviteSasSignal, SasDoneSignal, + ShowSasSignal) class IdCounter: diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..c7d49af --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,65 @@ +import shutil +import tempfile +from random import choices +from string import ascii_letters, ascii_uppercase, digits + +import pytest +from faker import Faker +from faker.providers import BaseProvider +from nio.crypto import OlmAccount +from nio.store import SqliteStore + +from pantalaimon.store import ClientInfo, PanStore + +faker = Faker() + + +class Provider(BaseProvider): + def mx_id(self): + return "@{}:{}".format(faker.user_name(), faker.hostname()) + + def device_id(self): + return "".join(choices(ascii_uppercase, k=10)) + + def access_token(self): + return "MDA" + "".join(choices(digits + ascii_letters, k=272)) + + def client(self): + return ClientInfo(faker.mx_id(), faker.access_token()) + + +faker.add_provider(Provider) + + +@pytest.fixture +def access_token(): + return faker.access_token() + + +@pytest.fixture +def client(): + return faker.client() + + +@pytest.fixture +def tempdir(): + newpath = tempfile.mkdtemp() + yield newpath + shutil.rmtree(newpath) + + +@pytest.fixture +def panstore(tempdir): + for _ in range(10): + store = SqliteStore( + faker.mx_id(), + faker.device_id(), + tempdir, + "", + "pan.db" + ) + account = OlmAccount() + store.save_account(account) + + store = PanStore(tempdir, "pan.db") + return store diff --git a/tests/store_test.py b/tests/store_test.py index 08f4057..b95a89a 100644 --- a/tests/store_test.py +++ b/tests/store_test.py @@ -1,69 +1,6 @@ import pdb -import shutil -import tempfile -from random import choices -from string import ascii_letters, ascii_uppercase, digits -import pytest -from faker import Faker -from faker.providers import BaseProvider -from nio.crypto import OlmAccount -from nio.store import SqliteStore - -from pantalaimon.store import ClientInfo, PanStore - -faker = Faker() - - -class Provider(BaseProvider): - def mx_id(self): - return "@{}:{}".format(faker.user_name(), faker.hostname()) - - def device_id(self): - return "".join(choices(ascii_uppercase, k=10)) - - def access_token(self): - return "MDA" + "".join(choices(digits + ascii_letters, k=272)) - - def client(self): - return ClientInfo(faker.mx_id(), faker.access_token()) - - -faker.add_provider(Provider) - - -@pytest.fixture -def access_token(): - return faker.access_token() - - -@pytest.fixture -def client(): - return faker.client() - - -@pytest.fixture -def tempdir(): - newpath = tempfile.mkdtemp() - yield newpath - shutil.rmtree(newpath) - - -@pytest.fixture -def panstore(tempdir): - for _ in range(10): - store = SqliteStore( - faker.mx_id(), - faker.device_id(), - tempdir, - "", - "pan.db" - ) - account = OlmAccount() - store.save_account(account) - - store = PanStore(tempdir, "pan.db") - return store +from conftest import faker class TestClass(object):