예제 #1
0
def test_client_custom_http_client(db, username, password):

    # Define custom HTTP client which increments the counter on any API call.
    class MyHTTPClient(DefaultHTTPClient):

        def __init__(self):
            super(MyHTTPClient, self).__init__()
            self.counter = 0

        def send_request(self,
                         method,
                         url,
                         headers=None,
                         params=None,
                         data=None,
                         auth=None):
            self.counter += 1
            return super(MyHTTPClient, self).send_request(
                method, url, headers, params, data, auth
            )

    http_client = MyHTTPClient()
    client = ArangoClient(
        protocol='http',
        host='127.0.0.1',
        port=8529,
        http_client=http_client
    )
    # Set verify to True to send a test API call on initialization.
    client.db(db.name, username, password, verify=True)
    assert http_client.counter == 1
예제 #2
0
def createdatabase(password):
    client = ArangoClient(hosts='http://localhost:8529')
    sys_db = client.db('_system', username='******', password=password)

    if sys_db.has_database('Capstone'):
        sys_db.delete_database('Capstone')

    sys_db.create_database('Capstone')
    global db
    db = client.db('Capstone', username='******', password=password)
    languagesCollection = db.create_collection('languages')
    programmingLang = ['Python', 'Java', 'Dart', 'C++']
    for lang in programmingLang:
        data = {'name': lang}
        languagesCollection.insert(data)

    coursesCollection = db.create_collection('courses')
    coursesName = ['Beginner', 'Intermediate', 'Advance']
    for lang in programmingLang:
        for course in coursesName:
            data = {
                'name': course + ' ' + lang,
                'language': lang,
                'vedio quality': 0,
                'qalified instructor': 0,
                'content quality': 0,
                'course pace': 0,
                'course depth and quality': 0,
                'rating': 0
            }
            coursesCollection.insert(data)
    return 'database created'
예제 #3
0
def test_client_custom_http_client(db, username, password):

    # Define custom HTTP client which increments the counter on any API call.
    class MyHTTPClient(DefaultHTTPClient):
        def __init__(self) -> None:
            super().__init__()
            self.counter = 0

        def send_request(self,
                         session,
                         method,
                         url,
                         headers=None,
                         params=None,
                         data=None,
                         auth=None):
            self.counter += 1
            return super().send_request(session, method, url, headers, params,
                                        data, auth)

    http_client = MyHTTPClient()
    client = ArangoClient(hosts="http://127.0.0.1:8529",
                          http_client=http_client)
    # Set verify to True to send a test API call on initialization.
    client.db(db.name, username, password, verify=True)
    assert http_client.counter == 1
예제 #4
0
파일: arango.py 프로젝트: ndebuhr/yay
def get_db(variables):
    endpoint = variables[ARANGO_ENDPOINT]
    database = variables[ARANGO_DATABASE]

    client = ArangoClient(endpoint['protocol'], endpoint['host'],
                          endpoint['port'])

    return client.db(database, endpoint['username'], endpoint['password'])
예제 #5
0
def test_client_good_connection(db, username, password):
    client = ArangoClient(hosts="http://127.0.0.1:8529")

    # Test connection with verify flag on and off
    for verify in (True, False):
        db = client.db(db.name, username, password, verify=verify)
        assert isinstance(db, StandardDatabase)
        assert db.name == db.name
        assert db.username == username
        assert db.context == "default"
예제 #6
0
def test_client_good_connection(db, username, password):
    client = ArangoClient(
        protocol='http',
        host='127.0.0.1',
        port=8529,
    )

    # Test connection with verify flag on and off
    for verify in (True, False):
        db = client.db(db.name, username, password, verify=verify)
        assert isinstance(db, StandardDatabase)
        assert db.name == db.name
        assert db.username == username
        assert db.context == 'default'
예제 #7
0
def test_client_good_connection(db, username, password):
    client = ArangoClient(
        protocol='http',
        host='127.0.0.1',
        port=8529,
    )

    # Test connection with verify flag on and off
    for verify in (True, False):
        db = client.db(db.name, username, password, verify=verify)
        assert isinstance(db, StandardDatabase)
        assert db.name == db.name
        assert db.username == username
        assert db.context == 'default'
예제 #8
0
 def build(cls, config: ArangoConfig):
     client: ArangoClient = ArangoClient(
         hosts=f"http://{config.hostname}:{config.port}")
     try:
         db: StandardDatabase = connect_to_db(client=client, config=config)
         return cls(db=db)
     except ServerConnectionError:
         initialize_db(client=client, config=config)
         return cls.build(config=config)
예제 #9
0
def test_client_bad_connection(db, username, password, cluster):
    client = ArangoClient(hosts="http://127.0.0.1:8529")

    bad_db_name = generate_db_name()
    bad_username = generate_username()
    bad_password = generate_string()

    if not cluster:
        # Test connection with bad username password
        with pytest.raises(ServerConnectionError):
            client.db(db.name, bad_username, bad_password, verify=True)

    # Test connection with missing database
    with pytest.raises(ServerConnectionError):
        client.db(bad_db_name, bad_username, bad_password, verify=True)

    # Test connection with invalid host URL
    client = ArangoClient(hosts="http://127.0.0.1:8500")
    with pytest.raises(ServerConnectionError) as err:
        client.db(db.name, username, password, verify=True)
    assert "bad connection" in str(err.value)
