Can i pass variable from Example section into table in behave scenario? - gherkin

Can i do something like this:
Response contains requested data
| method | status | url |
| post | 200 | <url_variable>|
Examples:
|url_variable|
| test1 |
|test2 |
Its a simple example just to show what i want. Is it possible in behave anyhow?

Basically i should have just tried what i suggested) it is literally like that, write variable name inside a table in <> quotes. And behave will understand it.

Related

Not able to pass CSV file data to call another feature in background

Not able to call one feature file from another when passing the data via CSV. Same works when i directly give in examples.
The below works
Background:
def rspSes = call read('classpath:helpers/createSessionID.feature') {"customerNo": '#(IP_Customer)'}
Scenario Outline: To validate based on different product combinations
Given path '/v1/sourceAccounts'
And param paymentType = "PERSONAL"
And header cus = IP_Customer
When method get
Then status <status>
Examples:
| IP_Customer | IP_FROM_ACCT | IP_TO_ACCT | AMOUNT | Purpose | Message | status |
| 165942 | 8957 | 1004 | 5.99 | PERSONAL | dkfkdjfkdjkfjdkjfkdjfkjd | 200 |
**However, if I change the above examples to read a CSV file. It is not picking the value from CSV. Tried changing {"customerNo": <IP_Customer>}, still didnt work. **
| read("testData.csv") |

Conditional update column B with modified value based on column A

I am facing a large table with data that got imported from a csv. However the delimiters in the csv where not sanitized, so the input data looked something like this:
alex#mail.com:Alex
dummy#mail.com;Bob
foo#bar.com:Foo
spam#yahoo.com;Spam
whatever#mail.com:Whatever
During the import : was defined as the delimiter, so each row with the delimiter ; was not imported properly. This resulted in a table structured like this:
| ID | MAIL | USER |
|-- --|---------------------|----------|
| 1 | alex#mail.com | ALEX |
| 2 | dummy#mail.com;Bob | NULL |
| 3 | foo#bar.com | Foo |
| 4 | spam#yahoo.com;Spam | NULL |
| 5 | whatever#mail.com | Whatever |
As reimporting is no option I was thinking about manually sanitizing the data in the affected rows by using SQL queries. So I tried to combine SELECT and UPDATE statements by filtering rows WHERE USER IS NULL and update both columns with the correct value where applicable.
What you need are string functions. Reading a bit, I find that Google BigQuery has STRPOS() and SUBSTR().
https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#substr
https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#strpos
An update query to fix the situation you are describing looks like this:
update table_name set mail =SUBSTR(mail,1,STRPOS(mail,';')-1), user =SUBSTR(mail,STRPOS(mail,';')+1) where user is null
The idea here is to split mail in its two parts, the part before the ; and the part after. Hope this helps.

Behat: How do you use multiline values in tables?

How do you use multiline values in tables?
Pystring dont work
| single | multi
| qewr | """
qewrqewr
qwerqre
"""
This doesnt either
| single | multi
| qewr | qewrqewr
| qwerqre
I want to use a scenario outline and seed a form with input multiple times, not having multilines would be a bugger.
You can use "," in your tables. For example:
| single | multi |
| one | one, two |
If you use TableNode extension, check your extension Gherkin.
It possible need upgrade.
https://github.com/Behat/Behat/issues/99
I hope that was helpful, though a bit late.

Multidimensional Tables in PostgreSQL

I have been wondering whether it's possible to do multidimensional tables in PostgreSQL. Here's an example table from my project:
id | created_by | content | comments |
---+---------------+----------------------------+----------+
1 | Anonymous | does this thing work? | |
2 | James | this is the body | |
3 | Chan | this must work this time~! | |
4 | Freak | just to add something new | |
5 | Anonymous | yahoo! | |
What do I mean by multidimensional table? It would look like something like this if there's such thing.
id | created_by | content | comments |
---+---------------+----------------------------+------------------------------------------+
1 | Anonymous | does this thing work? | id | created_by | comments |
2 | James | this is the body | |created_by| comments |
3 | Chan | this must work this time~! | |
4 | Freak | just to add something new | |
5 | Anonymous | yahoo! | |
This is just an example. But the key concept is that in every comment, there's another set of columns, making comments sort of like a table by itself.
So yeah, does this exist in Postgres or is there any better way to implement this feature? :)
I would like to convince you, if possible, to not encode your data this way, (independent of how terrible an idea it is)
Lets suppose you have a really hot post, goes viral, et-cetera. That means all of your users are viewing it and many are trying to comment on it. with all of your nested discussion embedded in a single row, all updates must apply to that row. This in turn means that every update on that discussion competes with every other to update that one attribute. As you might imagine, this write contention will make your database slow way down.
A second reason is that it violates the rules of first normal form; in the sense that the comment attribute on the table you're showing contains more than one value. The motivating reasoning for this widely applied rule is that it makes a larger number of queries possible. In your design, it would be very difficult to delete from COMMENTS where USER = 'spammy-user'*, or even select * from COMMENTS where text like '%Trending Topic%'. In general, if you might ever want to look at part of a value in a column, rather than the whole thing, then you're probably looking at an opportunity for normalization.
The rule I try to use is "each 'kind of thing' gets its own table". as comments are a 'kind of thing', we'll split them out:
create table COMMENTS(
COMMENT_ID serial primary key,
POST_ID integer not null foreign key references POSTS(ID),
PARENT_COMMENT_ID integer foreign key references COMMENTS(COMMENT_ID),
CREATED_BY ...
CONTENT ...
)
with the convention that comments having a null parent_comment_id are the roots of threaded discussions.

Select products, that have all of the parameters in column

I have a Product model and ProductParams, where I store product ids, column with some additional parameters(param) and param type.
It will look like that:
id | type | param
| |
1 | color | blue
1 | type | hard
2 | color | blue
2 | type | soft
.. | ..... | .....
How do I get only first product, when I call it with params = [blue, hard]?
For now I thought of something like Product.joins{product_params}.where{product_params.param.in params}.uniq, but I get 2nd as well, because it is blue too...
I use squeel gem, to constuct SQL queries, but answer doesn't have to be in squeel as well.
EDIT
I came up with solution, but it's a bit strange:
Product.joins{product_params}.where{product_params.param.in params}.group{id}.having{count(product_params.param) == 2}
But it would be great, if there was more graceful one.