Using too many .and in my test how make it better. [Cypress] - mocha.js

I have written the below script and I feel I am using too many .and is there a more convenient way to write this?
cy.get('[data-cy="resumeSelectHiringManagerRowGroupLink"]')
.should('contain', '3')
.and ('contain', 'Resumes')
.and ('contain', 'awaiting next status change since')
.and ('contain', '7+ days')
.and ('contain', 'under')
.and ('contain', 'Resume Select - Hiring Manager')

You can shorten you code by doing like this:
const texts = [
'3',
'Resumes',
'awaiting next status change since',
'7+ days',
'under',
'Resume Select - Hiring Manager',
]
texts.forEach((text) => {
cy.get('[data-cy="resumeSelectHiringManagerRowGroupLink"]').should(
'contain',
text
)
})

Related

For Chart - Trying to Get data for last 30 days and add "0" if data is not available in particular date

I am trying to draw chart for Last 30 days from Today showing total milk quantity. I get last 30 days using - [0 => "2022-02-07" ----- 30 => "2022-03-09"]
$olddate = Carbon::today()->subDays(30)->toDateString();
$todaydate = Carbon::today()->toDateString();
Also get the Data for Database as below [ date" => "2022-03-01" "totalmilk" => "24.10" "daykey" => "01"................."date" => "2022-02-16" "totalmilk" => "22.90" "daykey" => "16"]
$rahul = Buffalomilkrecord::select(DB::raw('date'), DB::raw('sum(totalmilk) as totalmilk, DATE_FORMAT(date,"%d") as "daykey"'))
->whereBetween('date', [$olddate, $todaydate] )
->groupBy(DB::raw('date'))
->orderBy('date', 'desc')
->get();
BY Below code, trying to put "0" if data is not Available
$ddtest = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
foreach($rahul as $order)
{
$ddtest[$order->daykey-1] = $order->date;
}
The code is working fine except the start date he is taking the database date which is (2022-03-01) where it should start with "2022-02-07".
I think i am making mistake while getting "daykey". It is assigning daykey "1" to first data available in database which start from date ""2022-03-01" (as No data available from 07-02-2022 to 28-02-2022 in the database and it start from 1 March 2022.) where as it should start from "$olddate" that is ""2022-02-07"..
where did i am making the mistake.....Thanks in Advance

Magento get Shipping collectRates() attributes in observer

In a shippingModule in the collectRates method, i have set up a few values:
$method->setCarrier('test_customrate');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('test_customrate');
$method->setMethodTitle($this->getConfigData('name'));
$method->setPrice($this->getConfigData('price'));
$method->setCost(2);
$method->setUsername($this->getConfigData('username'));
$method->setPassword($this->getConfigData('password'));
$result->append($method);
Where are these values stored in the checkout session?
I can't find them anywhere.
I have now found that with the below mentioned code in the observer, i can get a couple of values back as mentioned above. However, some values like cost, username and password are not present here.
$rates = Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()
->getShippingRatesCollection();
foreach ($rates as $rate) {
Mage::log($rate->getData());
}
this retrieves something of the following structure:
2013-06-01T15:36:10+00:00 DEBUG (7): Array
(
[rate_id] => 852
[address_id] => 93
[created_at] => 2013-06-01 15:36:06
[updated_at] => 2013-06-01 15:36:09
[carrier] => test_customrate
[carrier_title] => test_customrate
[code] => test_customrate_test_customrate
[method] => test_customrate
[method_description] =>
[price] => 0.0000
[method_title] => test123
[error_message] =>
)
I worked around this by simply getting the values directly from the shipping module config.
Like this:
Mage::getStoreConfig('section/group/field');
So I'm just getting the data from system.xml like i did in the collectRates().
However this is quite static and i would still prefer a method to get this straight from the order.
For now this fixes my problem. If anything knows any other ways feel free to answer

Codeigniter CSV upload then explode

I have some code that uploads the CSV file to the specified folder, but it doesn't update the database.
public function do_upload()
{
$csv_path = realpath(APPPATH . '/../assets/uploads/CSV/');
$config['upload_path'] = $csv_path;
$config['allowed_types'] = '*'; // All types of files allowed
$config['overwrite'] = true; // Overwrites the existing file
$this->upload->initialize($config);
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->layout->buffer('content', 'program/upload', $error);
$this->layout->render();
}
else
{
$image_data = $this->upload->data();
$fname = $image_data['file_name'];
$fpath = $image_data['file_path'].$fname;
$fh = fopen($fpath, "r");
$insert_str = 'INSERT INTO wc_program (JobRef, Area, Parish, AbbrWorkType, WorkType, Timing, TrafficManagement, Location, Duration, Start, Finish) VALUES '."\n";
if ($fh) {
// Create each set of values.
while (($csv_row = fgetcsv($fh, 2000, ',')) !== false) {
foreach ($csv_row as &$row) {
$row = strtr($row, array("'" => "\'", '"' => '\"'));
}
$insert_str .= '("'
// Implode the array and fix pesky apostrophes.
.implode('","', $csv_row)
.'"),'."\n";
}
// Remove the trailing comma.
$insert_str = rtrim($insert_str, ",\n");
// Insert all of the values at once.
$this->db->set($insert_str);
echo '<script type="text/javascript">
alert("Document successfully uploaded and saved to the database.");
location = "program/index";
</script>';
}
else {
echo '<script type="text/javascript">
alert("Sorry! Something went wrong please proceed to try again.");
location = "program/upload";
</script>';
}
}
}
When I run var_dump($fh); it shows: resource(89) of type (stream)
When I run var_dump($fpath) it shows: string(66) "/Applications/MAMP/htdocs/site/assets/uploads/CSV/wc_program.csv"
So it all uploads but what is wrong with it not updating the database?
I have tried all kinds of changing the fopen method but still no joy, I really need it to add to the database and the insert query and set query should do the trick but it doesn't.
Any help greatly appreciated!
You are not running any query on the database. You are mixing active record syntax with simple query syntax. The active record insert query will be executed by calling.
$this->db->insert('my_table');
db::set() does not actually query the database. It takes in a key/value pair that will be inserted or updated after db::insert() or db::update() is called. If you build the query yourself you need to use the db::query() function.
Review the active directory documentation.
You can use $this->db->query('put your query here'), but you lose the benefit of CodeIgniter's built in security. Review CodeIgniter's query functions.
I'll give you examples of just a few of the many ways you can insert into a database using CodeIgniter. The examples will generate the query from your comment. You will need to adjust your code accordingly.
EXAMPLE 1:
$result = $this->db
->set('JobRef', 911847)
->set('Area', 'Coastal')
->set('Parish', 'Yapton')
->set('AbbrWorkType', 'Micro')
->set('WorkType', 'Micro-Asphalt Surfacing')
->set('Timing', 'TBC')
->set('TrafficManagement', 'No Positive Traffic Management')
->set('Location', 'Canal Road (added PMI 16/07/12)')
->set('Duration', '2 days')
->set('Start', '0000-00-00')
->set('Finish', '0000-00-00')
->insert('wc_program');
echo $this->db->last_query() . "\n\n";
echo "RESULT: \n\n";
print_r($result);
EXAMPLE 2 (Using an associative array):
$row = array(
'JobRef' => 911847,
'Area' => 'Coastal',
'Parish' => 'Yapton',
'AbbrWorkType' => 'Micro',
'WorkType' => 'Micro-Asphalt Surfacing',
'Timing' => 'TBC',
'TrafficManagement' => 'No Positive Traffic Management',
'Location' => 'Canal Road (added PMI 16/07/12)',
'Duration' => '2 days',
'Start' => '0000-00-00',
'Finish' => '0000-00-00'
);
$this->db->insert('wc_program', $row);
// This will do the same thing
// $this->db->set($row);
// $this->db->insert('wc_program');
echo $this->db->last_query();
Example 1 and 2 are using the Active Record. The information is stored piece by piece and then the query is built when you make the final call. This has several advantages. It allows you to build queries dynamically without worrying about SQL syntax and order of the keywords. It also escapes your data.
EXAMPLE 3 (Simple Query):
$query = 'INSERT INTO
wc_program
(JobRef, Area, Parish, AbbrWorkType, WorkType, Timing, TrafficManagement, Location, Duration, Start, Finish)
VALUES
("911847","Coastal","Yapton","Micro","Micro-Asphalt Surfacing","TBC","No Positive Traffic Management","Canal Road (added PMI 16/07/12)","2 days","0000-00-00","0000-00-00")';
$result = $this->db->query($query);
echo $this->db->last_query() . "\n\n";
echo "RESULT: \n";
print_r($result);
This way leaves all the protection against injection up to you, can lead to more errors, and is harder to change/maintain.
If you are going to do it this way you should use the following syntax, which will protect against injection.
EXAMPLE 4:
$query = 'INSERT INTO
wc_program
(JobRef, Area, Parish, AbbrWorkType, WorkType, Timing, TrafficManagement, Location, Duration, Start, Finish)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);';
$row = array(
911847,
'Coastal',
'Yapton',
'Micro',
'Micro-Asphalt Surfacing',
'TBC',
'No Positive Traffic Management',
'Canal Road (added PMI 16/07/12)',
'2 days',
'0000-00-00',
'0000-00-00'
);
$result = $this->db->query($query, $row);
echo $this->db->last_query() . "\n\n";
echo "RESULT: \n";
print_r($result);
CodeIgniter will replace each "?" in the query with the corresponding value from the array after it is escaped. You can use this to run many queries that are of the same form, but have different data just by updating the $row array and benefit from CI's built in security.

