async def main(user, passw, url_name):
    print('Trying to connect with user ' + user)

    async with aiohttp.ClientSession() as sess:
        connector = Connector(user, passw, sess)

        try:
            await connector.login(True)
            print('Login successful')
        except ApiError as err:
            print(err.message)
            print(err.response)
            print(err.status)

        facilities = await connector.get(urls.facilities_list())
        serial = mapper.map_serial_number(facilities)

        url_method = getattr(urls, url_name)
        url = url_method(**{'serial': serial})
        print(url)

        try:
            print(json.dumps(await connector.get(url)))
        except ApiError as err:
            print(err.message)
            print(err.response)
            print(err.status)
Beispiel #2
0
async def main(user, passw):
    print('Trying to connect with user ' + user)

    async with aiohttp.ClientSession() as sess:

        shutil.rmtree('./dump_result', ignore_errors=True)
        os.mkdir('./dump_result')

        connector = Connector(user, passw, sess)

        try:
            await connector.login(True)
            print('Login successful')
        except ApiError as err:
            print('Cannot login: '******'requesting ' + url.__name__)
            req = connector.get(url(**{'serial': serial}))
            requests.update({url.__name__: req})

        print('did {} requests'.format(len(requests)))

        responses = {}
        for key in requests:
            try:
                responses.update({key: await requests[key]})
            except:
                print('Cannot get response for {}, skipping it'.format(key))

        print('received {} responses'.format(len(responses)))

        for key in responses:
            try:
                with open('./dump_result/{}.json'.format(key), 'w+') as file:
                    data = json.dumps(responses[key])\
                        .replace(serial, 'SERIAL_NUMBER')
                    json.dump(json.loads(data), file, indent=4)
            except:
                print('cannot write to file {}'.format(file.name))
import json
from datetime import date, timedelta
from typing import Any, AsyncGenerator, Dict, List, Tuple, Type
from unittest import mock

import pytest
from aiohttp import ClientSession
from aioresponses import aioresponses

from pymultimatic.api import ApiError, Connector, WrongResponseError, payloads, urls
from pymultimatic.model import OperatingModes, QuickModes, QuickVeto, constants, mapper
from pymultimatic.systemmanager import SystemManager, retry_async
from tests.conftest import mock_auth, path

SERIAL = mapper.map_serial_number(
    json.loads(open(path("files/responses/facilities")).read()))


@pytest.fixture(name="resp", autouse=True)
async def fixture_resp(
        resp: aioresponses) -> AsyncGenerator[aioresponses, None]:
    with open(path("files/responses/facilities"), "r") as file:
        facilities = json.loads(file.read())
        resp.get(urls.facilities_list(), payload=facilities, status=200)
    yield resp


@pytest.fixture(name="manager")
async def fixture_manager(
        session: ClientSession,
        connector: Connector) -> AsyncGenerator[SystemManager, None]: