Skip to content

Commit

Permalink
py3.10 test msg & non_member (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-marqh authored Jul 27, 2023
1 parent fa25216 commit 05989c5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pre-commit-hook-on-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ jobs:
python3 -m uploadChanges "$UNAME" "$TPASS" /tmp/reg_test_results
- name: Test
run: |
python3 -m check_urls
nofails=1 python3 -m check_urls
22 changes: 14 additions & 8 deletions check_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,18 @@ def check_result(self, result, expected, uploads, identityURI):
except AssertionError:
ufile = '{}.ttl'.format(identityURI.split(rooturl)[1])
uploads['PUT'].append(ufile)
msg = lbr + lbe.join([g.serialize(format='n3') for g in
rdflib.compare.graph_diff(result, expected)])
# Alternative code for older versions of rdflib:
# msg = lbr + lbe.join([g.serialize(format='n3').decode("utf-8") for
# g in
# rdflib.compare.graph_diff(result,expected)[1:]])

if nofails:
self.assertTrue(True)
else:
self.assertTrue(rdflib.compare.isomorphic(result, expected),
lbr + lbe.join([g.serialize(format='n3').decode("utf-8") for g in
rdflib.compare.graph_diff(result,
expected)[1:]]))
self.assertTrue(rdflib.compare.isomorphic(result, expected), msg)


with open('prodRegister', 'r') as fh:
rooturl = fh.read().split('\n')[0]
Expand Down Expand Up @@ -139,17 +144,18 @@ def entity_exists(self):
def make_another_test(infile):
identityURI = copy.copy(identity)
def entity_consistent(self):
headers={'Accept':'text/turtle'}
headers={'Accept':'text/turtle',
'Cache-Control': 'private, no-store, no-cache'}
regr = session.get(identityURI, headers=headers)
ufile = '{}.ttl'.format(identityURI.split(rooturl)[1].lstrip('/'))
result_rdfgraph = rdflib.Graph()

result_rdfgraph.parse(ufile, publicID=identityURI, format='n3')
if not nofails:
msg = '{} returned {} not 200'.format(identityURI,
regr.status_code)
assert(regr.status_code == 200), msg
if regr.status_code == 200:
result_rdfgraph = rdflib.Graph()

result_rdfgraph.parse(ufile, publicID=identityURI, format='n3')
expected = session.get(identityURI, headers=headers)
expected_rdfgraph = rdflib.Graph()
expected_rdfgraph.parse(data=expected.text, format='n3')
Expand Down
20 changes: 19 additions & 1 deletion uploadChanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ def put(session, url, payload):
if response.status_code != 200:
raise ValueError('Cannot PUT to {}, it does not exist.'.format(url))
res = session.put(url, headers=headers, data=payload.encode("utf-8"))
print('\t' + str(res.status_code))
if res.status_code != 204:
print('\t' + res.text)

def put_non_member(session, url, payload):
headers={'Content-type':'text/turtle', 'charset':'utf-8'}
response = session.get(url, headers=headers)
if response.status_code != 200:
raise ValueError('Cannot PUT to {}, it does not exist.'.format(url))
res = session.put(url + '?non-member-properties', headers=headers,
data=payload.encode("utf-8"))
print('\t' + str(res.status_code))
if res.status_code != 204:
print('\t' + res.text)

def post_uploads(session, rootURL, uploads):
for postfile in uploads:
Expand All @@ -74,7 +88,11 @@ def put_uploads(session, rootURL, uploads):
relID = putfile.replace('.ttl', '')
url = '{}{}'.format(rootURL, relID)
print(url)
put(session, url, pdata)
if os.path.exists('.{}'.format(putfile.replace('.ttl', ''))):
# then it is a register, so, only non-member-properties can be PUT
put_non_member(session, url, pdata)
else:
put(session, url, pdata)

if __name__ == '__main__':
with open('prodRegister', 'r', encoding='utf-8') as fh:
Expand Down

0 comments on commit 05989c5

Please sign in to comment.