using get_metric_statistics in simple_aws using ruby

I am trying to explore the simple_aws gem. When I connect to cloudwatch to get the metric statistics I get an error as follows:
cw.get_metric_statistics(
:metric_name => metric_name,
:period => period,
:start_time => start_time,
:end_time => end_time,
:statistics => "Average",
:namespace => "AWS/EC2"
)
SimpleAWS::UnsuccessfulResponse: MissingParameter (400):
The parameter Namespace is required.
The parameter MetricName is required.
The parameter StartTime is required.
The parameter EndTime is required.
The parameter Period is required.
The parameter Statistics is required.
Later, I tried this:
cw.get_metric_statistics(
options => [
{:metric_name=>"CPUUtilization",
:period=>60,
:start_time => Time.now()-86400,
:end_time => Time.now()-3600,
:statistics => "Average"
}
]
)
But got the following error:
URI::InvalidComponentError: bad component(expected query component):
Action=GetMetricStatistics&{:metric_name=>"CPUUtilization"}.1.metric_name=CPUUtilization&{:metric_name=>"CPUUtilization"}.1.period=60&{:metric_name=>"CPUUtilization"}.1.start_time=2012-05-06%2014%3A25%3A28%20%2B0530&{:metric_name=>"CPUUtilization"}.1.end_time=2012-05-07%2013%3A25%3A28%20%2B0530&{:metric_name=>"CPUUtilization"}.1.statistics=Average&AWSAccessKeyId=AccessKey&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2012-05-07T08%3A55%3A28Z&Version=2010-08-01&Signature=Signature
one more try:
cw.get_metric_statistics(
namespace: 'AWS/EC2',
measure_name: 'CPUUtilization',
statistics: 'Average',
start_time: time-1000,
dimensions: "InstanceId=#{instance_id}"
)
ArgumentError: comparison of Array with Array failed
Can anybody please help find the correct syntax for issuing this command.
result = cw.get_metric_statistics(step,
start_time,
end_time,
metric,
'AWS/RDS',
'Average',
dimensions={'DBInstanceIdentifier': [indentifier]})
This also worked for me
I found that this works;
lat = cw.get_metric_statistics(
'MetricName' => 'Latency',
'Period' => 60,
'StartTime' => (Time.now() - 3600).iso8601,
'EndTime' => Time.now().iso8601,
'Statistics.member.1' => "Average",
'Namespace' => "AWS/ELB",
'Unit' => 'Seconds'
)
Firstly that the datetime is required in ISO8601 format, secondly that the parameters need to be cased correctly, thirdly the Unit parameter is required, and finally that Statistics needed a namespace(?) after it.
Hope this helps, even if it is a little late.

