Skip to content

Commit 3a89099

Browse files
committed
Refactoring folder_utils
1 parent 9ebe366 commit 3a89099

2 files changed

Lines changed: 56 additions & 6 deletions

File tree

src/solid/utils/folder_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@
77
LDP = Namespace("http://www.w3.org/ns/ldp#")
88
container_types = [URIRef('http://www.w3.org/ns/ldp#Container'), URIRef('http://www.w3.org/ns/ldp#BasicContainer')]
99

10+
1011
# FIXME
1112
# def parse_folder_response(folder_response: Response, url) -> FolderData:
1213
def parse_folder_response(folder_response: Response, url):
14+
return _parse_folder_response(folder_response.text, url)
15+
16+
17+
def _parse_folder_response(text, url):
1318
from solid.solid_api import FolderData, Item
1419

15-
g = Graph().parse(data=folder_response.text, publicID=url, format='turtle')
20+
g = Graph().parse(data=text, publicID=url, format='turtle')
1621

1722
def is_type(sub, type) -> bool:
1823
return (sub, RDF.type, type) in g

tests/test_folder_utils.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,54 @@
1-
from solid.utils.folder_utils import parse_folder_response
2-
import httpx
1+
from solid.utils.folder_utils import _parse_folder_response
2+
3+
TEXT = '''
4+
@prefix : <#>.
5+
@prefix dct: <http://purl.org/dc/terms/>.
6+
@prefix ldp: <http://www.w3.org/ns/ldp#>.
7+
@prefix stat: <http://www.w3.org/ns/posix/stat#>.
8+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
9+
@prefix test: <>.
10+
@prefix sub: <subdir/>.
11+
@prefix jpeg: <http://www.w3.org/ns/iana/media-types/image/jpeg#>.
12+
@prefix tur: <http://www.w3.org/ns/iana/media-types/text/turtle#>.
13+
@prefix m: <http://www.w3.org/ns/iana/media-types/text/markdown#>.
14+
15+
test:
16+
a ldp:BasicContainer, ldp:Container;
17+
dct:modified "2021-07-06T03:24:55Z"^^xsd:dateTime;
18+
ldp:contains <picture.jpg>, <picture.jpg2>, test:qq, sub:, <testfile.md>;
19+
stat:mtime 1625541895.566;
20+
stat:size 4096.
21+
<picture.jpg>
22+
a jpeg:Resource, ldp:Resource;
23+
dct:modified "2021-06-24T02:47:10Z"^^xsd:dateTime;
24+
stat:mtime 1624502830.078;
25+
stat:size 412944.
26+
<picture.jpg2>
27+
a jpeg:Resource, ldp:Resource;
28+
dct:modified "2021-07-05T03:49:57Z"^^xsd:dateTime;
29+
stat:mtime 1625456997.73;
30+
stat:size 0.
31+
test:qq
32+
a tur:Resource, ldp:Resource;
33+
dct:modified "2021-06-22T11:08:50Z"^^xsd:dateTime;
34+
stat:mtime 1624360130.12;
35+
stat:size 0.
36+
sub:
37+
a ldp:BasicContainer, ldp:Container, ldp:Resource;
38+
dct:modified "2021-07-06T03:24:55Z"^^xsd:dateTime;
39+
stat:mtime 1625541895.566;
40+
stat:size 4096.
41+
<testfile.md>
42+
a m:Resource, ldp:Resource;
43+
dct:modified "2021-06-22T10:00:07Z"^^xsd:dateTime;
44+
stat:mtime 1624356007.481;
45+
stat:size 44.
46+
'''
47+
48+
URL = 'https://tim.solidcommunity.net/test/'
349

450

551
def test_parse_folder_response():
6-
url = 'https://dahanhsi.solidcommunity.net/test/'
7-
resp = httpx.get(url)
8-
fold_data = parse_folder_response(resp, url)
52+
fold_data = _parse_folder_response(TEXT, URL)
53+
# TODO: assert result
954
pass

0 commit comments

Comments
 (0)