diff --git a/docker-compose.yml b/docker-compose.yml index 03cf854..784dcd0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,7 @@ +# Note that circleci executor does not allow to volume mounting, hence the volume block can't be used here. +# https://support.circleci.com/hc/en-us/articles/360007324514-How-can-I-use-Docker-volume-mounting-on-CircleCI- +# For this reason, we are creating specific dockerfiles, and building the images from them, copying the files in the images +# instead of mounting them. version: "3.3" services: stardog: @@ -13,11 +17,8 @@ services: command: ["./utils/run_tests.sh"] container_name: pystardog_tests mysql: - image: "mysql:8.0.3" - environment: - - MYSQL_ROOT_PASSWORD=rootpw - - MYSQL_DATABASE=test_db - - MYSQL_USER=user - - MYSQL_PASSWORD=passw0rd + build: + context: . + dockerfile: dockerfiles/dockerfile-mysql container_name: pystardog_mysql diff --git a/dockerfiles/dockerfile-mysql b/dockerfiles/dockerfile-mysql new file mode 100644 index 0000000..b8c8b71 --- /dev/null +++ b/dockerfiles/dockerfile-mysql @@ -0,0 +1,11 @@ +FROM mysql:8.0.3 + +RUN apt-get update && apt-get install -y vim nano + +COPY ./test/data/beatles.sql /docker-entrypoint-initdb.d/2-beatles.sql +COPY ./test/data/music_schema.sql /docker-entrypoint-initdb.d/1-music_schema.sql + +ENV MYSQL_ROOT_PASSWORD=rootpw +ENV MYSQL_DATABASE=music +ENV MYSQL_USER=user +ENV MYSQL_PASSWORD=pass diff --git a/dockerfiles/dockerfile-python b/dockerfiles/dockerfile-python index 5e85136..1504b2e 100644 --- a/dockerfiles/dockerfile-python +++ b/dockerfiles/dockerfile-python @@ -1,5 +1,7 @@ FROM python +RUN apt-get update && apt-get install -y vim nano + COPY . /var/pystardog WORKDIR /var/pystardog diff --git a/dockerfiles/dockerfile-stardog b/dockerfiles/dockerfile-stardog index 8b10fa3..8503299 100644 --- a/dockerfiles/dockerfile-stardog +++ b/dockerfiles/dockerfile-stardog @@ -1,3 +1,4 @@ FROM stardog/stardog:latest -COPY . /var/opt/stardog +COPY stardog-license-key.bin /var/opt/stardog +COPY mysql-connector-java-5.1.48.jar /opt/stardog/server/dbms \ No newline at end of file diff --git a/dockerfiles/mysql-connector-java-5.1.48.jar b/dockerfiles/mysql-connector-java-5.1.48.jar new file mode 100644 index 0000000..fcd53a5 Binary files /dev/null and b/dockerfiles/mysql-connector-java-5.1.48.jar differ diff --git a/test/conftest.py b/test/conftest.py index 0cc731d..c022e37 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -12,4 +12,16 @@ def conn_string(pytestconfig): 'username': pytestconfig.getoption("username"), 'password': pytestconfig.getoption("passwd") } - return conn \ No newline at end of file + return conn + + +@pytest.fixture +def ds_options(): + options = { + "namespaces": "stardog=tag:stardog:api", + "jdbc.driver": "com.mysql.jdbc.Driver", + "jdbc.username": "user", + "jdbc.password": "pass", + "jdbc.url": "jdbc:mysql://pystardog_mysql/music" + } + return options diff --git a/test/data/beatles.sql b/test/data/beatles.sql new file mode 100644 index 0000000..2740c10 --- /dev/null +++ b/test/data/beatles.sql @@ -0,0 +1,19 @@ +insert into Artist values (1, 'John Lennon', 'John Winston Ono Lennon, MBE (born John Winston Lennon; 9 October 1940 – 8 December 1980) was an English singer and Songwriter who co-founded the Beatles (1960-70), the most commercially successful band in the history of popular music. With fellow member Paul McCartney, he formed a celebrated songwriting partnership.', 1); +insert into Artist values (2, 'Paul McCartney', 'Sir James Paul McCartney, MBE (born 18 June 1942) is an English singer-Songwriter, multi-instrumentalist, and composer. With John Lennon, George Harrison, and Ringo Starr, he gained worldwide fame with the rock band the Beatles, one of the most popular and influential groups in the history of pop music. His songwriting partnership with Lennon is one of the most celebrated of the 20th century. After the band''s break-up, he pursued a solo career and formed the band Wings with his first wife, Linda, and Denny Laine.', 1); +insert into Artist values (3, 'Ringo Starr', '"Richard Starkey, MBE (born 7 July 1940), known professionally as Ringo Starr, is an English musician, singer, Songwriter and actor who gained worldwide fame as the drummer for the Beatles. He occasionally sang lead vocals, usually for one song on an album, including "With a Little Help from My Friends", "Yellow Submarine" and their cover of "Act Naturally". He also wrote the Beatles'' songs "Don''t Pass Me By" and "Octopus''s Garden", and is credited as a co-writer of others, including "What Goes On" and "Flying".', 1); +insert into Artist values (4, 'George Harrison', 'George Harrison, MBE (25 February 1943 – 29 November 2001) was an English guitarist, singer, Songwriter, and music and film producer who achieved international fame as the lead guitarist of the Beatles. Often referred to as "the quiet Beatle", Harrison embraced Hindu mythology and helped broaden the horizons of his fellow Beatles as well as their Western audience by incorporating Indian instrumentation in their music. Although the majority of the Beatles'' songs were written by John Lennon and Paul McCartney, most Beatles albums from 1965 onwards contained at least two Harrison compositions. His songs for the group included "Taxman", "Within You Without You", "While My Guitar Gently Weeps", "Here Comes the Sun", and "Something", the last of which became the Beatles'' second-most covered song"', 1); +insert into Artist values (5, 'The Beatles', 'The Beatles were the greatest rock band of all time. Formed in Liverpool, England in 1960, the group was composed of members John Lennon, Paul McCartney, George Harrison and Ringo Starr. Rooted in skiffle, beat, and 1950s rock and roll, the Beatles later experimented with several musical styles, ranging from pop ballads and Indian music to psychedelia and hard rock, often incorporating classical elements and unconventional recording techniques in innovative ways. In the early 1960s, their enormous popularity first emerged as "Beatlemania", but as the group''s music grew in sophistication, led by primary Songwriters Lennon and McCartney, they came to be perceived as an embodiment of the ideals shared by the counterculture of the 1960s.', 2); + +insert into Membership values (1, 5); +insert into Membership values (2, 5); +insert into Membership values (3, 5); +insert into Membership values (4, 5); + +insert into Album values (1, "Please Please Me", "1963-03-22", 5); +insert into Album values (2, "McCartney", "1970-04-17", 2); +insert into Album values (3, "Imagine", "1971-10-11", 1); + +insert into Track values (1, "Love Me Do", 1, 125); + +insert into Songwriter values (1, 1); +insert into Songwriter values (1, 2); \ No newline at end of file diff --git a/test/data/music_schema.sql b/test/data/music_schema.sql new file mode 100644 index 0000000..5467320 --- /dev/null +++ b/test/data/music_schema.sql @@ -0,0 +1,39 @@ +CREATE TABLE Artist ( + id INT, + name VARCHAR(30), + description VARCHAR(1024), + type INT, + PRIMARY KEY (id) +); + +CREATE TABLE Album ( + id INT, + name VARCHAR(30), + release_date DATE, + artist INT, + PRIMARY KEY (id), + FOREIGN KEY (artist) REFERENCES Artist (id) +); + +CREATE TABLE Membership ( + artist INT, + band INT, + FOREIGN KEY (band) REFERENCES Artist (id), + FOREIGN KEY (artist) REFERENCES Artist (id) +); + +CREATE TABLE Track ( + id INT, + name VARCHAR(30), + album INT, + length INT, + PRIMARY KEY (id), + FOREIGN KEY (album) REFERENCES Album (id) +); + +CREATE TABLE Songwriter ( + song INT, + writer INT, + FOREIGN KEY (writer) REFERENCES Artist (id), + FOREIGN KEY (song) REFERENCES Track (id) +); diff --git a/test/test_admin.py b/test/test_admin.py index 4475bb5..e7f1195 100644 --- a/test/test_admin.py +++ b/test/test_admin.py @@ -2,6 +2,7 @@ import datetime import os + import stardog.admin import stardog.connection as connection import stardog.content as content @@ -290,29 +291,21 @@ def test_stored_queries(admin): admin.clear_stored_queries() assert len(admin.stored_queries()) == 0 - -def test_virtual_graphs(admin): +@pytest.mark.skip(reason="Fix this tests, and test against a real VG: https://github.com/stardog-union/pystardog/issues/2") +def test_virtual_graphs(admin, ds_options): assert len(admin.virtual_graphs()) == 0 - options = { - "namespaces": "stardog=tag:stardog:api", - "jdbc.driver": "com.mysql.jdbc.Driver", - "jdbc.username": "admin", - "jdbc.password": "admin", - "jdbc.url": "jdbc:mysql://localhost/support" - } - vg = admin.virtual_graph('test') # TODO add VG to test server with pytest.raises( exceptions.StardogException, match='java.sql.SQLException'): admin.new_virtual_graph('vg', content.File('test/data/r2rml.ttl'), - options) + ds_options) with pytest.raises( exceptions.StardogException, match='java.sql.SQLException'): - vg.update('vg', content.File('test/data/r2rml.ttl'), options) + vg.update('vg', content.File('test/data/r2rml.ttl'), ds_options) with pytest.raises( exceptions.StardogException, @@ -333,3 +326,16 @@ def test_virtual_graphs(admin): exceptions.StardogException, match='Virtual Graph test Not Found!'): vg.delete() + +def test_data_source(admin, ds_options): + + ds = admin.new_datasource('music', ds_options) + assert len(admin.datasources()) == 1 + assert ds.name == 'music' + assert ds.get_options() == ds_options + ds.delete() + assert len(admin.datasources()) == 0 + + + +