Fixed twitter tests.
This commit is contained in:
parent
be6c374cdc
commit
d882c77546
2 changed files with 93 additions and 66 deletions
|
@ -45,6 +45,18 @@ job_integration_email_helper:
|
||||||
- rake db:migrate
|
- rake db:migrate
|
||||||
- ruby -I test/ test/integration/email_helper_test.rb
|
- ruby -I test/ test/integration/email_helper_test.rb
|
||||||
|
|
||||||
|
job_integration_twitter:
|
||||||
|
stage: test
|
||||||
|
tags:
|
||||||
|
- core
|
||||||
|
script:
|
||||||
|
- export RAILS_ENV=test
|
||||||
|
- rake db:drop;
|
||||||
|
- rake db:create
|
||||||
|
- rake db:migrate
|
||||||
|
- rake db:seed
|
||||||
|
- ruby -I test/ test/integration/twitter_test.rb
|
||||||
|
|
||||||
job_integration_geo_ip:
|
job_integration_geo_ip:
|
||||||
stage: test
|
stage: test
|
||||||
tags:
|
tags:
|
||||||
|
|
|
@ -16,16 +16,34 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
)
|
)
|
||||||
|
|
||||||
# app config
|
# app config
|
||||||
consumer_key = 'd2zoZBmMXmT7KLPgEHSzpw'
|
if !ENV['TWITTER_APP_CONSUMER_KEY']
|
||||||
consumer_secret = 'QMUrlyDlqjITCkWdrOgsTxMVVLxr4A4IW3DIgtIg'
|
fail "ERROR: Need TWITTER_APP_CONSUMER_KEY - hint TWITTER_APP_CONSUMER_KEY='1234'"
|
||||||
|
end
|
||||||
|
if !ENV['TWITTER_APP_CONSUMER_SECRET']
|
||||||
|
fail "ERROR: Need TWITTER_APP_CONSUMER_SECRET - hint TWITTER_APP_CONSUMER_SECRET='1234'"
|
||||||
|
end
|
||||||
|
consumer_key = ENV['TWITTER_APP_CONSUMER_KEY']
|
||||||
|
consumer_secret = ENV['TWITTER_APP_CONSUMER_SECRET']
|
||||||
|
|
||||||
# armin_theo (is system and is following marion_bauer)
|
# armin_theo (is system and is following marion_bauer)
|
||||||
armin_theo_token = '1405469528-WQ6XHizgrbYasUwjp0I0TUONhftNkrfrpgFLrdc'
|
if !ENV['TWITTER_SYSTEM_TOKEN']
|
||||||
armin_theo_token_secret = '0LHChGFlQx9jSxM8tkBsuDOMhbJMSXTL2zKJJO5Xk'
|
fail "ERROR: Need TWITTER_SYSTEM_TOKEN - hint TWITTER_SYSTEM_TOKEN='1234'"
|
||||||
|
end
|
||||||
|
if !ENV['TWITTER_SYSTEM_TOKEN_SECRET']
|
||||||
|
fail "ERROR: Need TWITTER_SYSTEM_TOKEN_SECRET - hint TWITTER_SYSTEM_TOKEN_SECRET='1234'"
|
||||||
|
end
|
||||||
|
armin_theo_token = ENV['TWITTER_SYSTEM_TOKEN']
|
||||||
|
armin_theo_token_secret = ENV['TWITTER_SYSTEM_TOKEN_SECRET']
|
||||||
|
|
||||||
# me_bauer (is following armin_theo)
|
# me_bauer (is following armin_theo)
|
||||||
me_bauer_token = '1406098795-XQTjg1Zj5uVW0C11NNpNA4xopyclRJJoriWis0I'
|
if !ENV['TWITTER_CUSTOMER_TOKEN']
|
||||||
me_bauer_token_secret = 'T8ph5afeSDjGDA9X1ZBlzEvoSiXfN266ZZUMj5UaY'
|
fail "ERROR: Need CUSTOMER_TOKEN - hint TWITTER_CUSTOMER_TOKEN='1234'"
|
||||||
|
end
|
||||||
|
if !ENV['TWITTER_CUSTOMER_TOKEN_SECREET']
|
||||||
|
fail "ERROR: Need CUSTOMER_TOKEN_SECREET - hint TWITTER_CUSTOMER_TOKEN_SECREET='1234'"
|
||||||
|
end
|
||||||
|
me_bauer_token = ENV['TWITTER_CUSTOMER_TOKEN']
|
||||||
|
me_bauer_token_secret = ENV['TWITTER_CUSTOMER_TOKEN_SECREET']
|
||||||
|
|
||||||
# add channel
|
# add channel
|
||||||
current = Channel.where(area: 'Twitter::Account')
|
current = Channel.where(area: 'Twitter::Account')
|
||||||
|
@ -64,7 +82,7 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
)
|
)
|
||||||
|
|
||||||
test 'new outbound and reply' do
|
test 'a new outbound and reply' do
|
||||||
|
|
||||||
hash = '#citheo42' + rand(9999).to_s
|
hash = '#citheo42' + rand(9999).to_s
|
||||||
user = User.find(2)
|
user = User.find(2)
|
||||||
|
@ -78,18 +96,18 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
assert( ticket, "outbound ticket created, text: #{text}" )
|
assert(ticket, "outbound ticket created, text: #{text}")
|
||||||
|
|
||||||
article = Ticket::Article.create(
|
article = Ticket::Article.create(
|
||||||
ticket_id: ticket.id,
|
ticket_id: ticket.id,
|
||||||
body: text,
|
body: text,
|
||||||
type: Ticket::Article::Type.find_by( name: 'twitter status' ),
|
type: Ticket::Article::Type.find_by(name: 'twitter status'),
|
||||||
sender: Ticket::Article::Sender.find_by( name: 'Agent' ),
|
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
|
||||||
internal: false,
|
internal: false,
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
assert( article, "outbound article created, text: #{text}" )
|
assert(article, "outbound article created, text: #{text}")
|
||||||
|
|
||||||
# reply by me_bauer
|
# reply by me_bauer
|
||||||
client = Twitter::REST::Client.new do |config|
|
client = Twitter::REST::Client.new do |config|
|
||||||
|
@ -102,11 +120,11 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
tweet_found = false
|
tweet_found = false
|
||||||
client.user_timeline('armin_theo').each { |tweet|
|
client.user_timeline('armin_theo').each { |tweet|
|
||||||
|
|
||||||
next if tweet.id != article.message_id
|
next if tweet.id.to_s != article.message_id.to_s
|
||||||
tweet_found = true
|
tweet_found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
assert( tweet_found, "found outbound '#{text}' tweet '#{article.message_id}'" )
|
assert(tweet_found, "found outbound '#{text}' tweet '#{article.message_id}'")
|
||||||
|
|
||||||
reply_text = '@armin_theo on my side the weather is nice, too! 😍😍😍 #weather' + rand(9999).to_s
|
reply_text = '@armin_theo on my side the weather is nice, too! 😍😍😍 #weather' + rand(9999).to_s
|
||||||
tweet = client.update(
|
tweet = client.update(
|
||||||
|
@ -122,12 +140,12 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
# check if follow up article has been created
|
# check if follow up article has been created
|
||||||
article = Ticket::Article.find_by( message_id: tweet.id )
|
article = Ticket::Article.find_by( message_id: tweet.id )
|
||||||
|
|
||||||
assert( article, "article tweet '#{tweet.id}' imported" )
|
assert(article, "article tweet '#{tweet.id}' imported")
|
||||||
assert_equal( 2, article.ticket.articles.count, 'ticket article inbound count' )
|
assert_equal(2, article.ticket.articles.count, 'ticket article inbound count')
|
||||||
assert_equal( reply_text.utf8_to_3bytesutf8, ticket.articles.last.body, 'ticket article inbound body' )
|
assert_equal(reply_text.utf8_to_3bytesutf8, ticket.articles.last.body, 'ticket article inbound body')
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'new inbound and reply' do
|
test 'b new inbound and reply' do
|
||||||
|
|
||||||
# new tweet by me_bauer
|
# new tweet by me_bauer
|
||||||
client = Twitter::REST::Client.new do |config|
|
client = Twitter::REST::Client.new do |config|
|
||||||
|
@ -142,22 +160,19 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
tweet = client.update(
|
tweet = client.update(
|
||||||
text,
|
text,
|
||||||
)
|
)
|
||||||
sleep 20
|
sleep 15
|
||||||
|
|
||||||
# fetch check system account
|
|
||||||
Channel.fetch
|
|
||||||
|
|
||||||
# fetch check system account
|
# fetch check system account
|
||||||
article = nil
|
article = nil
|
||||||
(1..4).each {
|
(1..3).each {
|
||||||
Channel.fetch
|
Channel.fetch
|
||||||
|
|
||||||
# check if ticket and article has been created
|
# check if ticket and article has been created
|
||||||
article = Ticket::Article.find_by( message_id: tweet.id )
|
article = Ticket::Article.find_by(message_id: tweet.id)
|
||||||
|
|
||||||
break if article
|
break if article
|
||||||
|
|
||||||
sleep 5
|
sleep 10
|
||||||
}
|
}
|
||||||
assert(article)
|
assert(article)
|
||||||
ticket = article.ticket
|
ticket = article.ticket
|
||||||
|
@ -167,25 +182,24 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
article = Ticket::Article.create(
|
article = Ticket::Article.create(
|
||||||
ticket_id: ticket.id,
|
ticket_id: ticket.id,
|
||||||
body: reply_text,
|
body: reply_text,
|
||||||
type: Ticket::Article::Type.find_by( name: 'twitter status' ),
|
type: Ticket::Article::Type.find_by(name: 'twitter status'),
|
||||||
sender: Ticket::Article::Sender.find_by( name: 'Agent' ),
|
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
|
||||||
internal: false,
|
internal: false,
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
assert( article, "outbound article created, text: #{reply_text}" )
|
assert(article, "outbound article created, text: #{reply_text}")
|
||||||
|
sleep 2
|
||||||
tweet_found = false
|
tweet_found = false
|
||||||
client.user_timeline('armin_theo').each { |local_tweet|
|
client.user_timeline('armin_theo').each { |local_tweet|
|
||||||
|
next if local_tweet.id.to_s != article.message_id.to_s
|
||||||
next if local_tweet.id != article.message_id
|
|
||||||
tweet_found = true
|
tweet_found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
assert( tweet_found, "found outbound '#{reply_text}' tweet '#{article.message_id}'" )
|
assert(tweet_found, "found outbound '#{reply_text}' tweet '#{article.message_id}'")
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'new by direct message inbound' do
|
test 'c new by direct message inbound' do
|
||||||
|
|
||||||
# cleanup direct messages of system
|
# cleanup direct messages of system
|
||||||
client = Twitter::REST::Client.new do |config|
|
client = Twitter::REST::Client.new do |config|
|
||||||
|
@ -194,7 +208,7 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
config.access_token = armin_theo_token
|
config.access_token = armin_theo_token
|
||||||
config.access_token_secret = armin_theo_token_secret
|
config.access_token_secret = armin_theo_token_secret
|
||||||
end
|
end
|
||||||
dms = client.direct_messages( count: 200 )
|
dms = client.direct_messages(count: 200)
|
||||||
dms.each {|dm|
|
dms.each {|dm|
|
||||||
client.destroy_direct_message(dm.id)
|
client.destroy_direct_message(dm.id)
|
||||||
}
|
}
|
||||||
|
@ -204,7 +218,7 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
access_token: me_bauer_token,
|
access_token: me_bauer_token,
|
||||||
access_token_secret: me_bauer_token_secret
|
access_token_secret: me_bauer_token_secret
|
||||||
)
|
)
|
||||||
dms = client.direct_messages( count: 200 )
|
dms = client.direct_messages(count: 200)
|
||||||
dms.each {|dm|
|
dms.each {|dm|
|
||||||
client.destroy_direct_message(dm.id)
|
client.destroy_direct_message(dm.id)
|
||||||
}
|
}
|
||||||
|
@ -215,55 +229,55 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
'armin_theo',
|
'armin_theo',
|
||||||
text,
|
text,
|
||||||
)
|
)
|
||||||
assert( dm, "dm with ##{hash} created" )
|
assert(dm, "dm with ##{hash} created")
|
||||||
|
|
||||||
# fetch check system account
|
# fetch check system account
|
||||||
article = nil
|
article = nil
|
||||||
(1..4).each {
|
(1..2).each {
|
||||||
Channel.fetch
|
Channel.fetch
|
||||||
|
|
||||||
# check if ticket and article has been created
|
# check if ticket and article has been created
|
||||||
article = Ticket::Article.find_by( message_id: dm.id )
|
article = Ticket::Article.find_by(message_id: dm.id)
|
||||||
|
|
||||||
break if article
|
break if article
|
||||||
|
|
||||||
sleep 5
|
sleep 10
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( article, "inbound article '#{text}' created" )
|
assert(article, "inbound article '#{text}' created")
|
||||||
ticket = article.ticket
|
ticket = article.ticket
|
||||||
assert( ticket, 'ticket of inbound article exists' )
|
assert(ticket, 'ticket of inbound article exists')
|
||||||
assert( ticket.articles, 'ticket.articles exists' )
|
assert(ticket.articles, 'ticket.articles exists')
|
||||||
assert_equal( 1, ticket.articles.count, 'ticket article inbound count' )
|
assert_equal(1, ticket.articles.count, 'ticket article inbound count')
|
||||||
assert_equal( ticket.state.name, 'new' )
|
assert_equal(ticket.state.name, 'new')
|
||||||
|
|
||||||
# reply via ticket
|
# reply via ticket
|
||||||
outbound_article = Ticket::Article.create(
|
outbound_article = Ticket::Article.create(
|
||||||
ticket_id: ticket.id,
|
ticket_id: ticket.id,
|
||||||
to: 'me_bauer',
|
to: 'me_bauer',
|
||||||
body: 'Will call you later!',
|
body: 'Will call you later!',
|
||||||
type: Ticket::Article::Type.find_by( name: 'twitter direct-message' ),
|
type: Ticket::Article::Type.find_by(name: 'twitter direct-message'),
|
||||||
sender: Ticket::Article::Sender.find_by( name: 'Agent' ),
|
sender: Ticket::Article::Sender.find_by(name: 'Agent'),
|
||||||
internal: false,
|
internal: false,
|
||||||
updated_by_id: 1,
|
updated_by_id: 1,
|
||||||
created_by_id: 1,
|
created_by_id: 1,
|
||||||
)
|
)
|
||||||
ticket.state = Ticket::State.find_by( name: 'pending reminder' )
|
ticket.state = Ticket::State.find_by(name: 'pending reminder')
|
||||||
ticket.save
|
ticket.save
|
||||||
|
|
||||||
assert( outbound_article, 'outbound article created' )
|
assert(outbound_article, 'outbound article created')
|
||||||
assert_equal( 2, outbound_article.ticket.articles.count, 'ticket article outbound count' )
|
assert_equal(2, outbound_article.ticket.articles.count, 'ticket article outbound count')
|
||||||
|
|
||||||
text = 'Ok. ' + hash
|
text = 'Ok. ' + hash
|
||||||
dm = client.create_direct_message(
|
dm = client.create_direct_message(
|
||||||
'armin_theo',
|
'armin_theo',
|
||||||
text,
|
text,
|
||||||
)
|
)
|
||||||
assert( dm, "second dm with ##{hash} created" )
|
assert(dm, "second dm with ##{hash} created")
|
||||||
|
|
||||||
# fetch check system account
|
# fetch check system account
|
||||||
article = nil
|
article = nil
|
||||||
(1..4).each {
|
(1..2).each {
|
||||||
Channel.fetch
|
Channel.fetch
|
||||||
|
|
||||||
# check if ticket and article has been created
|
# check if ticket and article has been created
|
||||||
|
@ -271,18 +285,18 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
break if article
|
break if article
|
||||||
|
|
||||||
sleep 5
|
sleep 10
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( article, "inbound article '#{text}' created" )
|
assert(article, "inbound article '#{text}' created")
|
||||||
ticket = article.ticket
|
ticket = article.ticket
|
||||||
assert( ticket, 'ticket of inbound article exists' )
|
assert(ticket, 'ticket of inbound article exists')
|
||||||
assert( ticket.articles, 'ticket.articles exists' )
|
assert(ticket.articles, 'ticket.articles exists')
|
||||||
assert_equal( 3, ticket.articles.count, 'ticket article inbound count' )
|
assert_equal(3, ticket.articles.count, 'ticket article inbound count')
|
||||||
assert_equal( ticket.state.name, 'open' )
|
assert_equal(ticket.state.name, 'open')
|
||||||
|
|
||||||
# close dm ticket, next dm should open a new
|
# close dm ticket, next dm should open a new
|
||||||
ticket.state = Ticket::State.find_by( name: 'closed' )
|
ticket.state = Ticket::State.find_by(name: 'closed')
|
||||||
ticket.save
|
ticket.save
|
||||||
|
|
||||||
text = 'Thanks for your call . I just have one question. ' + hash
|
text = 'Thanks for your call . I just have one question. ' + hash
|
||||||
|
@ -290,26 +304,27 @@ class TwitterTest < ActiveSupport::TestCase
|
||||||
'armin_theo',
|
'armin_theo',
|
||||||
text,
|
text,
|
||||||
)
|
)
|
||||||
assert( dm, "third dm with ##{hash} created" )
|
assert(dm, "third dm with ##{hash} created")
|
||||||
|
|
||||||
# fetch check system account
|
# fetch check system account
|
||||||
article = nil
|
article = nil
|
||||||
(1..4).each {
|
(1..2).each {
|
||||||
Channel.fetch
|
Channel.fetch
|
||||||
|
|
||||||
# check if ticket and article has been created
|
# check if ticket and article has been created
|
||||||
article = Ticket::Article.find_by( message_id: dm.id )
|
article = Ticket::Article.find_by(message_id: dm.id)
|
||||||
|
|
||||||
break if article
|
break if article
|
||||||
|
|
||||||
sleep 5
|
sleep 10
|
||||||
}
|
}
|
||||||
|
|
||||||
assert( article, "inbound article '#{text}' created" )
|
assert(article, "inbound article '#{text}' created")
|
||||||
ticket = article.ticket
|
ticket = article.ticket
|
||||||
assert( ticket, 'ticket of inbound article exists' )
|
assert(ticket, 'ticket of inbound article exists')
|
||||||
assert( ticket.articles, 'ticket.articles exists' )
|
assert(ticket.articles, 'ticket.articles exists')
|
||||||
assert_equal( 1, ticket.articles.count, 'ticket article inbound count' )
|
assert_equal(1, ticket.articles.count, 'ticket article inbound count')
|
||||||
assert_equal( ticket.state.name, 'new' )
|
assert_equal(ticket.state.name, 'new')
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue