Postman null value in optional string field - postman

I'm writing a POST request in Postman. There is an optional field, which can contain null or a date (a string value). So, I have this in my POST request body:
"paidOn": "{{date}}"
It works great with non-null values, obviously. But if I put null in the paidOn column, it ends up like a string "null". If I put nothing, it ends up like an empty string "". In both cases, I get a 400 error.
I tried another approach too:
"paidOn": {{date}}
This one works ok with empty fields, but doesn't when I have an actual date in it (like, 2020-04-13T14:39:52) -> I get a 400 error.
Does anyone know how I could work it out?

Alright, I found something in another forum, which gave me an idea: https://sqa.stackexchange.com/a/42484/25137
I kept the following format:
"paidOn": {{date}}
And in the CSV file:
paidOn
"""non-null-value"""
null
Works like a charm.

Related

Data format in Ext JS forms and Django models is equivalent, but not works

When I POST my form, I receive the following exception:
act_date: ["Date has wrong format. Use one of these formats instead: YYYY-MM-DD."]
And the same validation error for other DateFields.
I changed the default date format in extjs (Ext.util.Format.defaultDateFormat= 'Y-m-d') which did not work.
So next I define date format in Django setting:
'DATE_FORMATS': [("%Y-%m-%d"),],
This also hasn't worked.
When you said I changed the default date format in extjs (Ext.util.Format.defaultDateFormat= 'Y-m-d') which did not work. it's the date format don't work or again you'r server validation ?
Cause actually if i do this :
var d = new Date();
Ext.Date.format(d, 'Y-m-d');
That give me : "2019-03-05" and it's seem to be correct.
Have you check inside of you'r POST request the format of the sending date ?
You maybe have a unexpected date format before sending you'r request.

TypeError: expected string or bytes-like object User.id

I'm trying to register an new Transaction object on the DB using Django, but I'm having TypeError: expected string or bytes-like object when I try to do user_id = user.id I can't really understand why this is happening, since I do the same steps when registering a new Bank object (as shown on prints below). I've tried to debug and the local variables have the correct value, I've also tried to cast user.id with string or int, but none of them worked.
traceback console error create Transaction method create Bank method
models.py
Firstly, please don't post code or errors as images; they are text, they should be posted as text in the question.
However I don't see anything in any of those snippets that suggest the error is with the user - that line is probably highlighted because it's the last in that multi-line call.
Rather, the error looks to be in the reference to date.today - if that's the datetime.date class, then today is a method, which you would need to call:
Transaction.objects.create(date=date.today(), ... )
Or, since that field has a default anyway, you could leave out the date attribute from the create call altogether.

Self.request.cookies.get is not returning complete value of the cookie in google app engine

I am setting the cookie value to (id, hash_of_id), but when the code is reading the value of the cookie it is getting only the part before comma. Not sure why:
These are the codes:
This is setting the values of the cookie named user_id.
self.response.headers.add_header('Set-Cookie', 'user_id = %s; Path=/'
% id_hash)
The value of id_hash is coming from following:
def make_hash(user_id): return hmac.new(SECRET,
str(user_id)).hexdigest()
def new_hash(user_id): id_hash = make_hash(user_id) return "%s,%s"
%((user_id), id_hash)
id_hash = new_hash(user.key().id())
When I am checking the value of the cookie in the browser using Edit this Cookie extension, it shows something like this:
This shows cookie has got id and hashed value of id.
Now value of cookie is being read:
cookiess = self.request.cookies.get('user_id')
When I am displaying the value of variable cookiess using
self.render("welcome.html", username = cookiess)
It shows only the part before comma,
enter image description here
I am not able to understand why the self.request.cookie.get returns value only till comma and not complete value.
Came to know that there is a bug in google appengine due to which
self.request.cookie.get()
was returning value only till comma. Instead of comma if something else like a pipe (|) is used as separator, then this function is working properly.

Can creationTime and other Directory meta-fields be used in a query?

I'm trying to filter the list of users returned from Directory.Users.List, and want to use the creationTime value in the filter. According to this:
Search for users
...you can use Date fields in comparisons, however when I try something like:
creationTime>=2016-06-30 (or the same value quoted)
...I get:
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid Input: creationTime>=2016-06-30",
"reason" : "invalid"
} ],
"message" : "Invalid Input: creationTime>=2016-06-30"
}
The message isn't particularly helpful - is this a syntax issue with the query, or is it the case that the field isn't available for query (it isn't listed in that article, but it is part of the JSON response)?
The article specifies the format for Date field queries, however this field also includes a time component, so I tried to also replicate the exact format that shows in the JSON, with the same result.
Also, same result in the Try it! section of the Users reference page.
Also also, tried using a numeric value (Date.getTime(), in effect) - same error.
Thanks...
P.S. Interestingly, Google does document how to search on date fields for Chromebooks, and it's entirely different than they imply for users. I still can't use creationTime with this, but it does work for Chromebooks. The other part of this is that it refers to fields that aren't documented, and why I try to use the documented field (e.g. lastSync vs. sync), it fails with the same message. This whole thing seems half-baked.
View Chrome device information
Only the fields listed in the table are searchable via the users.list search.
A workaround (I don't know if this is suitable for you) may be to push the data you want to use in a search into custom user fields. These fields are searchable.

Testing multiple JSON lines response

I am trying to make a test in Postman to verify some content in a JSON response. If I just try to verify a single line from the JSON response everything is fine. My problem starts when I need to test multiple lines of the JSON response. Is always failing. Any suggestion?
tests["Body matches string"] = responseBody.has("\"name\": null,
\"nameType\": \"NON_REFUNDABLE\"");
If I understand your question correctly I'd like to suggest that you approach this in a different way.
Instead of looking at the entire response body and seeing if the strings match you could alternatively test the individual Json properties that make up the response body. For example you could do the following:
var data = JSON.parse(responseBody);
tests["name is null"] = data.name === null;
tests["nameType is non-refundable"] = data.nameType === "NON_REFUNDABLE";
There are other alternatives as well but this is the first that comes to mind. For some more ideas about testing using postman check out their documentation and examples.