I want to recover an object id (processId) that I pass in a simple Post request in a feature A
Given url <url>
And path 'processes'
And header Authorization = 'Bearer ' + <token>
And request process
When method post
Then status 201
* def processId = response.id
I test this request with 3 different environments in a Scenario outline (varriable <url>). So I have to recover the 3 id to use them in a feature B
My question is: how can I retrieve these IDs for use in feature B
Thanks
There is no way you can re-use data from one Scenario in another, and a Feature is certainly out of the question. Please take some time to read this: https://stackoverflow.com/a/46080568/143475
That said, if all you need to do is call a Scenario in a loop, just do that. Here is a simple example you can try:
Feature:
Scenario:
* table data
| value |
| 'one' |
| 'two' |
* def result = call read('called.feature') data
* def traceIds = $result[*].traceId
* print traceIds
And called.feature is simply:
#ignore
Feature:
Scenario:
* url 'https://httpbin.org/post'
* request { key: '#(value)' }
* method post
* def traceId = response.headers['X-Amzn-Trace-Id']
Please read the docs to understand how you can "collect" data from the "called" feature, traceId in this case: https://github.com/karatelabs/karate#data-driven-features
Related
I need to form a Splunk query to find a particular sessionId for which log a is available but log b is not. Both are part of the same transaction but code breaking in between somewhere.
LOGGER.info("Log a:: setting some details in session");
Response response = handler.transactionMethod(token); //throws some exception
LOGGER.info("Log b:: getting details in session");
So in the success scenario, both Log a and Log b will be printed. But when transactionMethod throws an exception, only Log a will be printed for that sessionId and not Log b.
The requirement is I need to find any of the sessionId for which only Log a is present, not Log b.
Assuming that you have 2 fields TEXT and SessionID already defined, we will use the following test data:
SessionID=1001 TEXT="setting
SessionID=1001 TEXT="getting
SessionID=1002 TEXT="setting
SessionID=1003 TEXT="getting"
Splunk query:
| makeresults count=4
| streamstats count
| eval TEXT=case(count=1 OR count=3, "setting", count=2 OR count=4, "getting")
| eval SessionID=case(count=1 OR count=2, 1001, count=3, 1002, count=4, 1003)
``` The above is just setting of the test data ```
``` Below is the actual SPL for the task ```
| stats count(eval(TEXT=setting")) as LogA count(eval(TEXT="getting") as Logb by SessionID
| search LogA > 0 and LogB = 0
As you can see I specifically excluded the case when only "LogB" record is present (SessionID=3)
I would like to process Azure AD audit Logs into HTML tables/csv files. The data contains nested sets of arrays that I would like to summarise into a comma separated string.
eg data that looks like this
{
"TargetResources": [{"displayName": "Policy",
"modifiedProperties": [{"displayname": "PolicySetting1"},
{"displayname": "PolicySetting2"}]
}]
}
Would be processed into
TargetResource | Policy
modifedProps | PolicySetting1, PolicySetting2
mv-expand doesn't seem to work because some rows do not have modifiedProperties so those rows get eliminated
The only solution I have been able to find that gets close to what I am trying to do looks like this:
AuditLogs
| extend TargetResource = tostring(TargetResources[0].displayName)
| extend ModifiedProperty0 = tostring(parse_json(tostring(TargetResources[0].modifiedProperties))[0].displayName)
| extend ModifiedProperty1 = tostring(parse_json(tostring(TargetResources[0].modifiedProperties))[1].displayName)
| extend ModifiedProperty2 = tostring(parse_json(tostring(TargetResources[0].modifiedProperties))[2].displayName)
| extend ModifiedProperties = strcat(ModifiedProperty0,", ",ModifiedProperty1,", ",ModifiedProperty2)
This solution is limited in that it cannot work for arbitrary numbers of modifiedProperty values (it only works properly for exactly 3) which is a requirement for my purposes, I would like the solution to work if modifiedProperties does not exist and if there are 0-15 values.
Thank you for any help you can provide
if I understood your description correctly, you could use mv-apply (twice) to achieve that:
datatable(d: dynamic)
[
dynamic({"TargetResources":[{"displayName": "Policy0","someOtherProperty":"hello world"}]}),
dynamic({"TargetResources":[{"displayName": "Policy1","modifiedProperties":[{"displayname":"PolicySetting1"},{"displayname":"PolicySetting2"}]}]}),
dynamic({"TargetResources":[{"displayName": "Policy2","modifiedProperties":[{"displayname":"PolicySetting3"},{"displayname":"PolicySetting4"}]}, {"displayName":"Policy3","modifiedProperties":[{"displayname":"PolicySetting5"},{"displayname":"PolicySetting6"}]}]}),
]
| mv-apply tr = d.TargetResources on (
extend TargetResource = tr.displayName
| mv-apply mp = tr.modifiedProperties on (
extend propertyName = mp.displayname
| summarize modifiedProps = strcat_array(make_set(propertyName), ", ")
)
)
| project TargetResource, modifiedProps
TargetResource
modifiedProps
Policy0
Policy1
PolicySetting1, PolicySetting2
Policy2
PolicySetting3, PolicySetting4
Policy3
PolicySetting5, PolicySetting6
I have sqlite database with article table that contains articleID and articleDescription.
I'm using expressjs as server:
app.get('/articleDetail/:id',function(req,res){
res.sendFile(path.join(__dirname+'/articleDetail.html'));
var id = req.params.id;
var query = "select * from article where articleID = " + id;
});
I want the to show the content of the article based on its id in the database.
An example: when you select article 5 on the home page, it take you to url ..../articleDetail/5 and the content is shown to the user.
Summary of the 2 questions I have:
How can I connect and id in my database to the id of the url/route?
How can I show the correct article content based on its id using express?
Thanks for any help.
Install module called sqlite3 into your project. It provides exactly what you want, here you can see detailed guide on how to install it and use it for connecting and querying database - http://www.sqlitetutorial.net/sqlite-nodejs/connect/
So steps should be like this:
Get article id from request or url params e.g let id = req.params.id
Execute query and get the item from database
pass the value (article) object to view and render there
app.get('/articleDetail/:id',function(req,res){
var id = req.params.id;
var query = "select * from article where articleID = " + id;
// execute the query here
res.sendFile(path.join(__dirname+'/articleDetail.html'));
});
In 'products.template' table I created three fields width,length and gsm. Now I want to retrieve it in 'mrp' table.First I will get the ids from mrp bill of materials and assign it to a variable called prod. 'mrp.bom.line' table contains product id.So through iterator I want to pass id of product stored in mrp bill of materials table to retrieve the value of width,length and gsm stored in product.template table.I am getting error as programming error can't adapt type 'product.product'.
#api.multi
def _compute_rim_weight(self):
bill_of_materials_id=[1,2,3]
prod = self.env['mrp.bom.line'].browse(bill_of_materials_id)
for i in prod:
j = self.env['product.template'].browse(i.product_id)
self.rim_weight = (j.width * j.length * j.gsm)/20000
return self.rim_weight
In ODOO browse take id not object
so just replace browse(i.product_id) with browse(i.product_id.id) as below:
j = self.env['product.template'].browse(i.product_id.id)
One more thing if in case product.template have** many2one relation** with model :mrp.bom.line from my understanding you even don't need the call browse .
Directly call line.product_id.width ,line.product_id.length,line.product_id.gsm as below :
#api.multi
def _compute_rim_weight(self):
bill_of_materials_ids=[1,2,3]
bom_lines = self.env['mrp.bom.line'].browse(bill_of_materials_ids)
for line in bom_lines:
self.rim_weight = (line.product_id.width * line.product_id.length * line.product_id.gsm)/20000
return self.rim_weight
#api.one
def _compute_rim_weight(self):
rim_weight =0
for line in self.bom_id.bom_line_ids:
rim_weight+ = (line.product_id.width * line.product_id.length * line.product_id.gsm)/20000
self.rim_weight =rim_weight
I have 3 Models: Offer, Request and Assignment. Assignment makes a connection between Request and Offer. Now I want to do this:
select *
from offer as a
where places > (
select count(*)
from assignment
where offer_id = a.id and
to_date > "2014-07-07");
I am not quiet sure how to achieve this with a django QuerySet... Any tips?
Edit: The query above is just an example, how the query in general should look like. The django model looks like this:
class Offer(models.Model):
...
places = models.IntegerField()
...
class Request(models.Model):
...
class Assignment(models.Model):
from_date = models.DateField()
to_data = models.DateField()
request = models.ForeignKey("Request",related_name="assignments")
offer = models.ForeignKey("Offer",related_name="assignments")
People now can create a offer with a given amount of places or a request. The admin then will connect a request with an offer for a given time. This is saved as an assignment. The query above should give me a list of offers, which have still places left. Therefore I want to count the number of valid assignments for a given offer to compare it with its number of places. This list should be used to find a possible offer for a given request to create a new assignment.
I hope this describes the problem better.
Unfortunately related subqueries aren't directly supported by ORM operations. Usage of .extra(where=...) should be possible in this case.
To get the same results without using a subquery something like the following should work:
Offer.objects.filter(
assignment__to_date__gt=thedate
).annotate(
assignment_cnt=Count('assignment')
).filter(
assignment_cnt__lte=F('places')
)
The exact query depends on the model definitions.
query = '''select *
from yourapp_offer as a
where places > (
select count(*)
from yourapp_assignment
where offer_id = a.id and
to_date > "2014-07-07");'''
offers = Offer.objects.raw(query):
https://docs.djangoproject.com/en/1.6/topics/db/sql/