BDD with Cucumber and MySQL — auto increment issues - mysql

I am writing some Cucumber features for my RoR app that insert records into the database then send a query to my XML API. Because of the nature of my requests (hardcoded XML) I need to know what the ID of a row is going to be. Here is my Scenario:
Scenario: Client requests call info
Given There is a call like:
| id | caller_phone_number |
| 1 | 3103937123 |
When I head over to call info
And Post this XML:
"""
<?xml version="1.0" encoding="UTF-8"?>
<request-call-info>
<project-code>1000000001</project-code>
</request-call-info>
"""
Then The call info should match
And The status code should be 0
I've got Cuke set up with my _test database, and I also noticed that it isn't resetting all of the tables prior to running my features.
What is the right way to set this up? Thanks!

Firstly, forgive me as this is going to be a bit of a brain dump, but hopefully it should help or at least give you some ideas:
You could rewrite your scenario like this:
Scenario: Client requests call info
Given There is a call with the phone number "3102320"
When I post "request-call-info" xml to "call info" for the phone number "3102320"
Then the call info for phone number "3102320" should match
And the status code for phone number "3102320" should be 0
This way you can refer to the record by an attribute that isn't the primary key.
Are you using fixtures? If so you can set the ID for the record there explicitly.
Depending on your application you might be able to run your tests using an in memory sqlite3 database.

Related

What is the URL when I DELETE an object

I'm running a local server playing around with an API using Django. I have a model called 'Users' populated with a few objects, and am using DefaultRouter.
I want to know what the URL would be if I were to DELETE a specific object from this model. For example, if I wanted to GET a user with an ID of 1 in this model, the URL would be: "localhost:8000/Users/1/". What would the equivalent be to DELETE this user?
I found an explanation of this on the REST API website (below), however, I don't understand what any of the syntaxes means.
What is {prefix}, {url_path}, {lookup} and [.format]? If anyone could provide an example of what this might be using a localhost that would be really helpful.
Thanks
Let us take an example of an API (URL) to update book data with id (pk) being 10. It would look something like this:
URL: http://www.example.com/api/v1/book/10/
Method: PUT/PATCH
With some data associated.
If you want to delete you just need to change method to DELETE instead of put or patch.
Regarding your second question lets compare the url with the parameters.
prefix: http://www.example.com/api/v1/book
lookup: 10
format: It specifies what type of data do you expect when you hit the API. Generally it is considered to be json.
url_path: In general, every thing after look up except query string is considered to be url_path.

ESP8266 and mySQL

To begin with, I set up my database which includes (an id (which is auto increment), username, email, and 2 more which are place0 and place1 (those two are boolean type)). Now my question is how can I connect an esp8266 directly to the database and update the booleans from 0 to 1 and back using a button for each one? Also, how can I read the boolean on the esp and turn an led for example? I need to make it update the values for a selected user not all of them....for example, I have users with id 1, 2, 3...i need to make the updates only on 1 if that one is selected...
Note that both the database and the esp8266 are in my house (on a local network)
Thanks very much
Nikolaos Konstantinou
NcCon
The best way I can think of is ESP8266 to Web Server(PHP/Python/NodeJS etc) to MySQL
Send the boolean values in the form of the HTTP Post method and handle the post method in Webserver then update the MYSQL table.
check out this link
For some reason, if you want to avoid webserver you can try micro python upymysql module which helps to directly communicate the database from ESP board uPyMySQL

How to Implement logging at the end of each job In talend?

