Karate: While Validating The Response Not Able To Get The Correct Value - automation

Here I Have Defined A Few Variables:
def qantity1 = '1'
def price1 = '14.49'
def qantity2 = '1'
def price2 = '14.49'
def OutstandingAmount = qantity1 * price1 + qantity2 * price2
I'm expecting The Response Of Above Calculations To Come Out As '28.98' But I'm Getting It As 28.98 . Here Is An Actual Response From Console,
$.total.outstandingAmount, actual: '28.98', expected: 28.98, reason: not equal (String : Double)

Yes, the message is clear isn't it, you are matching a string with a number.
You can read this for reference: https://github.com/karatelabs/karate#type-conversion
Solution:
* def OutstandingAmount = (qantity1 * price1 + qantity2 * price2) + ''

Related

odoo 11 Expected singleton

guys why is this thing happening?
I'm getting this error!
raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: product.pricelist.item(8, 9)
this is the related code:
if price is not False:
if rule.compute_price == 'fixed':
price = convert_to_price_uom(rule.fixed_price)
elif rule.compute_price == 'percentage':
price = (price - (price * (rule.percent_price / 100))) or 0.0
**elif rule.compute_price == 'nettech':
if product.aed_is_true:
price_tempo = self.env['res.currency'].search([('name', '=', 'IRR')], limit=1).rate * product.aed_in_irr + product.sud2 + (((self.env['res.currency'].search([('name', '=', 'IRR')], limit=1).rate * product.aed_in_irr + product.sud2) * (product.sud-rule.product_sub) / 100)) or 0.0
price = round(price_tempo,-4)
elif not product.aed_is_true:
price = price**
Search the variable of the product.pricelist.item model and create a for loop on it.
You have this error because there is a variable that contains an object of two records and you are trying to get one value from both. For this reason you should create a loop to get the value from each object.

Karate: Remove a dynamic element from from JSON

* def res1 = {"member":{"muid":"MBR1"},"part":[{"PID":"M123"},{"supportedMembers":[{"muid":"MBR3","status":{"code":"A"}},{"muid":"MBR2","status":{"code":"I"}}]}]}
* def res2 = {"members":[{"member":{"muid":"MBR2","test":[{"EID":"E123"}]}},{"member":{"muid":"MBR3","test":[{"EID":"E123"}]}}]}
Karate: Match array elements of two different JSON
I have another requirement which is related to my earlier post.
* def id = res1.member.muid
I want to remove id from res2 response, which can be any where in res2.members.member, and do the matching with res1 to see the presence of muids
I tried something like below, but its not working:
* karate.remove('$res2.members[*]..muid','$.muid[id]')
Sample Code:
Feature: Validation
Scenario:
* def res1 = {"member":{"muid":"MBR1"},"part":[{"PID":"M123"},{"supportedMembers":[{"muid":"MBR3","status":{"code":"A"}},{"muid":"MBR2","status":{"code":"I"}}]}]}
* def res2 = {"members":[{"member":{"muid":"MBR2","test":[{"EID":"E123"}]}},{"member":{"muid":"MBR3","test":[{"EID":"E123"}]}}]}
* def id = res1.member.muid
* def res2ids = $res2.members[*]..muid
* def data2 = karate.mapWithKey(res2ids, 'muid')
* print data2
* def res2ids = karate.jsonPath(data2, "$[?(#.muid != '" + id+ "')]")
* def res2ids = $res2ids[*]..muid
* print res2ids
* match res1.part[1].supportedMembers[*].muid contains only res2ids

Filter a json with a variable inline not correct

