Skip to content

Commit

Permalink
Adds data source testing
Browse files Browse the repository at this point in the history
  • Loading branch information
scardena committed May 3, 2021
1 parent 17c9999 commit 44bf6c8
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 20 deletions.
13 changes: 7 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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

11 changes: 11 additions & 0 deletions dockerfiles/dockerfile-mysql
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions dockerfiles/dockerfile-python
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM python

RUN apt-get update && apt-get install -y vim nano

COPY . /var/pystardog

WORKDIR /var/pystardog
Expand Down
3 changes: 2 additions & 1 deletion dockerfiles/dockerfile-stardog
Original file line number Diff line number Diff line change
@@ -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
Binary file added dockerfiles/mysql-connector-java-5.1.48.jar
Binary file not shown.
14 changes: 13 additions & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,16 @@ def conn_string(pytestconfig):
'username': pytestconfig.getoption("username"),
'password': pytestconfig.getoption("passwd")
}
return conn
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
19 changes: 19 additions & 0 deletions test/data/beatles.sql
Original file line number Diff line number Diff line change
@@ -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);
39 changes: 39 additions & 0 deletions test/data/music_schema.sql
Original file line number Diff line number Diff line change
@@ -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)
);
30 changes: 18 additions & 12 deletions test/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
import os


import stardog.admin
import stardog.connection as connection
import stardog.content as content
Expand Down Expand Up @@ -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,
Expand All @@ -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




0 comments on commit 44bf6c8

Please sign in to comment.