コード例 #1
0
def test_create_missing_fields(event_loop, server, client, file_server):

    # Start a new session.
    response, index = yield from get_json(
        client, server,
    )
    with autoclose(response):
        assert response.status == 200

    def without(d, key):
        return {k: v for k, v in d.items() if k != key}

    # Full request that works.
    req = {
        'app': 'foo',
        'node': 'web.0',
        'source_url': file_server.url('stuff.zip'),
        'process_type': 'web',
    }

    # App field is required.
    response = yield from client.post(
        index['create'], data=json.dumps(without(req, 'app')),
    )
    with autoclose(response):
        assert response.status == 400
コード例 #2
0
def post_json(client, url, payload, headers={}):
    response = yield from client.post(
        url, data=json.dumps(payload), headers=headers
    )
    with autoclose(response):
        body = yield from response.read()
        return response, json.loads(body.decode('utf-8'))
コード例 #3
0
def test_unknown_slug(event_loop, server, client):

    # Try to query an unknown process.
    response = yield from client.get(
        urllib.parse.urljoin(server, '/process-status/unknown'),
        data=json.dumps({}),
    )
    with autoclose(response):
        assert response.status == 404

    # Try to delete an unknown process.
    response = yield from client.post(
        urllib.parse.urljoin(server, '/delete-process/unknown'),
        data=json.dumps({}),
    )
    with autoclose(response):
        assert response.status == 404

    # Try to attach to an unknown process.
    with pytest.raises(aiohttp.errors.WSServerHandshakeError):
        stream = yield from client.ws_connect(
            urllib.parse.urljoin(server, '/attach-console/unknown'),
        )
        print(stream)
コード例 #4
0
def test_create_duplicate(event_loop, server, client, file_server):

    # Create an application.
    archive_path = file_server.provide('stuff.zip')
    with zipfile.ZipFile(archive_path, 'w') as archive:
        archive.writestr('Procfile', 'web: python dots.py')
        archive.writestr('requirements.txt', 'Flask==0.10.1')

    # Start a new session.
    response, index = yield from get_json(
        client, server,
    )
    assert response.status == 200

    # Create a new process.
    response, process = yield from post_json(
        client, index['create'], {
            'app': 'foo',
            'node': 'web.0',
            'source_url': file_server.url('stuff.zip'),
            'process_type': 'web',
        },
    )
    assert response.status == 201

    # Try to create the same process again.
    response = yield from client.post(
        index['create'], data=json.dumps({
            'app': 'foo',
            'node': 'web.0',
            'source_url': file_server.url('stuff.zip'),
            'process_type': 'web',
        }),
    )
    with autoclose(response):
        assert response.status == 409

    # Now, delete the process.
    response, delete = yield from post_json(
        client, process['delete'], {},
    )
    assert response.status == 200
コード例 #5
0
def client(event_loop):
    session = aiohttp.ClientSession(loop=event_loop)
    with autoclose(session):
        yield session
コード例 #6
0
def get_json(client, url):
    response = yield from client.get(url)
    with autoclose(response):
        body = yield from response.read()
        return response, json.loads(body.decode('utf-8'))