How to define a query parameter to be a list of specific values with Raml 1.0? - traits

I've been looking around on how to define the following queryParameters in RAML 1.0
/api/route?attrs=attr1,attr2,attr3
Where attr1,attr2 and attr3 are specific values and each one must be present only once
to make it more clear if I have a return object like
{
name: 'myName',
lastName: 'myLastName',
age: 20
}
The possible values in 'attrs' would be 'name','lastName' and 'age'.
i.e.
These are valid:
/api/route?attrs=name,lastName,age
/api/route?attrs=name,lastName
/api/route?attrs=name
These are invalid:
/api/route?attrs=name,lastName,name
/api/route?attrs=name,age,age
I appreciate your help and if anyone know how to accomplish this please let me know.
Thank you in advance.

You can define a regular expression pattern to validate the field.
https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#built-in-types

Related

Karate graphql variables inside query

I am trying to insert previously defined variable inside graphql query but I'm not able to find any example on how to do that except creating variables outside of query text and then making request with variables.
There is one problem for me for example in this example
queries: [{type: TERM, match: EQUAL, field: "fieldOne", value: "#(id)"},
{type: TERM, match: EQUAL, field: "fieldTwo", value: null}]
I want to insert value #(id) only for the first object in graphql query. Can anyone please provide some example for me or any suggestions on how to do that?
Alright I was thinking that it will be possible to directly replace text inside query, but I found solution from karate documentation with.
queries: [{type: TERM, match: EQUAL, field: "fieldOne", value: "<id>"},
{type: TERM, match: EQUAL, field: "fieldTwo", value: null}]
enclose id inside query text in angle brackets <> and then replace id inside query with id stored in variable id by calling
* replace query.id = id

How can i get the result of an query from BigQuery in Airflow, and attach it into an email auto-send to me

I want to use dynamic time {{ macros.ds_add(ds, 0) }}, so pandas_gbq.read_gbq doesn't work.
I also used the get_pandas_df of BigQueryHook, it showed 'BigQueryPandasConnector' object has no attribute 'http_error', the document says that I need to override DbApiHook method, but I don't know how.
And is there any solution for this issue? Appreciate for your help, guys.
Use BigQueryGetDataOperator. Following is an example:
Example: ::
get_data = BigQueryGetDataOperator(
task_id='get_data_from_bq',
dataset_id='test_dataset',
table_id='Transaction_partitions',
max_results='100',
selected_fields='DATE',
bigquery_conn_id='airflow-service-account'
)
Official Documentation: https://airflow.readthedocs.io/en/stable/integration.html#bigquerygetdataoperator

Can we validate dynamically generated values like datetime or any other number in Karate DSL

Can we validate dynamically generated values like datetime or any other number in Karate DSL. If yes, could you please tell how do we do it ?
Just make a JavaScript function replicating that dynamic value. and then do karate matching.
* def datetime = function(){code_generating_Date_time}
Then match datetime == response.datetime
Although i feel like generating the function should not be done, because it may become non-deterministic
Would suggest redesigning the test case.
Yes.
For example if the response is { id: 'a9f7a56b-8d5c-455c-9d13-808461d17b91', name: 'Billie' }
You can assert this way:
{ id: '#string', name: 'Billie' }
Please read the documentation, because all of this is explained there: https://github.com/intuit/karate#fuzzy-matching

django "use_natural_foreign_keys=True" issue

I currently use the well documented "use_natural_foreign_keys=True" to return the relevant field data required instead of the id:
all_orders = Orders.objects.all()
resp = serializers.serialize('json', all_orders, use_natural_foreign_keys=True)
What I don't know how to do is return both the id AND the field data required as typically returned by the "use of use_natural_foreign_keys=True".
Anyone know of a quick fix to return both?
Many thanks, Alan.
define a "natural_key" method in your model class, whose id and field_name you like to get. e.g
def natural_key(self):
return (self.id, self.field_name)

Query Appcelerator Cloud services Place with LIKE operator and case insensitive

Q) Is it possible to query Appcelerator cloud services Places objects (insensitive) where: - name LIKE 'fred' - SQL would be something like?
SELECT * FROM Places WHERE name like '%fred%'
I.e. query would return (if existing):
Fred
Alfred
Winnefred
Please tell me if this is possible with a simple code block using Ti.Cloud or REST or anything!
Note: I've read the documentation thoroughly but can't find an answer there. Please don't direct me to the documentation for the answer. Thanks.
Thanks.
Possibly. What you want is a $regex in the "where" parameter of Places.Query. The docs say it only supports prefix searches, but maybe it can do more. The below would be the equivalent of your select.
Ti.Cloud.Places.query({
where: {
name: { $regex: 'fred', $options: 'i' }
}
}, ...);
If it doesn't work, then you'll need to open up a feature request for it.
http://cloud.appcelerator.com/docs/api/v1/places/query
http://cloud.appcelerator.com/docs/search_query