This question already has an answer here:
How to pass multiple parameters to callSingle karate on karate-config.js
(1 answer)
Closed 1 year ago.
We have to call two APIs only once in whole project which is a pre-requisite for all other features to run. All features are using values set in userId and unitId.
The first feature call is working fine but I am not sure how to add if condition on status code as only when the status code of first feature#test1 is 200 only then we want to call the second one else not.
The below code displayed the value as
User Id is -------------378
But is not going in the if condition although this API returned response code as 200.
var result = karate.callSingle('classpath:util/users.feature#test1',config);
config.userId = result.response.value[0].id;
karate.log("User Id is -------------" + config.userId)
if( result.status == 200 )
{
var result1 = karate.callSingle('classpath:util/users.feature#test2',config);
config.unitId = result1.response.value[0].id;
karate.log("Unit Id is -------------" + config.unitId)
}
It should be result.responseStatus.
This question already has an answer here:
Is it possible to use karate 'match' inside conditional statement?
(1 answer)
Closed 1 year ago.
I want to execute more than 1 statements provided an If condition is true. I want to know whether and how is it achievable in Intuit Karate framework.
In the Karate documentation, I find examples like below all of which have only one statement to be executed if the If condition is satisfied as listed below.
if (env == 'dev') karate.configure("ssl", true)
if (responseStatus == 200) karate.call('delete-user.feature')
if (responseStatus == 404) karate.abort()
I want to achieve something like below (only a pseudocode representation of my requirement and not as per the actual Karate syntax)
if (responseStatus ==200)
#statement 1
#statement 2
#statement 3
#end of If
Thanks!
Normally good tests should never do this. Make sure you read this also: https://stackoverflow.com/a/54126724/143475
But here are the 2 possible patterns:
a) use a second feature file:
* if (condition) karate.call('second.feature')
b) use a function, the disadvantage is only the JS API, things like match not supported
* def fun =
"""
function() {
// line 1
// line 2
}
"""
* if (condition) fun()
I have two tables :
Question table where contains :
And then I have another table that is called
UserAnswerQuestion that contains :
That has reference to the question via question_id
The thing is that every time user answers a question I create a row in db saying :
question_id user_id has answered it and then I check if the answer is correct or not, if it's correct I put passed as a True, otherwise I put passed as a false.
Ok, from now is all ok, the thing that I can not get is I'm creating a method that returns to me the nextQuestion not answered, but I'm not able to do this method correctly.
What I'd like is to have a query that first return all questions that user have not answered yet, and then another query that returns just a question that user has not answered yet.
Note: This shown attribute was added because I want first to iterate over other questions instead of showing the ones that user has failed recently.
Is the question clear?
What I've tried?
I've tried to get the questions List<UserAnswerQuestion> findAllByUserEmailAndPassedFalseAndShownFalse(String email); but it doesn't work because with this table I can know every answer in every try that user does, so for example if I have a question that have 4 answers and 1 correct, this table can contain 4 row with the same question_question_id because the user perhaps has failed 3 times and then at the fourth it answers correctly.
Edit
I have already the questions that user can answer with this method :
public List<Question> getAllQuestionsThatUserCanAnswer(String email, Long topic){
List<Question> mList = this.questionRepository.findAllByTopicParentId(topic);
if(mList==null) return null;
List<UserAnswerQuestion> userAnswerQuestionList = this.userAnswerQuestionRepository.findAllByUserEmail(email);
for (UserAnswerQuestion userAnswerQuestion : userAnswerQuestionList) {
if(mList.contains(userAnswerQuestion.getQuestion())){
if(userAnswerQuestion.getPassed()){
mList.remove(userAnswerQuestion.getQuestion());
}
}
}
return mList;
}
Now I'm trying to do the getNext of this method but I do not know how to iterate over it.
Focus on SQL query that solve your problem
select * from Question q
left join Answer a on q.id = a.question_id
where a.id is null OR (a.passed != 'true' AND a.user_id = 1)
order by a.passed
Check scratch here
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm trying to include a for loop to add where conditionals to my query and it is returning an undefined offset 1 error on $ProductSubCategory. The contents of $ProductSubCategory is an array of strings I'd like to include as conditionals.
$Product = Product::select('id','ProductWorkpiece','ProductCategory','ProductName','ProductImage','ProductSubCategory')
->where('Status','=','1')
->Where(function ($query) use ($ProductSubCategory) {
for ($i=1; $i <= $ProductSubCategory ; $i++) {
$Product->where('ProductSubCategory', '=', $ProductSubCategory[$i]);
}
})->get();
https://pastebin.com/uDSywsQv (Laravel Query Builder snippet)
Here is the MySQL query I would like to replicate using Laravel's query builder, how would I go about doing this?
SELECT
`id`,
`ProductWorkpiece`,
`ProductCategory`,
`ProductName`,
`ProductImage`,
`ProductSubCategory`
FROM
`Product`
WHERE
`ProductSubCategory` = 'Laser Marking Machine' OR
`ProductSubCategory` = 'Dot Marking Machine' OR
`ProductSubCategory` = 'Digital Microscope' AND
`Status` = '1'
https://pastebin.com/AMWCz32g (Desired MySQL snippet)
Looking at this $ProductSubCategory is not an array or does not have the index of 1. Depending on the contents of $ProductSubCategory there are a few approaches you can use.
Solution 1: $ProductSubCategory is an array of strings
$Product = Product::select('id','ProductWorkpiece','ProductCategory','ProductName','ProductImage','ProductSubCategory')
->where('Status','=','1')
->whereIn('ProductSubCategory', $ProductSubCategory)
->get();
Here you can use whereIn() and specify the array of strings, no need to loop through anything.
Solution 2.1: $ProductSubCategory is an object collection of records
$Product = Product::select('id','ProductWorkpiece','ProductCategory','ProductName','ProductImage','ProductSubCategory')
->where('Status','=','1')
->where(function ($query) use ($ProductSubCategory) {
foreach($ProductSubCategory as $subcategory) {
$query->orWhere('ProductSubCategory', '=', $subcategory->name);
}
})->get();
Here we loop through each object record using foreach and then reference the name field from that object using a orWhere rather than WHERE foo = bar AND foo = bar2 AND foo = bar3
$subcategory->name is used as placeholder, use the the field name which applies to you.
Note In your version you did function($query) but then referenced $Product instead of $query to do your where clause.
Edit / Update
Solution 2.2: $ProductSubCategory is an object collection of records
$subCategories = $ProductSubCategory->only('name')->toArray();
$Product = Product::select('id','ProductWorkpiece','ProductCategory','ProductName','ProductImage','ProductSubCategory')
->where('Status','=','1')
->whereIn('ProductSubCategory', $subCategories)
->get();
This is the same as Solution 1 except we've used the collection method only() to retrieve only the name field (Change accordingly) and then converted the names toArray() so it can be used as part of a whereIn conditional. This is untested on my side but should work in theory
I could be more helpful knowing the contents and type of $ProductSubCategory.
inside tou loop $Product is not accessible try replace by $query :
$query->where('ProductSubCategory', '=', $ProductSubCategory[$i]);
This question already has an answer here:
How do I get the value from a form field using Odoo?
(1 answer)
Closed 7 years ago.
I'm new in Odoo 8 and have some difficulties getting the ID value of a object for example the ID field value of hr.employee, can you give me some sample in this matter
Please read the Official Doc for v8.0 , it will give you clear idea.
For note, if your are using New API then you just directly create model_object and fetch using model_obj.id
As on your example
HrEmployee = self.env['hr.employee']
employee_id = HrEmployee.id