I create a script to filter a list user that not include the specified one. But when I tried:
* def userId = response.data[0].id
* def filter = ''
* def users = get[0] response.data[?(#.id!="bd04b9f0-c254-4f23-9fed-6a0300692bbb")]
* print users.id
is correct
But I want re-use a value form previous step like:
* def userId = response.data[0].id
* def filter = 'bd04b9f0-c254-4f23-9fed-6a0300692bbb'
* def users = get[0] response.data[?(#.id!="#(filter)")]
* print users.id
Is incorrect
Read the docs please: https://github.com/intuit/karate#jsonpath-filters
* def users = karate.jsonPath(response, "$.data[?(#.id!='" + filter + "')]")[0]

PyQt exclusive OR in sql query

How can I make that if my first search shows results it doesn't do the second part of the query, but stops and displays results? I tried something like this, but it just gives me blank window and it's pretty chaotic:
def test_update(self):
projectModel = QSqlQueryModel()
projectModel.setQuery("""SELECT * FROM pacijent WHERE prezime = '%s' OR (prezime, 3) = metaphone('%s', 3) OR LEVENSHTEIN(LOWER(prezime), '%s') < 3 AND NOT (prezime = '%s' AND (prezime, 3) = metaphone('%s', 3) AND LEVENSHTEIN(LOWER(prezime), '%s') < 3)""" % (str(self.lineEdit.text()), str(self.lineEdit.text()), str(self.lineEdit.text()), str(self.lineEdit.text()), str(self.lineEdit.text()), str(self.lineEdit.text())))
global projectView
projectView = QtGui.QTableView()
projectView.setModel(projectModel)
projectView.show()
So, if it finds the exact value of attribute "prezime" it should display it, but if it doesn't it should call for more advance saerch tactics, such as metaphone and levenshtein.
EDIT:
I got it working like this:
ef search_data(self):
myQSqlQueryModel = QSqlQueryModel()
query = QSqlQueryModel()
global myQTableView
myQTableView = QtGui.QTableView()
querySuccess = False
for queryCommand in [""" SELECT * FROM "%s" WHERE "%s" = '%s' """ % (str(self.search_from_table_lineEdit.text()), str(self.search_where_lineEdit.text()), str(self.search_has_value_lineEdit.text()))]:
myQSqlQueryModel.setQuery(queryCommand)
if myQSqlQueryModel.rowCount() > 0:
myQTableView.setModel(myQSqlQueryModel)
myQTableView.show()
querySuccess = True
break
if not querySuccess:
query.setQuery(""" SELECT * FROM "%s" WHERE METAPHONE("%s", 3) = METAPHONE('%s', 3) OR LEVENSHTEIN("%s", '%s') < 4 """ % (str(self.search_from_table_lineEdit.text()), str(self.search_where_lineEdit.text()), str(self.search_has_value_lineEdit.text()), str(self.search_where_lineEdit.text()), str(self.search_has_value_lineEdit.text())))
global var
var = QtGui.QTableView()
var.setModel(query)
var.show()
After your query success, your can check your data in model if have any row count in this method. And your for loop to get many query;
def testUpdate (self):
myQSqlQueryModel = QtSql.QSqlQueryModel()
myQTableView = QtGui.QTableView()
querySuccess = False
for queryCommand in ["YOUR QUERY 1", "YOUR QUERY 2"]:
myQSqlQueryModel.setQuery(queryCommand)
if myQSqlQueryModel.rowCount() > 0:
myQTableView.setModel(myQSqlQueryModel)
myQTableView.show()
querySuccess = True
break
if not querySuccess:
QtGui.QMessageBox.critical(self, 'Query error', 'Not found')

How do I fix error message. "Remember that ordinal parameters are 1-based!"

given the code snippet (please do not ask why I construct it this way...)
...some more Logic...
def blaParam = ['checkinable':checkinable]
def blaQuery = " AND c.product = :checkinable"
...some more Logic...
and
def paramBox = [] + blaParam
def queryBox = "" + blaQuery
def c = Bla.executeQuery("FROM Bla b WHERE 1 = 1 "+queryBox+" ", paramBox, [max:params.max])
I end up with a message
errors.GrailsExceptionResolver Remember that ordinal parameters are 1-based!
How do I prevent this?
Merging the two last parameter maps worked for me:
Bla.executeQuery("FROM Bla b WHERE 1 = 1 "+queryBox+" ", paramBox + [max:params.max])
if I change
def paramBox = [] + blaParam
to
def paramBox = [:] + blaParam
it is working