How can i use OR condition in match? - dsl

I am trying to execute this code:
When def responseFromAuthenticatedExternalWSO2Gateway = call read('classpath:examples/Services/InvokeAuthenticatedQantasExternalWSO2Gateway.feature') {'domain': '#(domain)' , 'basepath': '#(basepath)' , 'path': '#(path)' , 'externalGatewayResponse': '#(externalGatewayResponse)' , 'method': '#(requestMethod)' , 'accessTokenforSandbox': '#(accessTokenforSandbox)' }
Then retry until responseFromExternalWSO2Gateway.responseStatus == 404 || responseFromExternalWSO2Gateway.responseStatus == 200
But this '||' OR condition is not working with match eventhough '&&' AND condition works.
Is there any workaround for this ?

Sorry, the retry until is not designed to work with a request made in a call. It has to be declared before you do * method.
Also I have no idea what you mean by "'&&' AND condition works"
Please make the question more clear or follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Related

NodeJS using single quotes instead of double quotes in object [Answered]

[Answered by: Loulou BadWeed]
Hi #NickP. , did you stringify/serialize your payload before passing
it in the fetch body ? Does not seem the case from your example and I
don't think fetch does that for you. Try JSON.stringify(config) in the
body argument of the fetch function
I have a "small" problem.
I can't figure out, why nodejs uses single quotes for the string value instead of double quotes...
My Code
let config = {}
config["active"] = 1
config["domain"] = req.body.domain
config["mailboxes"] = req.body.mailboxes
config["defquota"] = req.body.defquota
config["maxquota"] = req.body.maxquota
config["quota"] = req.body.quota
config["restart_sogo"] = 10
console.log(req.body.domain)
console.log(config)
What I input:
{
"domain": "domain.tld",
"mailboxes": 10,
"defquota": 512,
"maxquota": 1024,
"quota": 10240
}
What I get:
{
active: 1,
domain: 'domain.tld',
mailboxes: 10,
defquota: 512,
maxquota: 1024,
quota: 10240,
restart_sogo: 10
}
The problem I have with this, is that the mailcow api doesn't like single quotes in the request body. :) Does anyone know, why this happens and can help me?
I tried replacing the single quotes with str.replace() or str.replaceAll(). But that didn't work. I tried using both types where I used the '' outside of the "".
I also already asked ChatGPT for help, but the results were just the replace and replaceAll...
PS: It's 4:30 AM when I wrote this. I'm not at 100% of my usual capacity. So please don't hate me for my question.

Binance API in python APIError(code=-1121): Invalid symbol

I am trying to code a binance Buy function. However the code
from binance.enums import *
order = client.create_order(symbol='DOGEUSDT', side = 'BUY', type = 'MARKET', quantity = 475, timeInForce='GTC')
this code outputs > APIError(code=-1121): Invalid symbol.
Also, for the same symbol,
print(client.get_symbol_info(symbol="DOGEUSDT"))
ouptuts > None
The symbol DOGEUSDT exists is the orderbook. https://api.binance.com/api/v3/ticker/bookTicker
I dont know why the same symbol I get from binance is invalid.
Are you using the testnet? I had the same error, however when I removed testnet=True from the client initialization the error was resolved.
two things can happen
client.API_URL = https://testnet.binance.vision/api
in that case change it to
https://api.binance.com/api
Client(api_key, secret_key, testnet=True)
in that case change testnet=False or delete it

Issues using UNWIND to load data to Neo4j using python

I am trying to load neo4j db using CSV file from python. I am able to connect and load the data without using UNWIND operation. But I want to use it for a faster load. I am getting the following error upon trying to use it.
{code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input '': expected whitespace, '.', node labels, '[', '^', '*', '/', '%', '+', '-', "=~", IN, STARTS, ENDS, CONTAINS, IS, '=', '~', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR or AS (line 1, column 16 (offset: 15))
" UNWIND {data1} as node"
^}
I have the following code where I am using UNWIND. This is just a small sample I am trying to test out with.
cq1=""" UNWIND {data1}​ as node
MERGE (n:Person {id : node.ID}​)
SET
n.gender = node.GENDER"""
list_dicts_data1 = [{"ID": '1',"GENDER": 'Male'}]
graph.run(cq1, data1 = list_dicts_data1)
Any suggestions what is causing this error and how do I fix it?
I can't read the error clearly due to bad formatting, but which version of Neo4j are you running? The parameter syntax changed a while ago from {var} to $var. That might be the cause.
Also, have you considered using py2neo's bulk load API, which wraps this kind of statement for you?
https://py2neo.org/2021.0/bulk/index.html

