-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | ||
|
||
|