ScalaTest: how to properly assert over Try values? - scalatest

At the moment if I need to test that a value v of Try[T] type is Success(t) I do like:
v.isSuccess shouldBe true
I wonder if there are probably some better ways. For example, for Option[T] we can assert like:
t shouldBe defined
Probably there is something like this for Try[T] but I am not aware and searching the web does not help.

So far I came up with this solution:
Based on this section of the ScalaTest docs we declare such symbol value:
val successful = 'success and then assert like this:
CampaignRowsPage.reserveInventory shouldBe successful
Looks good to me.

Related

peewee get_or_create and then save: error binding

Is there an easy way to update a field on a get of a get_or_create?
I have a class ItemCategory and I want to either create a new entry or get the already created entry and update a field (update_date).
What I do is:
item,created= ItemCategory.get_or_create(cat=cat_id,item=item_id)
if created == True:
print "created"
else:
item.update_date = datetime.now
item.somethingelse = 'aaa'
item.save()
This works for a while in my loop. But after 50-100 get/create it crashes:
peewee.InterfaceError: Error binding parameter 4 - probably unsupported type.
Maybe I should use upsert(), I tried but wasn't able to get anything working. Also it's not probably the best solution, since it makes a replace of the whole row instead of just a field.
I like peewee, it's very easy and fast to use, but I can't find many full examples and that's a pity
Newbie mistake
item.update_date = datetime.now()
I am not 100% sure this is the only answer though. I modified my code so many times that it might be also something else.
Regarding my question about create_or_update , I've done this:
try:
Item.create(...)
except IntegrityError:
Item.update(...)
peewee is really great, I wonder why no one ever asked for a create_or_update.

Using 'or' in Protractor expected conditions

I am trying to write an expects statement in Protractor that uses the or expected condition. However, the documentation does not have any examples of how to use 'or' or 'and' with these blocks.
I have tried doing
expect(myString).or.toEqual('a string').toEqual('another string')
expect(myString).toEqual('a string').or.toEqual('another string')
and just for kicks
expect(myString).toEqual('a string', 'another string')
This question has been asked previously but only a workaround was given.
I would like to actually use the or function that is built into Protractor as it should allow the message to read something like
Expected 'a totally different string' to be 'a string' or 'another string'
Examples are provided here: http://angular.github.io/protractor/#/api?view=ExpectedConditions. However, you're confusing the use of expected conditions, which is used for browser.wait and not expects.
You can always write a custom matcher. In this case, there is no need to write one, the one provided at Expect item in array would fit your use case. For jasmine 1.x:
this.addMatchers({
toBeIn: function(expected) {
var posibilities = Array.isArray(expected) ? expected : [expected];
return posibilities.indexOf(this.actual) > -1;
}
});
Usage:
expect(myString).toBeIn(["a string", "another string"]);
Just FYI, there is also a useful library of custom jasmine matchers: jasmine-matchers.
This is a bit of a hack, but it just helped me. I am posting it in case it would be useful to someone, not because I think it is the most elegant approach (and it may also be a "workaround"). It works if your strings are really different, and it works for strings, not more generally. For my case, I had to resolve the promise first.
myString.getText().then(function(text){
expect('a stringanother string'.search(text)).toBeGreaterThan(-1);
});
Of course the above would be quite happy to pass partial matches like 'n' or 'another' or nonsense like 'ngano'. None of those were going to happen in my case.

What does the __default__ prefix mean in ng-inspector?

What exactly does the __default__ prefix mean in ng-inspector as shown below?
I am trying to access this value and I'm not quite sure how.
Thanks!
The extension certainly didn't add that prefix, if it shows up in ng-inspector, something else added that to your model.

How to indicate what a boolean parameter for an Angular filter represents

If you look at something like this:
{{data | customFilter:true}} you won't know what that true stands for unless you look at the implementation of the filter.
Is there a more readable way of passing that argument, like customerFilter:{showLabel:true}?
Thanks.

BadValueError: Expected GeoPt

I am trying to pass values from a html form into the gae datastore and receive the following error:
"BadValueError: Expected GeoPt, got (51.123, -0.123)"
Apologies up front, but I'm new to this so may be going about it all wrong but would really appreciate some advice on the best way of doing this.
Thanks in advance.
Looks like you're trying to assign a tuple to the property instead of a geopt.
Your code does this:
entity.some_geo_property = (51.123, -0.123)
Where it needs to do this:
from google.appengine.ext import ndb
entity.some_geo_property = ndb.GeoPt(51.123, -0.123)
alternatively using the tuple:
entity.some_geo_property = ndb.GeoPt(*value)
Without seeing your exact code it's hard to offer a complete solution. If you provide code I'll try to update my answer.
I have never worked with GeoPt properties, but I would think that you passed a tuple of two floats.
Pass the value to ndb.GeoPt() first and store the return value in NDB. Example:
location = ndb.GeoPt(51.123, -0.123)
If you use the DB API of HRD rathern than the NDB API, use db.GeoPt() which is basically the same.

Resources