| 1 | use strict; |
|---|
| 2 | use Test::More; |
|---|
| 3 | |
|---|
| 4 | use Net::Google::Spreadsheets; |
|---|
| 5 | |
|---|
| 6 | my $ws; |
|---|
| 7 | BEGIN { |
|---|
| 8 | plan skip_all => 'set TEST_NET_GOOGLE_SPREADSHEETS to run this test' |
|---|
| 9 | unless $ENV{TEST_NET_GOOGLE_SPREADSHEETS}; |
|---|
| 10 | eval "use Config::Pit"; |
|---|
| 11 | plan skip_all => 'This Test needs Config::Pit.' if $@; |
|---|
| 12 | my $config = pit_get('google.com', require => { |
|---|
| 13 | 'username' => 'your username', |
|---|
| 14 | 'password' => 'your password', |
|---|
| 15 | } |
|---|
| 16 | ); |
|---|
| 17 | my $service = Net::Google::Spreadsheets->new( |
|---|
| 18 | username => $config->{username}, |
|---|
| 19 | password => $config->{password}, |
|---|
| 20 | ); |
|---|
| 21 | my $title = 'test for Net::Google::Spreadsheets'; |
|---|
| 22 | my $ss = $service->spreadsheet({title => $title}); |
|---|
| 23 | plan skip_all => "test spreadsheet '$title' doesn't exist." unless $ss; |
|---|
| 24 | plan tests => 8; |
|---|
| 25 | $ws = $ss->add_worksheet; |
|---|
| 26 | } |
|---|
| 27 | { |
|---|
| 28 | is scalar $ws->rows, 0; |
|---|
| 29 | $ws->batchupdate_cell( |
|---|
| 30 | {col => 1, row => 1, input_value => 'name'}, |
|---|
| 31 | {col => 2, row => 1, input_value => 'mail'}, |
|---|
| 32 | {col => 3, row => 1, input_value => 'nick'}, |
|---|
| 33 | ); |
|---|
| 34 | is scalar $ws->rows, 0; |
|---|
| 35 | my $value = { |
|---|
| 36 | name => 'Nobuo Danjou', |
|---|
| 37 | mail => 'nobuo.danjou@gmail.com', |
|---|
| 38 | nick => 'lopnor', |
|---|
| 39 | }; |
|---|
| 40 | my $row = $ws->add_row($value); |
|---|
| 41 | isa_ok $row, 'Net::Google::Spreadsheets::Row'; |
|---|
| 42 | is_deeply $row->content, $value; |
|---|
| 43 | my $value2 = { |
|---|
| 44 | name => 'Kazuhiro Osawa', |
|---|
| 45 | nick => 'yappo', |
|---|
| 46 | }; |
|---|
| 47 | $row->content($value2); |
|---|
| 48 | is_deeply $row->content, $value2; |
|---|
| 49 | is scalar $ws->rows, 1; |
|---|
| 50 | ok $row->delete; |
|---|
| 51 | is scalar $ws->rows, 0; |
|---|
| 52 | } |
|---|
| 53 | END { |
|---|
| 54 | $ws->delete; |
|---|
| 55 | } |
|---|