예제 #1
0
def client(connection_type, testdb_uri):
    print("GETTING CLIENT")
    if connection_type == 'local':
        client = JSONConnection(app_name='Hydra Local Test Suite', db_url=testdb_uri)
        #fake a login using the test's session
        client.user_id = 1
        client.connect()
    else:

        from spyne.server.null import NullServer
        from hydra_server import initialize_api_server

        hydra_server = initialize_api_server(testdb_uri, test=True)

        null_server = NullServer(hydra_server.json_application, ostr=True)

        #The url argument here is to avoid the connection complaining.
        #It's not actually used, as we're using a null (testing) server
        client = RemoteJSONConnection(url='localhost:8080/json',
                                      app_name='Hydra Remote Test Suite',
                                      test_server=null_server)
        client.login('root', '')

    client.testutils = hydra_base.util.testing.TestUtil(client)
    pytest.root_user_id = 1
    pytest.user_a = client.testutils.create_user("UserA")
    pytest.user_b = client.testutils.create_user("UserB")
    pytest.user_c = client.testutils.create_user("UserC", role='developer')
    yield client
    #???
    hydra_base.db.close_session()
    try:
        drop_tables(testdb_uri)
    except Exception as err:
        print("Error dropping DB")
def test_local_connection(session):
    """ Test a direct connection to hydra-base. """

    connection = JSONConnection(app_name='Test application.')
    connection.login()
    # Check login
    assert connection.user_id is not None

    # Get my own projects
    #The UID argument ere is the user whose projects are being requested
    projects = connection.get_projects(connection.user_id)
    # There should be no projects in this new DB.
    assert len(projects) == 0
예제 #3
0
def client(testdb_uri, session):
    client = JSONConnection(app_name='Hydra Network Utilities App',
                            session=hydra_base.db.DBSession)
    #fake a login using the test's session
    client.user_id = 1
    return client
예제 #4
0
파일: cli.py 프로젝트: pywr/PywrApp
def get_client(hostname, **kwargs):
    return JSONConnection(app_name='Pywr Hydra App', db_url=hostname, **kwargs)
예제 #5
0
def get_client(hostname, **kwargs):
    return JSONConnection(app_name='Hydra Base Utilities',
                          db_url=hostname,
                          **kwargs)
예제 #6
0
def client(testdb_uri):
    return JSONConnection(app_name="Test Pywr application.", db_url=testdb_uri)