Show expected and actual values for assertion failures

When writing assertions for my tests, the assertion failures don't provide enough information without needing to open an IDE and start debugging.
For example, I have some code that uses the 'assert' library:
import * as assert from 'assert'
// some code
assert(someObject.getValue() === 0)
I just get
AssertionError [ERR_ASSERTION]: false == true
+ expected - actual
-false
+true
This error message isn't really meaningful. As a workaround, I added it in the message in the assertion:
assert(someObject.getValue() === 0,
'\nActual: ' + someObject.getValue() +
'\nExpected: ' + 0)
Is there a better, cleaner way to just show the expected & actual values without overriding the message on every assertion? I also tried to create an assert wrapper, but I wasn't able to extract the actual and expected values from the expression.
EDIT: assert.strictEqual resolves this issue for equalities only. But as soon as any other operator is included, then we have the same issue (e.g. assert(someObject.getValue() > 0)
Any advice would be appreciated.
Thanks!
You can use assert.strictEqual(actual, expected[, message]) to get actual/expected error messages without the need of the third message argument:
assert.strictEqual(someObject.getValue(), 0)
You'd get an error message such as:
// AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
//
// 1 !== 0
Hopefully that helps!

How to run specified step in SoapUI according testcase result

I have project in soapui with more testcases. After running each testcase I need to run one of two http request, depending on results of steps. So if one or more steps in testcase failed, I need to run httprequest1 and if all steps passed I need to run httprequest2. How can I do this? I have tried many scripts... for now my best solution is something like this, just add groovy script at the end of test case. Problem is that it is checking only last step. I have tried many other solutions, but nothing was working for me. Can somebody help me with this? Thank you
def lastResult = testRunner.getResults().last()
def lastResultStatus = lastResult.getStatus().toString()
log.info 'Test + lastResultStatus
if( lastResultStatus == 'FAILED' )
{
testRunner.gotoStepByName( 'httprequest1' )
testRunner.testCase.testSteps["httprequest2"].setDisabled(true)
}
else
{
testRunner.gotoStepByName( 'httprequest2' )
}
another solution that I have tried:
for( r in testRunner.results )
result = r.status.toString()
log.info result
if( result == 'FAILED' )
{
testRunner.gotoStepByName( 'httprequest1' )
testRunner.testCase.testSteps["httprequest2"].setDisabled(true)
}
else
{
testRunner.gotoStepByName( 'httprequest2' )
}
Like it was mentioned in the comment, and based on the details shared in the comments, Conditional GoTo test step can be used. However, it may required multiple of them. Instead Groovy Script can be the best way in this scenario.
Here are the details assuming the following are the steps in the test case.
Test Case:
request step1
request step2
groovy script step (the proposed script to handle the scenario)
request1 step if above step1 & step2 are successful
request2 step otherwise
following step x
following step y
Here is the pseudo code for the proposed Groovy Script mentioned in #3.
Evaluate the previous test step execution result, like what you currently doing.
Based on the condition, run the test step #4 if true, run step #5 otherwise. Here note that do not use gotoStepByName method, instead run step by its name. See sample #15 here
Once the above if ..else is done, then use gotoStepByName to continue the steps #6, #7 (of course, if any).
NOTE: If gotoStepByName is used to run a step in groovy step, then the control will not come back.
Use a testcase teardown to call the step, since you have to do it for all test cases. The teardown script will look something like this:
if(testRunner.status.toString() == "FAILED"){
testRunner.runTestStepByName( "httprequest1")
println "in if"
}else{
testRunner.runTestStepByName( "httprequest2")
println "in else"
}
Note that you have to use the SoapUI Runner to trigger the testcase / suite and the difference in method being called.

Resources