예제 #10
0
def test_client_attributes():
    session = DefaultHTTPClient()
    client = ArangoClient(protocol='http',
                          host='127.0.0.1',
                          port=8529,
                          http_client=session)
    assert client.version == __version__
    assert client.protocol == 'http'
    assert client.host == '127.0.0.1'
    assert client.port == 8529
    assert client.base_url == 'http://127.0.0.1:8529'
    assert repr(client) == '<ArangoClient http://127.0.0.1:8529>'
예제 #11
0
def test_client_attributes():
    http_client = DefaultHTTPClient()

    client = ArangoClient(hosts="http://127.0.0.1:8529",
                          http_client=http_client)
    assert client.version == get_distribution("python-arango").version
    assert client.hosts == ["http://127.0.0.1:8529"]

    assert repr(client) == "<ArangoClient http://127.0.0.1:8529>"
    assert isinstance(client._host_resolver, SingleHostResolver)

    client_repr = "<ArangoClient http://127.0.0.1:8529,http://localhost:8529>"
    client_hosts = ["http://127.0.0.1:8529", "http://localhost:8529"]

    client = ArangoClient(
        hosts="http://127.0.0.1:8529,http://localhost"
        ":8529",
        http_client=http_client,
        serializer=json.dumps,
        deserializer=json.loads,
    )
    assert client.version == get_distribution("python-arango").version
    assert client.hosts == client_hosts
    assert repr(client) == client_repr
    assert isinstance(client._host_resolver, RoundRobinHostResolver)

    client = ArangoClient(
        hosts=client_hosts,
        host_resolver="random",
        http_client=http_client,
        serializer=json.dumps,
        deserializer=json.loads,
    )
    assert client.version == get_distribution("python-arango").version
    assert client.hosts == client_hosts
    assert repr(client) == client_repr
    assert isinstance(client._host_resolver, RandomHostResolver)
예제 #12
0
def test_client_attributes():
    http_client = DefaultHTTPClient()

    client = ArangoClient(hosts='http://127.0.0.1:8529',
                          http_client=http_client)
    assert client.version == __version__
    assert client.hosts == ['http://127.0.0.1:8529']

    assert repr(client) == '<ArangoClient http://127.0.0.1:8529>'
    assert isinstance(client._host_resolver, SingleHostResolver)

    client_repr = '<ArangoClient http://127.0.0.1:8529,http://localhost:8529>'
    client_hosts = ['http://127.0.0.1:8529', 'http://localhost:8529']

    client = ArangoClient(
        hosts='http://127.0.0.1:8529,http://localhost'
        ':8529',
        http_client=http_client,
        serializer=json.dumps,
        deserializer=json.loads,
    )
    assert client.version == __version__
    assert client.hosts == client_hosts
    assert repr(client) == client_repr
    assert isinstance(client._host_resolver, RoundRobinHostResolver)

    client = ArangoClient(
        hosts=client_hosts,
        host_resolver='random',
        http_client=http_client,
        serializer=json.dumps,
        deserializer=json.loads,
    )
    assert client.version == __version__
    assert client.hosts == client_hosts
    assert repr(client) == client_repr
    assert isinstance(client._host_resolver, RandomHostResolver)
예제 #13
0
def test_client_bad_connection(db, username, password):
    client = ArangoClient(protocol='http', host='127.0.0.1', port=8529)

    bad_db_name = generate_db_name()
    bad_username = generate_username()
    bad_password = generate_string()

    # Test connection with bad username password
    with pytest.raises(ServerConnectionError):
        client.db(db.name, bad_username, bad_password, verify=True)

    # Test connection with missing database
    with pytest.raises(ServerConnectionError):
        client.db(bad_db_name, bad_username, bad_password, verify=True)

    # Test connection with invalid host URL
    client._url = 'http://127.0.0.1:8500'
    with pytest.raises(ServerConnectionError) as err:
        client.db(db.name, username, password, verify=True)
    assert 'bad connection' in str(err.value)
예제 #14
0
def test_client_bad_connection(db, username, password):
    client = ArangoClient(protocol='http', host='127.0.0.1', port=8529)

    bad_db_name = generate_db_name()
    bad_username = generate_username()
    bad_password = generate_string()

    # Test connection with bad username password
    with pytest.raises(ServerConnectionError):
        client.db(db.name, bad_username, bad_password, verify=True)

    # Test connection with missing database
    with pytest.raises(ServerConnectionError):
        client.db(bad_db_name, bad_username, bad_password, verify=True)

    # Test connection with invalid host URL
    client._url = 'http://127.0.0.1:8500'
    with pytest.raises(ServerConnectionError) as err:
        client.db(db.name, username, password, verify=True)
    assert 'bad connection' in str(err.value)
예제 #15
0
def connect_to_db(client: ArangoClient,
                  config: ArangoConfig) -> StandardDatabase:
    return client.db(**config.credentials.to_dict(),
                     name=SYSTEM_DB,
                     verify=True)