Gatling Pebble Templating - gatling

I am having issues resolving the dot (.) notation of pebble templating in Gatling to retrieve attributes of variables, such as Map key values.
Here's an example of a session attribute that I've defined:
session => session.set("location", Map("text" -> "Alabama"))
I'm trying to replace {{ location.text }} in the following json template file with the value "Alabama":
...
"text": "{{ location.text }}",
...
However, it looks like Gatling is unable to resolve the attribute, and therefore, the result is an empty string.
I am using version 3.2.1 of Gatling.
Any help would be appreciated, thanks!

Answered here: https://groups.google.com/forum/#!topic/gatling/23CuH88x1Vo
Since Pebble is a Java library...
after converting the map to a java.util.Map datatype using scala.collection.JavaConverters, I was able to successfully use Pebble dot (.) notation for traversing the map.

Related

Returning a JSON array of translated content using i18n

Context: I am making a multi-language page using the react-i18next module of ReactJS.
Issue: I cannot access the arrayed JSON content.
The translated content being stored in separate JSON files for each language, non-array content works fine and gets correctly displayed and translated, however, I can't seem to use the arrayed content on my React components, let alone access its content through console.log().
Below is an example of my translationEN.json file:
{
"name": "Test",
"occupations":["occupation1",
"Part-time occupation2",
"Language enthusiast"]
}
I am being able to refer to the non-array name using i18n.t("name").
However, attempting to access my arrayed occupations using i18n.t("occupations") results in the following console.log:
key 'occupations (en)' returned an object instead of string.
Using JSON.stringify() doesn't solve the issue, neither does console.log(i18n.t("occupations"), { returnObjects: true }) as suggested on i18next's documentation
Thanks in advance!
Problem solved.
The array values can be accessed as such: i18n.t("occupations.0") for occupation 1, i18n.t("occupations.1") for Part-time occupation 2 and i18n.t("occupations.2") for Language enthusiast.
I just need to loop it out to make it look cleaner.

Airflow XCom to Python Variable

I have a stored XCom expense_list that I want to convert into a Python variable
expense_variable (rather than passing it into a templated field). I tried to set the variable in my DAG, but the following code did not work.
expense_variable = "{{task_instance.xcom_pull(task_ids='expense_list')}}"
How can I convert the stored XCom expense_list into a Python variable expense_variable in Airflow? Is there a function or operator for this?
Recall that JINJA templating is a helpful feature provided by Airflow guys to ease our lives; and it doesn't mean we have to (or that we should use) JINJA templates everywhere, notwithstanding that we really can't.
Once again citing gotchas from Gtoonstra (that you seemed to have missed in previous answer)
Not all parameters in operators are templated, so you cannot use Jinja
templates everywhere. The Jinja templates only work for those fields
in operators where it’s listed in the template_fields list inside the
source file, like:
template_fields = ('audit_key', 'cycle_dtm')
In this particular case, there is no reason to pull XCOMs via JINJA template. You can simply refer to the docs that show how you can pull them via task_instance object obtained from context dict
expense_variable = context['task_instance'].xcom_pull(task_ids='expense_list')

Adding Editors to a Google Document with Google Apps Script

I'm trying to add editors and viewers to a Google Doc using Google Apps Script. The documentation of addEditors() says that:
Adds the given array of users to the list of editors for the Document.
I can't figure out how to configure or use an array for this. The array is determined by values passed from a different script file.
Well, without any code to start with you need to do something like the following:
function addEditors() {
var emails = [
'john#example.com',
'steve#example.com',
'bill#example.com'
];
DocumentApp.getActiveDocument().addEditors(emails);
}
Arrays are a variable type in Javascript that you need to know to get started with Apps Script.
You can read more about arrays here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
Or get some practice at FreeCodeCamp: https://www.freecodecamp.com/challenges/store-multiple-values-in-one-variable-using-javascript-arrays
Good luck.

W3C validation - unable to pass arrays in href

I am using w3c validator with html5. I have an array afilter[]=abc I am passing in the href and I have tried escaping the brackets as follows:
<a href='slideshowform.php?x=y&afilter[]=abc'>phases of matter</a>
But I am still getting the error:
Bad value slideshowform.php?x=y&afilter[]=abc for attribute href on element a: Illegal character in query component.
How can I pass an array without getting errors - or did I escape the brackets incorrectly?
You have to URL encode it, not HTML encode it. Your URL would have to look like the following:
slideshowform.php?x=y&afilter%5B%5D=abc
Most programming languages have stuff like this built in (e.g. rawurlencode() in PHP or encodeURI in JavaScript) or you can simply use an online service like (no affiliation, just one of the first search results) http://www.url-encode-decode.com/
Of course it’s a good idea to encode the HTML reserved characters for outputting the link in an HTML document as well. So you’d end up with the following URL within your HTML document.
slideshowform.php?x=y&afilter%5B%5D=abc

Google App Engine Go SDK update problems with template

I`ve just updated my GAE Go SDK to the newest release. I ran the gofix
on my code, but there were still some errors. The code used to look:
AnkietaTemp = template.New(nil)
err := AnkietaTemp.ParseFile("ankieta/ankieta.html")
but now passing nil doesn't seem to work, so I replaced it into:
AnkietaTemp = template.New("")
_, err := AnkietaTemp.ParseFile("ankieta/ankieta.html")
Tried running my app, but in HTML source I get:
<td width="400"><img src="images/{.section One}{#}{.end}"
alt="images/{.section One}{#}{.end}" width="100%"/></td>
Instead of a neat reference to an image file.
What is the proper way to parse the template files now, after the
update?
In the new template package the template tag syntax changed, as you can see in the documentation. E.g. dot (.) is used instead of # for referencing the "current" item and the template tags are indicated with two curly braces instead of one.
Edit: Oh, and there's no .section tag any more. You didn't provide the structure you pass to template's Execute() method so I can't provide details on how mitigate that exactly, but I guess you can use {{with}} tag like {{with One}}{.}{{end}} or maybe {{.One}}.

Resources