From a853f70eb3fc07f814114be4467f119af75d8dc0 Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Freeman <jeffrey.freeman@syncleus.com> Date: Sun, 26 Jan 2020 19:29:37 +0100 Subject: [PATCH] CI: Fixing integration tests. --- .eggs/README.txt | 6 +++ .gitlab-ci.yml | 8 +++- builds/0/project-0 | 1 + builds/0/project-0.tmp/git-template/config | 2 + requirements.txt | 14 +++++++ tests/conftest.py | 44 ++++++++++++++++++++-- tests/test_aliases.py | 4 +- tests/test_client.py | 8 ++-- tests/test_config.py | 2 +- tests/test_gremlin_python/conftest.py | 29 +++++++++++++- 10 files changed, 104 insertions(+), 14 deletions(-) create mode 100644 .eggs/README.txt create mode 160000 builds/0/project-0 create mode 100644 builds/0/project-0.tmp/git-template/config diff --git a/.eggs/README.txt b/.eggs/README.txt new file mode 100644 index 0000000..5d01668 --- /dev/null +++ b/.eggs/README.txt @@ -0,0 +1,6 @@ +This directory contains eggs that were downloaded by setuptools to build, test, and run plug-ins. + +This directory caches those eggs to prevent repeated downloads. + +However, it is safe to delete this directory. + diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a33dbc4..f12250b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,14 +1,18 @@ image: goblinogm/goblin-buildchain + cache: paths: - vendor test: + services: + - name: goblinogm/gremlin-server-python:latest + alias: gremlin-server + image: goblinogm/goblin-buildchain script: - pip install -U -r requirements.txt - - cd docs - - make html + - python setup.py test except: - master diff --git a/builds/0/project-0 b/builds/0/project-0 new file mode 160000 index 0000000..110cd16 --- /dev/null +++ b/builds/0/project-0 @@ -0,0 +1 @@ +Subproject commit 110cd16336d7e67d40c3656cd5a651a5db49229d diff --git a/builds/0/project-0.tmp/git-template/config b/builds/0/project-0.tmp/git-template/config new file mode 100644 index 0000000..63543c8 --- /dev/null +++ b/builds/0/project-0.tmp/git-template/config @@ -0,0 +1,2 @@ +[fetch] + recurseSubmodules = false diff --git a/requirements.txt b/requirements.txt index 963671d..169b160 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,16 @@ gremlinpython==3.3.0 PyYAML>=3.12 + +#required foir kobalos +six==1.10.0 +aenum==1.4.5 +aiohttp==2.3.10 +inflection==0.3.1 + +#for kobalos testing +pytest-asyncio>=0.8.0 +pytest-cache>=1.0 +pytest-cov>=2.5.1 +pytest-pep8>=1.0.6 +pytest>=3.2.1 + diff --git a/tests/conftest.py b/tests/conftest.py index abce5a0..44d1240 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,9 +16,13 @@ # along with Goblin. If not, see <http://www.gnu.org/licenses/>. import asyncio import pytest + +from aiogremlin.structure.graph import Graph +from gremlin_python.process.traversal import T from aiogremlin import driver from aiogremlin.driver.provider import TinkerGraph from gremlin_python.driver import serializer +from aiogremlin.remote.driver_remote_connection import DriverRemoteConnection # def pytest_generate_tests(metafunc): @@ -29,7 +33,7 @@ from gremlin_python.driver import serializer def pytest_addoption(parser): parser.addoption('--provider', default='tinkergraph', choices=('tinkergraph', 'dse',)) - parser.addoption('--gremlin-host', default='localhost') + parser.addoption('--gremlin-host', default='gremlin-server') parser.addoption('--gremlin-port', default='8182') @@ -63,7 +67,7 @@ def gremlin_server(): @pytest.fixture def unused_server_url(unused_tcp_port): - return 'http://localhost:{}/gremlin'.format(unused_tcp_port) + return 'https://localhost:{}/gremlin'.format(unused_tcp_port) @pytest.fixture @@ -78,7 +82,7 @@ def gremlin_port(request): @pytest.fixture def gremlin_url(gremlin_host, gremlin_port): - return "http://{}:{}/gremlin".format(gremlin_host, gremlin_port) + return "ws://{}:{}/gremlin".format(gremlin_host, gremlin_port) @pytest.fixture @@ -133,3 +137,37 @@ def cluster(request, gremlin_host, gremlin_port, event_loop, provider, aliases): @pytest.fixture def cluster_class(event_loop): return driver.Cluster + +@pytest.fixture +def remote_connection(event_loop, gremlin_url): + try: + remote_conn = event_loop.run_until_complete( + DriverRemoteConnection.open(gremlin_url, 'g')) + except OSError: + pytest.skip('Gremlin Server is not running') + else: + return remote_conn + +@pytest.fixture(autouse=True) +def run_around_tests(remote_connection, event_loop): + g = Graph().traversal().withRemote(remote_connection) + + async def create_graph(): + await g.V().drop().iterate() + software1 = await g.addV("software").property("name", "lop").property("lang", "java").property(T.id, 3).next() + software2 = await g.addV("software").property("name", "ripple").property("lang", "java").property(T.id, 5).next() + person1 = await g.addV("person").property("name", "marko").property("age", "29").property(T.id, 1).next() + person2 = await g.addV("person").property("name", "vadas").property("age", "27").property(T.id, 2).next() + person3 = await g.addV("person").property("name", "josh").property("age", "32").property(T.id, 4).next() + person4 = await g.addV("person").property("name", "peter").property("age", "35").property(T.id, 6).next() + + knows1 = await g.addE("knows").from_(person1).to(person2).property("weight", 0.5).property(T.id, 7).next() + knows2 = await g.addE("knows").from_(person1).to(person3).property("weight", 1,0).property(T.id, 8).next() + created1 = await g.addE("created").from_(person1).to(software1).property("weight", 0.4).property(T.id, 9).next() + created2 = await g.addE("created").from_(person3).to(software2).property("weight", 1.0).property(T.id, 10).next() + created3 = await g.addE("created").from_(person3).to(software1).property("weight", 1.0).property(T.id, 11).next() + created4 = await g.addE("created").from_(person4).to(software1).property("weight", 0.2).property(T.id, 12).next() + + event_loop.run_until_complete(create_graph()) + + yield diff --git a/tests/test_aliases.py b/tests/test_aliases.py index 6926f6f..21d2271 100644 --- a/tests/test_aliases.py +++ b/tests/test_aliases.py @@ -9,7 +9,7 @@ from gremlin_python.driver import request, serializer @pytest.mark.asyncio async def test_gremlin_query(event_loop, cluster): alias = { 'g': 'g' } - cluster = await driver.Cluster.open(event_loop, aliases=alias) + cluster = await driver.Cluster.open(event_loop, aliases=alias, hosts=['gremlin-server']) client = await cluster.connect() assert client.aliases == alias resp = await client.submit("1 + 1") @@ -22,7 +22,7 @@ async def test_gremlin_query(event_loop, cluster): async def test_alias_serialization(event_loop): alias = { 'g': 'g' } message = '1 + 1' - cluster = await driver.Cluster.open(event_loop, aliases=alias) + cluster = await driver.Cluster.open(event_loop, aliases=alias, hosts=['gremlin-server']) client = await cluster.connect() # This is the code client/conn uses on submit message = request.RequestMessage( diff --git a/tests/test_client.py b/tests/test_client.py index 226e4dd..a366a3a 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -25,7 +25,7 @@ from aiogremlin.driver.server import GremlinServer @pytest.mark.asyncio async def test_client_auto_release(cluster): - client = await cluster.connect() + client = await cluster.connect(hostname='gremlin-server') resp = await client.submit("1 + 1") async for msg in resp: pass @@ -37,7 +37,7 @@ async def test_client_auto_release(cluster): @pytest.mark.asyncio async def test_alias(cluster): - client = await cluster.connect() + client = await cluster.connect(hostname='gremlin-server') aliased_client = client.alias({"g": "g1"}) assert aliased_client._aliases == {"g": "g1"} assert aliased_client._cluster is client._cluster @@ -47,11 +47,11 @@ async def test_alias(cluster): @pytest.mark.asyncio async def test_client_auto_release(cluster): - client = await cluster.connect(hostname='localhost') + client = await cluster.connect(hostname='gremlin-server') resp = await client.submit("1 + 1") async for msg in resp: assert msg == 2 - assert client._hostname == 'localhost' + assert client._hostname == 'gremlin-server' await cluster.close() diff --git a/tests/test_config.py b/tests/test_config.py index 7b41854..9ee43ec 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -79,7 +79,7 @@ def test_cluster_config_from_json(event_loop, cluster_class): def test_cluster_config_from_yaml(event_loop, cluster_class): - cluster = cluster_class(event_loop) + cluster = cluster_class(event_loop, host='gremlin-server') cluster.config_from_file(dirname + '/tests/config/config.yml') assert cluster.config['scheme'] == 'wss' assert cluster.config['hosts'] == ['localhost'] diff --git a/tests/test_gremlin_python/conftest.py b/tests/test_gremlin_python/conftest.py index 468fbf6..2172845 100644 --- a/tests/test_gremlin_python/conftest.py +++ b/tests/test_gremlin_python/conftest.py @@ -19,11 +19,12 @@ under the License. '''THIS FILE HAS BEEN MODIFIED BY DAVID M. BROWN TO SUPPORT PEP 492''' import pytest -from aiogremlin.remote.driver_remote_connection import ( - DriverRemoteConnection) +from aiogremlin.structure.graph import Graph +from aiogremlin.remote.driver_remote_connection import DriverRemoteConnection from aiogremlin.driver.protocol import GremlinServerWSProtocol from aiogremlin.driver.aiohttp.transport import AiohttpTransport from gremlin_python.driver.serializer import GraphSONMessageSerializer +from gremlin_python.process.traversal import T @pytest.fixture @@ -44,3 +45,27 @@ def remote_connection(event_loop, gremlin_url): pytest.skip('Gremlin Server is not running') else: return remote_conn + +@pytest.fixture(autouse=True) +def run_around_tests(remote_connection, event_loop): + g = Graph().traversal().withRemote(remote_connection) + + async def create_graph(): + await g.V().drop().iterate() + software1 = await g.addV("software").property("name", "lop").property("lang", "java").property(T.id, 3).next() + software2 = await g.addV("software").property("name", "ripple").property("lang", "java").property(T.id, 5).next() + person1 = await g.addV("person").property("name", "marko").property("age", "29").property(T.id, 1).next() + person2 = await g.addV("person").property("name", "vadas").property("age", "27").property(T.id, 2).next() + person3 = await g.addV("person").property("name", "josh").property("age", "32").property(T.id, 4).next() + person4 = await g.addV("person").property("name", "peter").property("age", "35").property(T.id, 6).next() + + knows1 = await g.addE("knows").from_(person1).to(person2).property("weight", 0.5).property(T.id, 7).next() + knows2 = await g.addE("knows").from_(person1).to(person3).property("weight", 1,0).property(T.id, 8).next() + created1 = await g.addE("created").from_(person1).to(software1).property("weight", 0.4).property(T.id, 9).next() + created2 = await g.addE("created").from_(person3).to(software2).property("weight", 1.0).property(T.id, 10).next() + created3 = await g.addE("created").from_(person3).to(software1).property("weight", 1.0).property(T.id, 11).next() + created4 = await g.addE("created").from_(person4).to(software1).property("weight", 0.2).property(T.id, 12).next() + + event_loop.run_until_complete(create_graph()) + + yield -- GitLab