Skip to content

Commit

Permalink
Use docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
acoburn committed Dec 13, 2018
1 parent f1b4917 commit 07f4d14
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 68 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ services:
- docker

before_install:
- docker pull trellisldp/trellis
- docker run -d -p 127.0.0.1:8080:8080/tcp trellisldp/trellis
- docker-compose --version
- docker-compose up -d
- docker ps -a

script:
- sleep 20
- python setup.py test
- sleep 60
- python setup.py test -a "--baseurl=http://localhost:8080/"
- python setup.py test -a "--baseurl=http://localhost/"
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3"
services:
trellis:
image: trellisldp/trellis:latest
ports:
- 8080:8080
trellis-db:
image: trellisldp/trellis-ext-db:latest
environment:
TRELLIS_DB_USERNAME: trellis
TRELLIS_DB_PASSWORD: trellis
TRELLIS_DB_URL: jdbc:postgresql://db/trellis
ports:
- 80:8080
depends_on:
- db
db:
image: postgres
environment:
POSTGRES_DB: trellis
POSTGRES_PASSWORD: trellis
POSTGRES_USER: trellis

10 changes: 3 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ class PyTest(TestCommand):

def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = []

def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
self.pytest_args = ""

def run_tests(self):
import shlex
import pytest

errno = pytest.main(self.pytest_args)
errno = pytest.main(shlex.split(self.pytest_args))
sys.exit(errno)

setup(name='pytrellis-test',
Expand Down
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest

def pytest_addoption(parser):
parser.addoption(
"--baseurl", action="store", default="http://localhost:8080/")

@pytest.fixture
def baseurl(request):
return request.config.getoption("--baseurl")


112 changes: 55 additions & 57 deletions tests/test_container.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,60 @@
import unittest
import pytest
import requests
from requests.utils import parse_header_links


class TestContainer(unittest.TestCase):

ROOT = "http://localhost:8080/";

def test_get_container(self):
r = requests.get(self.ROOT)

self.assertEqual(200, r.status_code)
self.assertEqual("text/turtle", r.headers['content-type'])
links = parse_header_links(r.headers['link'])
types = [l['url'] for l in links if (l['rel'] == 'type')]
self.assertTrue("http://www.w3.org/ns/ldp#BasicContainer" in types)
self.assertTrue("http://www.w3.org/ns/ldp#Resource" in types)

def test_get_json_ld(self):
r = requests.get(self.ROOT, headers={"accept": "application/ld+json"})
self.assertEqual(200, r.status_code)
self.assertEqual("application/ld+json", r.headers['content-type'])

def test_post_binary(self):
headers = {
"content-type": "text/plain",
"link": "<http://www.w3.org/ns/ldp#NonRDFSource>; rel='type'"}
data = "A simple file."
r = requests.post(self.ROOT, headers=headers, data=data)
self.assertEqual(201, r.status_code)
location = r.headers['location']

r = requests.get(location)
self.assertEqual(200, r.status_code)
self.assertEqual("text/plain", r.headers['content-type'])
self.assertEqual(data, r.text)

r = requests.get(self.ROOT, headers={"accept":"application/ld+json"})
d = r.json()
self.assertTrue(location in d['contains'])

def test_post_rdf(self):
headers = {
"content-type": "text/turtle",
"link": "<http://www.w3.org/ns/ldp#RDFSource>; rel='type'"}
data = "<> a <http://example.com/TestResource> ."
r = requests.post(self.ROOT, headers=headers, data=data)
self.assertEqual(201, r.status_code)
location = r.headers['location']

r = requests.get(location, headers={"accept":"application/ld+json"})
self.assertEqual(200, r.status_code)
self.assertEqual("application/ld+json", r.headers['content-type'])
d = r.json()
self.assertEqual("http://example.com/TestResource", d['@type'])

r = requests.get(self.ROOT, headers={"accept":"application/ld+json"})
d = r.json()
self.assertTrue(location in d['contains'])
ROOT = "http://localhost:8080/";


def test_get_container(baseurl):
r = requests.get(baseurl)

assert 200 == r.status_code
assert "text/turtle" == r.headers['content-type']
links = parse_header_links(r.headers['link'])
types = [l['url'] for l in links if (l['rel'] == 'type')]
assert "http://www.w3.org/ns/ldp#BasicContainer" in types
assert "http://www.w3.org/ns/ldp#Resource" in types

def test_get_json_ld():
r = requests.get(ROOT, headers={"accept": "application/ld+json"})
assert 200 == r.status_code
assert "application/ld+json" == r.headers['content-type']

def test_post_binary():
headers = {
"content-type": "text/plain",
"link": "<http://www.w3.org/ns/ldp#NonRDFSource>; rel='type'"}
data = "A simple file."
r = requests.post(ROOT, headers=headers, data=data)
assert 201 == r.status_code
location = r.headers['location']

r = requests.get(location)
assert 200 == r.status_code
assert "text/plain" == r.headers['content-type']
assert data == r.text

r = requests.get(ROOT, headers={"accept":"application/ld+json"})
d = r.json()
assert location in d['contains']

def test_post_rdf():
headers = {
"content-type": "text/turtle",
"link": "<http://www.w3.org/ns/ldp#RDFSource>; rel='type'"}
data = "<> a <http://example.com/TestResource> ."
r = requests.post(ROOT, headers=headers, data=data)
assert 201 == r.status_code
location = r.headers['location']

r = requests.get(location, headers={"accept":"application/ld+json"})
assert 200 == r.status_code
assert "application/ld+json" == r.headers['content-type']
d = r.json()
assert "http://example.com/TestResource" == d['@type']

r = requests.get(ROOT, headers={"accept":"application/ld+json"})
d = r.json()
assert location in d['contains']


0 comments on commit 07f4d14

Please sign in to comment.