I have the following problem - I want to test REST api with Codeception.
When I want to make sure in JSON response I have array:
'data' => [
'sth' => 'whathever'
]
I can use seeResponseJsonMatchesXpath this way:
$I->seeResponseJsonMatchesXpath('//data/sth');
But what to do if I want to make sure I don't have in response sth? I would like to use for example:
$I->seeResponseJsonMatchesXpath('//data');
$I->dontSeeResponseJsonMatchesXpath('//data/sth');
but obviously there is no dontSeeResponseJsonMatchesXpath method in Codeception.
I also don't know what will be exact value in sth so probably I cannot use here dontSeeResponseContainsJson.
The question is - how to make the following check?
(Disclaimer: Entirely unfamiliar with codeception, only with XPath)
JSON is not supposed to be checked against XPath. But the check you could probably do is
$I->seeResponseJsonMatchesXpath('not(//data/sth)');
Which would return true or 1 if there is no data and sth - and false or 0 if there is.
EDIT: As a response to your comments:
Probably this is something close I need but I want to make sure only sth is not present inside data whereas data should exist (but I don't need to check it in this expression)
The expression already does exactly that - not(//data/sth) returns false for a document like
<data>
<sth/>
</data>
but returns true for a document containing data only:
<data/>
or anything else. But it seems to me there could be pitfalls with converting JSON to XML.
I checked both solutions - yours and //data/not(sth) but it doesn't seem to work
Yes, that does not work because you are using an XPath 1.0 engine. Your attempt would be a valid XPath 2.0 expression. Use the following expression to independently test data and sth:
//data and not(//data/sth)
This only returns true if at least one data element exists and if there is no data element that has an sth element as a child.
Related
I'm new to SAPUI5 component.
Is there a way to apply $filter to sap.m.Tree? It seems weird to me.
I'm currently using $filter options to limit the data from back-end (by using WHERE clause, came from $filter option), so I have to $filter to pass my parameter.
My controller :
this.oCharTable = this.getView().byId("CharTree")
var aFilterChar = new Filter("Matnr", FilterOperator.EQ , filter_base[2])
this.oCharTable.bindElement({
path: "/AUSP_ENTITY",
model: "AUSP_DATA",
filters: [aFilterChar],
parameters: {
NumberOfExpandedLevels : 2
}
});
and It's $batch payload :
GET AUSP_ENTITY?$filter=HierarchyLevel%20eq%20%270%27&$skip=0&$top=100 HTTP/1.1
sap-cancel-on-close: true
It depends on your data source:
if you have a odata v2, you can't filter on children. This is simply not supported by v2
if you have a odata v4, this is not supported by tree-binding. Good news, it on the roadmap https://github.com/SAP/openui5/issues/2728
if you preload all data an put it in a json model. You could filter as you like with vanilla js
Based on the given answer. You could just ignore v2 specification and filter in the backend as you want with any passed filter.
Oh, I think I found the solution - the problem is on backend!
Thanks to this answer, Using Suspend - Resume makes me send right GET request, like
../AUSP_ENTITY?$filter=HierarchyLevel%20eq%20%270%27%20and%20(Matnr%20eq%20%27SomeKindofMaterialHere%27)&$skip=0&$top=100
I changed my backend to select right values, and returning value to frontend.
For future leaders, who might read my question, I changed my backend to take not only take 1 option (this one, might be Matnr), but also take 'HierarchyLevel', which have to be taken care of.
In detail - I using $filter parameters to get data from CDS View, which can reduce the select result to resonable level.
so I redefine DPC_EXT Class, split up my $filter input, and put it into my parameter, and put result into result table.
TL;dr : If you using $filter on Tree View : check the 'return' backend. It might be problem in there.
This question derives from this question asked earlier. I am making a Soap request, and I am receiving the response as either an Array, or String.
[print] [ "M4205N", "M4206U" ]
[print] M5967H
When I get the response as an array, I figured out how to loop through it, and pass the values to another request. However, sometimes the response will come back as a single Code, and it will be returned as a String. In that case, I cannot perform the same logic as I did with the array. I've read about Karate conditional logic, but I cannot figure out how to make it do what I want.
I want to do something like this:
If the response is returned as a String, then call this method with the one value.
If the response is returned as an array, then call this method and pass each value from the array.
This is one of the ways I had in mind, but it does not work because of the Type difference:
* def memberCodes = memberCodes.size() > 1 ? karate.mapWithKey(memberCodes, 'memberCode') : {}
* def result = call read('OtherRequest.feature') memberCodes
This works if the response is returned as an array, but obviously if it's returned as a String it will break.
What is the right way to perform this conditional logic? Also, please refer to my previous question for more context if needed. Thanks!
Interesting. This check should work for testing if (not) a string:
* def memberCodes = typeof memberCodes != 'string' ? karate.mapWithKey(memberCodes, 'memberCode') : {}
Also refer this somewhat related question: https://stackoverflow.com/a/58543843/143475
How do I take a list of values, iterate through it to create the needed objects then pass that "list" of objects to the API to create multiple rows?
I have been successful in adding a new row with a value using the API example. In that example, two objects are created.
row_a = ss_client.models.Row()
row_b = ss_client.models.Row()
These two objects are passed in the add row function. (Forgive me if I use the wrong terms. Still new to this)
response = ss_client.Sheets.add_rows(
2331373580117892, # sheet_id
[row_a, row_b])
I have not been successful in passing an unknown amount of objects with something like this.
newRowsToCreate = []
for row in new_rows:
rowObject = ss.models.Row()
rowObject.cells.append({
'column_id': PM_columns['Row ID Master'],
'value': row
})
newRowsToCreate.append(rowObject)
# Add rows to sheet
response = ss.Sheets.add_rows(
OH_MkrSheetId, # sheet_id
newRowsToCreate)
This returns this error:
{"code": 1062, "errorCode": 1062, "message": "Invalid row location: You must
use at least 1 location specifier.",
Thank you for any help.
From the error message, it looks like you're missing the location specification for the new rows.
Each row object that you create needs to have a location value set. For example, if you want your new rows to be added to the bottom of your sheet, then you would add this attribute to your rowObject.
rowObject.toBottom=True
You can read about this location specific attribute and how it relates to the Python SDK here.
To be 100% precise here I had to set the attribute differently to make it work:
rowObject.to_bottom = True
I've found the name of the property below:
https://smartsheet-platform.github.io/smartsheet-python-sdk/smartsheet.models.html#module-smartsheet.models.row
To be 100% precise here I had to set the attribute differently to make it work:
Yep, the documentation isn't super clear about this other than in the examples, but the API uses camelCase in Javascript, but the same terms are always in snake_case in the Python API (which is, after all, the Pythonic way to do it!)
While testing code in the google chrome developer console, i get
[]
and sometimes i get "".
The later shows up,when i think there not such strings available with the current selector combinations.But i still couldn't figure out the meaning of the former [] square brakets.
Please help.
With the information that you've given, all we can do is make assumptions. However, when you're logging things to the console, [] is an empty array, whereas "" is an empty string.
[] are returned whenever you jquery returns empty object. i.e. you selector expression cant locate what you are trying to search.
whereas "" is just simple string
i looked into your given site..
when i tried :
$('.four columns alpha') i get object[] (which means there jquery is returning empty object)
but when you write correct expression like :
$('.four.columns') you will get array of Div's which can be used like object.
Hope i'm able to make you understand. if any doubts do write.
And $('.four columns alpha') this is not the right way to select div's with more than one css class right way is to do something like below:
$('.four.columns.alpha')
I've been using filters in Sinatra the way it has been declared in the documentation: with no match string, with a match string or with a match regexp. It has been working fine til now. Now, I have a particular use case. Let's say I have this route:
/resources/1
According to REST, and depending of the request method, this can either be a GET method, PUT method or DELETE method. First question is: How to write filters that are only called when it is a GET request? (currently I'm letting all of them get filtered and only then I test the method. It works, but I don't like it). Second question, and more important: let's say a PUT request like this is triggered:
/resources/
This is of course wrong, because the PUT request has no resource id associated. I would like to know if there is something in Sinatra that enables me to do something like this:
before "/resources/", :method => :put do
error_message
end
just this possibility does not exist (before accepts only one argument). How could I achieve this result at best?
Actually, filters do take conditions. You don't have to use a condition though, you could use a conditional within the filter:
before "/path/" do
if request.request_method == "PUT"
# do something
end
end
If you want to use a condition, I think you'll need to write one, perhaps something like this:
set(:accepted_verbs) {|*verbs|
condition {
verbs.any?{|v| v == request.request_method }
}
}
before "/path/", :accepted_verbs => ["GET","POST"] do
# do something
end
before "/path/", :accepted_verbs => ["PUT"] do
# do something else
end
See conditions for more.