def test_directGetSchema(mocked_requests): WOQLClient.directGetSchema("http://localhost:6363/myFirstTerminusDB", "directCallKey") requests.get.assert_called_once_with( 'http://localhost:6363/myFirstTerminusDB/schema?terminus%3Aencoding=terminus%3Aturtle', headers={'Authorization': 'Basic OmRpcmVjdENhbGxLZXk='})
def test_createDatabaseConnectMode(mocked_requests): __woqlClient__ = WOQLClient(server="http://localhost:6363", key='mykey') print('__woqlClient__', __woqlClient__.conConfig.serverURL) __woqlClient__.connect() requests.get.assert_called_once_with( 'http://localhost:6363/', headers={'Authorization': 'Basic Om15a2V5'})
def test_directDeleteDatabase(mocked_requests): WOQLClient.directDeleteDatabase("http://localhost:6363/myFirstTerminusDB", "mykey") requests.delete.assert_called_once_with( 'http://localhost:6363/myFirstTerminusDB', headers={'Authorization': 'Basic Om15a2V5'})
def test_Connection(mocked_requests, monkeypatch): __woqlClient__ = WOQLClient() __woqlClient__.connect("http://localhost:6363", 'mykey') with open('tests/connectionDictionary.json') as json_file: dictTest = json.load(json_file) monkeypatch.setattr(__woqlClient__.conCapabilities, "connection", dictTest) assert (dictTest == __woqlClient__.conCapabilities.connection) == True
def test_deleteDatabase(mocked_requests, mocked_requests2, monkeypatch): __woqlClient__ = WOQLClient(server="http://localhost:6363", key="mykey") __woqlClient__.connect() monkeypatch.setattr(__woqlClient__.conCapabilities, "capabilitiesPermit", mock_func_with_1arg) monkeypatch.setattr(__woqlClient__.conCapabilities, "removeDB", mock_func_no_arg) __woqlClient__.deleteDatabase("myFirstTerminusDB") requests.delete.assert_called_once_with( 'http://localhost:6363/myFirstTerminusDB', headers={'Authorization': 'Basic Om15a2V5'})
def test_getSchema(mocked_requests, monkeypatch): __woqlClient__ = WOQLClient(server="http://localhost:6363", key="mykey", db='myFirstTerminusDB') __woqlClient__.connect() #getSchema with no parameter monkeypatch.setattr(__woqlClient__.conCapabilities, "capabilitiesPermit", mock_func_with_1arg) __woqlClient__.getSchema() requests.get.assert_called_with( 'http://localhost:6363/myFirstTerminusDB/schema?terminus%3Aencoding=terminus%3Aturtle', headers={'Authorization': 'Basic Om15a2V5'})
import pytest import unittest.mock as mock from woqlclient import WOQLQuery from woqlclient import WOQLClient test_client = WOQLClient(server="http://*****:*****@mock.patch('requests.get') def test_database_document_id(mocked_requests): woqlObject=WOQLQuery().limit(2).start(0) #woqlObject.execute(test_client) assert True class TestPreRollQuery: def test_get_everything_method(self): woqlObject=WOQLQuery().limit(2).start(0) jsonObj={ 'limit': [ 2, { 'start': [ 0, {"quad": ["v:Subject", "v:Predicate", "v:Object", "db:Graph" ] } ] } ] } assert woqlObject.get_everything("Graph").json() == jsonObj def test_get_all_documents_method(self): woqlObject=WOQLQuery().limit(2).start(0) jsonObj={ 'limit': [ 2, { 'start': [ 0, { "and": [ { "triple": [ "v:Subject", "rdf:type", "v:Type"] }, { "sub": ["v:Type", "tcs:Document" ] } ] } ] } ] } assert woqlObject.get_all_documents().json() == jsonObj def test_document_metadata_method(self): woqlObject=WOQLQuery().limit(2).start(0) jsonObj={ 'limit': [ 2, { 'start': [ 0, { "and": [
print("read types from csv and construct WOQL objects") types = pd.read_csv("all-layers-types.csv") types["WOQLObject"] = types.apply(construct_objects, axis=1) print("read perperties from csv and construct WOQL objects") properties = pd.read_csv("all-layers-properties.csv") properties["WOQLObject"] = properties.apply(construct_objects, axis=1) print("create Domain and Range object for properties") properties["WOQLObject_DR"] = properties.apply(construct_prop_dr, axis=1) print("create types addon") types["addon"] = types.apply(construct_type_addon, axis=1, type_id=types.id) print("create properties addon") properties["addon"] = properties.apply(construct_property_addon, axis=1, type_id=types.id) print("create db and schema") client = WOQLClient() client.connect(server_url, key) client.deleteDatabase(dbId) client.createDatabase(dbId, "Schema.org") create_schema_from_queries(client, list(types["WOQLObject"])) create_schema_from_queries(client, list(properties["WOQLObject"])) create_schema_from_addon(client, list(properties["WOQLObject_DR"])) create_schema_from_addon(client, list(types["addon"])) create_schema_from_addon(client, list(properties["addon"]))
WOQLObj.property('dateTimeValue', date_value)) return for prop in data['properties']: extract_data(data['properties'][prop], id + prop + '/') WOQLObj = WOQLObj.property('http://schema.org/' + prop, 'doc:' + id + prop + '/') execution_queue.append(WOQLObj) else: if '://' in data: WOQLObj = WOQLQuery().insert('doc:' + id, 'http://schema.org/URL') else: WOQLObj = WOQLQuery().insert('doc:' + id, 'http://schema.org/Text') data_obj = {"@value": data, "@type": "xsd:string"} execution_queue.append(WOQLObj.property('stringValue', data_obj)) extract_data(data['microdata'][0]) #for item in execution_queue[0:]: # print(item.json()) # print() pp.pprint(WOQLQuery().when(True).woql_and(*execution_queue).json()) client = WOQLClient() client.connect(server_url, key) #for item in execution_queue[0:]: #print(item.json()) client.update(WOQLQuery().when(True).woql_and(*execution_queue).json(), dbId) #WOQLQuery().when(True).woql_and(*execution_queue).execute(client)
def test_directCreateDatabase(mocked_requests): WOQLClient.directCreateDatabase("http://localhost:6363/myFirstTerminusDB", "my first terminusDB", "mykey", comment="test terminusDB")
def test_DirectConnect(mocked_requests): WOQLClient.directConnect("http://localhost:6363", "mykey")
def test_ConnectionError(): __woqlClient__ = WOQLClient() print("___MOCKED______", mocked_requests('http://...').status_code)