def test_connectionConfig_noParameter(): connectionConfig = ConnectionConfig() """ you need to set the terminusServer and the terminusDB id """ with pytest.raises(InvalidURIError): connectionConfig.serverURL connectionConfig.dbID connectionConfig.schemaURL() connectionConfig.docURL() connectionConfig.queryURL() connectionConfig.dbURL() assert connectionConfig.connectedMode == True, "start value of connectedMode is True" assert connectionConfig.checkCapabilities == True, "start value of checkCapabilities is True" assert connectionConfig.includeKey == True, "start value of includeKey is True"
def test_set_getClientKey(): conConfig = ConnectionConfig(server="http://localhost:6363") conCapabilities = ConnectionCapabilities(conConfig) conCapabilities.setClientKey("mykey") serverURL = conConfig.serverURL assert conCapabilities.getClientKey(serverURL) == "mykey" with pytest.raises(APIError): assert conCapabilities.getClientKey("http://testServer")
def test_connectionConfig_withParameter(): startParameters = { "server": "http://localhost:6363/", "db": "myFirstTerminusDB", "doc": "chess", "connected_mode": False, "include_key": False, "checks_capabilities": False } connectionConfig = ConnectionConfig(**startParameters) assert connectionConfig.serverURL == "http://localhost:6363/" assert connectionConfig.dbID == "myFirstTerminusDB" assert connectionConfig.connectedMode == False assert connectionConfig.checkCapabilities == False assert connectionConfig.includeKey == False assert connectionConfig.dbURL( ) == "http://localhost:6363/myFirstTerminusDB", "dbURL" assert connectionConfig.schemaURL( ) == "http://localhost:6363/myFirstTerminusDB/schema", "schemaURL" assert connectionConfig.docURL( ) == "http://localhost:6363/myFirstTerminusDB/document/chess", "docURL" assert connectionConfig.queryURL( ) == "http://localhost:6363/myFirstTerminusDB/woql", "queryURL"
def test_deleteDatabaseForTheConnectionList(): conConfig = ConnectionConfig(server="http://localhost:6363", db="myFirstTerminusDB") conCapabilities = ConnectionCapabilities(conConfig, 'mykey') with open('tests/capabilitiesResponse.json') as json_file: capResponse = json.load(json_file) conCapabilities.addConnection(capResponse) assert ("doc:myFirstTerminusDB" in conCapabilities.connection["http://localhost:6363/"]) == True conCapabilities.removeDB() assert ("doc:myFirstTerminusDB" in conCapabilities.connection["http://localhost:6363/"]) == False
def test_capabilitiesPermit(): conConfig = ConnectionConfig(server="http://localhost:6363", db="myFirstTerminusDB") conCapabilities = ConnectionCapabilities(conConfig, 'mykey') with open('tests/capabilitiesResponseNoAllAction.json') as json_file: capResponse = json.load(json_file) conCapabilities.addConnection(capResponse) #if the action are not permits the method raise an Exception with pytest.raises(AccessDeniedError): conCapabilities.capabilitiesPermit(const.DELETE_DATABASE) with pytest.raises(AccessDeniedError): conCapabilities.capabilitiesPermit(const.DELETE_DOCUMENT) assert conCapabilities.capabilitiesPermit(const.CREATE_DATABASE) == True assert conCapabilities.capabilitiesPermit(const.CREATE_DOCUMENT) == True
def test_connectionCapabilities_noParameter(): conConfig = ConnectionConfig() """ the key is related with a server you have to set both of the method raise an APIerror """ with pytest.raises(InvalidURIError): conCapabilities = ConnectionCapabilities(conConfig, 'mykey') with pytest.raises(InvalidURIError): conCapabilities.getClientKey() assert conCapabilities.serverConnected() == False with pytest.raises(InvalidURIError): with open('tests/capabilitiesResponse.json') as json_file: capResponse = json.load(json_file) conCapabilities.addConnection(capResponse)
def test_addConnection(): #No server url in intialization conConfig = ConnectionConfig(server="http://localhost:6363") conCapabilities = ConnectionCapabilities(conConfig, 'mykey') assert ({ "http://localhost:6363/": { 'key': "mykey" } } == conCapabilities.connection) == True with open('tests/capabilitiesResponse.json') as json_file: capResponse = json.load(json_file) conCapabilities.addConnection(capResponse) with open('tests/connectionDictionary.json') as json_file: dictTest = json.load(json_file) assert (dictTest == conCapabilities.connection) == True #you have setServer or the serverConnected is False assert conCapabilities.serverConnected() == True assert conCapabilities.getClientKey() == "mykey"
def test_setServer(): connectionConfig = ConnectionConfig() connectionConfig.setServer("http://localhost:6363") assert connectionConfig.serverURL == "http://localhost:6363/"