I am new to Talend os.
However, I received a task:
Create file delimited .csv metadata (one for Lead & Opportunity).
Move files to your repository on the AWS server (the etl_process1 login).
Create two tables sfdc_leads_reporting_raw and sfdc_opp_reporting_raw.
Load the data from the files into the tables. Ensure the data types are correctly used when creating metadata schemas & tables.
Till step 4 I am done.
Now the problem is:
How to Implement logging at the end of each job to report the number of leads (count of distinct id in leads table) and number of opportunities created (count of opportunity id) by stages (how many converted, qualified, closed won, and dead)?
Help would be appreciated.
You can get this data using global variables, in a subjob at the end of your job. Most components provide a global variable called tComponent_NB_LINE (or _NB_LINE_INSERTED for database components) that gives you the number of lines output by the component.
For instance tFileOutputDelimited_1_NB_LINE or tOracleOutput_1_NB_LINE_INSERTED.
Using these variables you can log into console or file.
Here is a simple example. If you have a tOracleOutput_1 in your job you can do:
tPostJob -- OnComponentOk -- tFixedFlowInput -- Main -- tLogRow
Inside tFixedFlowInput you retrieve the variable
(Integer)globalMap.get("tOracleOutput_1_NB_LINE_INSERTED")`.
If you need to log aggregated info, you can append a tAggregateRow to your output components, and use tSetGlobalVar to get count by certain criteria.

Couchbase compound keys in views with the C SDK

I'm trying to implement a very basic C application that queries a Couchbase view using the C SDK. I got the SDK as such working since I can retrieve data from the DB server and even query views with a range query (startkey and endkey). However, if I create a view with a compound key, i.e. an index with two values, then I get nothing back. If I implement the same view in PHP or Node I get the correct data back. My understanding of the C SDK is that it uses the REST API of Couchbase, so the options string (optstr) is essentially the same as if I would use the Couchbase in-built web management console. Using single numeric start and end keys I get it all to work, but as soon as I start using compound keys like
startkey=["test",2]&endkey=["test",4]
I get no results back. The query string that does return data looks like
startkey=2&endkey=4
The bucket has only 5 documents of the following structure:
{number: 1, name: "test"}
with the number simply being between 1 and 5.
the view for the compound key looks like:
function (doc, meta) {
emit([doc.name, doc.number], doc);
}
and the one for the single key simply has the doc.number as the first value in the emit without being an array.
The code that I'm using for the compound key in C looks like:
lcb_CMDVIEWQUERY vq = {0};
vq.optstr = "startkey=[\"test\",2]&endkey=[\"test\",4]";
vq.noptstr = strlen(vq.optstr);
lcb_view_query_initcmd(&vq, "ddoc", "myView", NULL, viewCallback);
lcb_error_t rc = lcb_view_query(instance, NULL, &vq);
What am I missing for the compound views? The examples on the Couchbase website don't cover views using any keys and the examples in their Git repository don't have any examples either. The Couchbase C SDK seems to be a but light on documentation, even the API documentation doesn't seem to be very detailed.
Any help is appreciated.
It would help if the view with the compound key would actually being published! The code actually does work as intended. However, it would be interesting to get peoples views on the formatting of the query/option string and if it should be URL encoded or not when created.
Update:
After setting up a new Couchbase server and populating it with the same data set and rebuilding the view it actually does work. So I have no idea why it didn't work against the original server. I have gone through the map function with a fine toothed comb and checked the correct spelling (uppercase/lowercase) of all variables and parameters. At least it does work. :)

How the google charts query language works?

I have implemented my own datasource in Go, which returns a JSON string. The data source is working fine and returning the correct JSON format expected by the chart (which is actually a table object to make the tests easier).
Now, I'd like to be able to use the query language features for my chart and something I could not figure out is how exactly the query language works.
Let's take the table below as example:
Name | Age | Phone
-------------------------------
John | 23 | 12341234
Chris | 47 | 54223452
Sam | 36 | 69694356
When called, my datasource will return a JSON representation of the entire table above.
In theory, I should be able to do something like this from my Javascript
query.setQuery('select Name, Age');
So, the result would ignore the column "Phone".
Now, my question is:
Is the setQuery() method applied to the JSON response only, or my datasource should be able to handle the query on request and return the correct data (only Name and Age columns). I'm not sure if the query language will act on the JSON response or if it's just an interface to tell the server what to do and the server should be able to prepare the correct data.
I'm asking that because as I said, my JSON response works fine, however the setQuery() method is being ignored. My table always shows the entire Dataset, no matter what I put on the setQuery method. Even if I define a column which does not exist, it does not cause any error.
I did some tests using a google spreadsheet and it works just fine. I should add that the structure of the JSON response from my app and the one from the google spreadsheet looks exactly the same.
Any help would be very much appreciated.
Thanks,
JB