Export comments from fb:comments

I'm a little desperate about this. I have a site with a comments box with around 183000 comments that I want to backup. But every time I do an fql.query, I only get 100 items. I had tried:
SELECT xid, object_id, post_id, time, text, id FROM comment WHERE xid='bdatapoyo' ORDER BY time DESC
and after that, using the last "time"
SELECT xid, object_id, post_id, time, text, id FROM comment WHERE xid='bdatapoyo' AND time >= xxxxxxx ORDER BY time DESC
but the latter only gives me one comment..
I made an PHP page with this code, but again, it only grabs 100 items:
<?php
require 'php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXXX',
'secret' => 'XXXXXXXXXX',
'cookie' => true,
));
$conexion = mysql_connect("localhost", "XXXX", "XXXX");
mysql_select_db("TVN", $conexion);
$time_old = "1315070888";
do {
$fql = "SELECT fromid,time,text FROM comment WHERE xid='bdatapoyo' AND time >= " . $time_old . " ORDER BY time";
$response = $facebook->api(array(
'method' => 'fql.query',
'query' =>$fql,
));
foreach($response as $key => $value) {
$sql = "INSERT INTO comment (text, uuid, time) VALUES ('" . $value["text"] . "', '" . $value["fromid"] . "', '" . $value["time"] . "')";
$result = mysql_query($sql);
}
$time_old = $response[count($response)-1]["time"];
print_r($time_old);
} while (count($response) > 0);
?>
OK, I was able to pull this out with LIMIT and OFFSET. The correct FQL is
SELECT fromid,time,text FROM comment WHERE xid='bdatapoyo' LIMIT 100 OFFSET 0
and then paging with the OFFSET
is this code setup to import every single comment to a db from all users on your site? What is xid=bdatapoyo?

Resources