I am attempting to create a test that checks a json response to contain either one property or another.
My example:
pm.expect(jsonData.data.owner).to.have.property('orgName') ||
pm.expect(jsonData.data.owner).to.have.property('firstName')
I can't seem to find any documentation on using or operators in the new pm.expect() syntax.
use oneOf() method
pm.expect(jsonData.carrierType.type).to.be.oneOf(["mobile", "landline"]);
I was looking for answer to implement OR in postman tests, but didn't found any. I've done just a simple if statement to determine which of the conditions should be checked. (Knowing the business logic). In my application I had to check if we support german language, but if we don't by default we set it to english. It was easy because I've took the value from my json and than manualy check which condition should be the valid one. This might help you and anyone else in further implementation of this. So for me it looked like this:
pm.test("German language support.", function(){
var jsonData = pm.response.json();
if(jsonData.count() > 0){
var langCode = jsonData[0].language.code;
if(langCode === "en"){
pm.expect(jsonData[0].language.code).to.eql("en") ;
}else{
pm.expect(jsonData[0].language.code).to.eql("de")
}
}
});
pm.expect( booleanCondition1 || booleanCondition2 ).to.be.true
first you misuse pm.expect, you should do something like
pm.expect(jsonData.data.owner).to.have.property('property_name','property_value)
I'm afraid that it is not straightforward to implement or condition ... see examples here
Related
I can't seem to figure out how to create optional query string parameters using a mapping template within my resource's Integration Request.
My template looks like this:
{ "limit": "$input.params('limit')", "post_date":"$input.params('post_date')" }
I'd like 'limit' & 'post_date' to be optional. This template creates a querystring that looks like this when these parameters are not provided:
/myresource?limit=undefined&
When I'm expecting:
/myresource
The Docs don't seem to cover this. I have found some example templates in the documentation that use a bash-like syntax to provide conditional functionality. I've tried testing the following but it will NOT validate in the AWS console:
#set($limit = $input.path('limit'))
{
#if($limit)"limit": "$input.params('limit')",#end
}
Am I on the right track?
Thanks!
Yes, you absolutely can do this in Api Gateway; although it does not seem to be well-documented!
In your question, you mentioned that this is a parameter; but you used input.path, which would normally refer to an element in the body of the POST request. The following should work:
#set($limit = $input.params('limit'))
{
#if($limit && $limit.length() != 0)
"limit": "$input.params('limit')"
#end
}
In terms of documentation, I found that the following page from AWS is actually pretty useful. It's tucked away in a section about mock endpoints, though:
http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-mock-integration.html
Wanted to contribute, as Tom Kerswill's answer did not work for me.
I kept running into the issue where if I defined an optional parameter and didn't use it, I would get a JSON parse exception when calling the API.
How I got mine to work:
#set($hasOptional = $input.params("optionalParam") != "")
{
"requiredParam1": $input.params("requiredParam1"),
"requiredParam2": $input.params("requiredParam2"),
#if(!$hasOptional )
"optionalParam": null
#end
#if($hasOptional )
"optionalParam": $input.params("optionalParam")
#end
}
Running with ONLY the second 'if' statement did NOT work, I had to explicitly set the optional parameter to null if it didn't exist.
Also note the use of quotation marks, putting quotes around the entire $input... never worked for me. E.g.
"$input.params('limit')"
I had to write them out exactly like this:
"requiredParam1": $input.params("requiredParam1")
Hope this helps another frustrated AWS API Gateway user.
I am trying to modify Angular's built-in e-mail validator according to the official documentation (https://docs.angularjs.org/guide/forms, almost at the bottom of the page). They even provide a plunkr there which I forked and updated with REGEX expressions that should validate emails better than Angular's standard validation: http://plnkr.co/edit/UerAymIVWmAYKjeT3FH2?p=preview - works.
However, if I try to implement this code in my module, it doesn't work: http://plnkr.co/edit/UerAymIVWmAYKjeT3FH2?p=preview.
So basically I've just replaced
var app = angular.module('form-example-modify-validators', []); with
var App = angular.module('ionicApp', ['ionic', 'firebase', 'ngCordova']).
Feels like am lacking some very basic understanding of Angular here, could anyone please give me a hint?
Super stupid: Obviously the plunkr can't find my dependencies.
I'm having trouble using TinyXML2 to blindly parse a XML page for specific tags.
Basically, I am asked to parse via C++ an HTML page. I use the (quite old) tidyHTML library to firstly "translate" my HTML pages into XML ones. Then, I want to use TinyXML2 to parse these newly created XML pages for specific tags' content (title, h1, meta keywords, ...).
To this end, I am trying to loop through all the tags in my XML page, using this code:
XMLDocument doc;
doc.Parse( cleanedHTML.c_str() );
XMLNode* currentNode;
if(currentNode->NoChildren())
{
while(!currentNode->NextSibling())
{
currentNode=currentNode->Parent();
if(!currentNode)
return NULL;
}
currentNode=currentNode->NextSibling();
}
else
{
currentNode=currentNode->FirstChild();
}
doc.Print();
std::string nodeName = currentNode->LastChild()->Value();
return nodeName;
There are probably a few things wrong with this code - no doubt, I'm clearly an amateur. But the result still puzzles me: nodeName is returning "USER=root" whatever the page I am parsing.
I tried selecting this node's related elements, like currentNode->FirstChildElement() or LastChildElement(), or even Siblings... But everytime it results in a Segmentation Fault which I cannot comprehend.
I've read that Xpath would be a good way to do what I'm trying to do, but then again I'm running out of time and I fear I wouldn't be able to wrap my mind around Xpath in such relatively short notice.
I probably am looking at all that the wrong way, or maybe should I be using Accept() ?
I honestly feel a bit lost here and would appreciate any help you guys would be so kind as to offer!
I'd like to quickly take this chance to also thank this website that has helped me so much in the past.
Truely amazing.
Thanks by advance for your responses!
Now that I've finished my project I can finally answer this:
What I was looking for indeed was Accept() and Visitors. I had to instantiate a Visitor, add any particular effect his "encounters" would produce, and throw it into my doc.Accept();
For instance, if I wanted to get in a string the parsed page's title, I would do so:
bool MyVisitor::VisitEnter(const XMLElement& element, const XMLAttribute* attribute)
if(strcmp( element.Name(), "title") == 0)
{
if(element.GetText() != NULL)
{
titleContent = element.GetText();
}
else
titleContent = "";
}
... and then return it with a classic MyVisitor::getTitle() function that you'd call wherever you'd need it.
Hope it helps, if anyone wants more details I can provide working & extended code.
I've since discovered that Google released gumbo parser so... yeah.
It's apparently both better & easier than using TinyXML-2 for parsing HTML5 nowadays :D
You might want to consider using a parser for which better examples are available, upon which you could base your tool... for example, Apache Xerces-C's SAX API examples could be adapted.
(I don't know anything about TinyXML2 and what APIs it supports, so I can't advise re how to fix the problem in your existing code.)
You can use Ember.guidFor to retrieve a GUID for an Ember object. It will return something like this:
"ember768"
Is there also a way to do this backwards (retrieving an object based on its GUID)?
I know that there is Ember.View.views which holds all Ember views indexed by its GUIDs. Something similar for any Ember object would be nice.
This is how I'm doing the lookup. Still trying to see if there is a way to get at it more directly instead of looping through but it works.
DS.Store.reopen({
findByGuid: function(type, guid) {
return this.typeMapFor(type).records.find(function(item) { return Em.guidFor(item) == guid; });
}
});
Usage as such:
store.findByGuid(MyModelType, "ember768");
HTH
N.B. Just to be clear, the above assumes you know the type of the object you're looking for. If you don't, one solution would be to iterate over the store.get('typeMaps') then iterate over each 'records' array. Seems a bit nasty to have to use N*N loops though!
As far as I know, you can't. What is it you would like to accomplish? If you just want to see the contents of the object, you can use ember chrome extension.
I have a class Post, with the following scope:
scope :by_tag, ->(tag){ where(:desc => /##{Regexp.escape(tag)}/) }
It works very well with one tags, but I can't make it work with various tags.
For example: I cant make it give me the posts tagged with #rails AND #regexp.
With criteria union I can make it return me the posts tagged with #rails OR #regexp.
How can I get it to work? I'm using mongoid, btw.
Thanks in advance.
Just fount that is not an OR. What happens is that the second time I call by_tag, it overrides the previous. I believe that's because it's the same property.
Someone know how to fix this? Thanks
Regexp queries tend to be really slow. Instead, store an array of tags and use $in to query the array.
With Mongoid 2.x use all_in
scope :by_tags, ->(*tags) { all_in(tags: *tags) }
With Mongoid 3 use all merge strategy
scope :by_tags, ->(*tags) { all(tags: *tags) }