コード例 #1
0
ファイル: test_messaging.py プロジェクト: MinesJA/grid
def mock_builder():
    # id = uuid1()
    node = Node('n1', 'abcd', '111.222.333', 1234, 10, 5)
    node.siblings = {'n2': NodeProxy('n2', '222.333.444', 2345)}
    node_builder = AsyncMock()
    node_builder.get.return_value = node
    return node_builder
コード例 #2
0
def test_get_energy():
    id = 'n1'
    address = '123.123.123'
    port = 1234
    consumption = 10
    production = 5

    node = Node(id, address, port, consumption, production)
    data = {'consumption': consumption, 'production': production, 'net': 5}

    TestCase().assertDictEqual(node.get_energy(), data)
コード例 #3
0
def test_equality():
    id = 'n1'
    consumption = 10
    production = 5

    address1 = '111.111.111'
    address2 = '222.222.222'
    port1 = 1111
    port2 = 2222

    node1 = Node(id, address1, port1, consumption, production)
    node2 = Node(id, address2, port2, consumption, production)
    node3 = Node('n2', address2, port2, consumption, production)

    assert node1 == node2
    assert node1 != node3
コード例 #4
0
def test_create_node():
    id = 'n1'
    address = '123.123.123'
    port = 1234
    consumption = 10
    production = 5

    node = Node(id, address, port, consumption, production)

    assert type(node) is Node
    assert node.id == id
    assert node.address == address
    assert node.port == port
    assert node.consumption == consumption
    assert node.production == production
    assert node.net == 5
    assert node.full_address == f'{address}:{port}'
    assert node.siblings == {}
コード例 #5
0
def test_update_energy():
    id = 'n1'
    address = '123.123.123'
    port = 1234
    consumption = 10
    production = 5

    node = Node(id, address, port, consumption, production)

    node.update_energy(consumption=20, production=None)
    assert node.consumption == 20
    assert node.production == production

    node.update_energy(consumption=None, production=10)
    assert node.consumption == 20
    assert node.production == 10

    node.update_energy(consumption=30, production=20)
    assert node.consumption == 30
    assert node.production == 20
コード例 #6
0
ファイル: app.py プロジェクト: MinesJA/grid
OUTBOX = asyncio.Queue()
SESSION = aiohttp.ClientSession()
ARGS = parse_args(sys.argv[1:])


def handle_exit(server, task_manager):
    server.exit()
    task_manager.exit()


mailroom = MailRoom(outbox=OUTBOX)


node = Node(name=ARGS.name,
            id=ARGS.id,
            host=ARGS.host,
            port=ARGS.port,
            production=0,
            consumption=0)

app = create_app(inbox=INBOX, token=ARGS.token, name=ARGS.name)

loop = asyncio.get_event_loop()

config = Config(app=app, host=ARGS.host, port=ARGS.port, loop=loop)
server = Server(config)
message_service = MessageService()

if __name__ == "__main__":
    print(f'Grid:   Starting Grid')
    print(f'Grid:   Created Node: {node.id}')
    print(f'GRID:   pid {os.getpid()}: send SIGINT or SIGTERM to exit.')