Fixed twitter tests.

This commit is contained in:
Martin Edenhofer 2015-12-11 11:55:22 +01:00
parent be6c374cdc
commit d882c77546
2 changed files with 93 additions and 66 deletions

View file

@ -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:

View file

@ -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)
@ -102,7 +120,7 @@ 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
} }
@ -127,7 +145,7 @@ class TwitterTest < ActiveSupport::TestCase
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,14 +160,11 @@ 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
@ -157,7 +172,7 @@ class TwitterTest < ActiveSupport::TestCase
break if article break if article
sleep 5 sleep 10
} }
assert(article) assert(article)
ticket = article.ticket ticket = article.ticket
@ -174,18 +189,17 @@ class TwitterTest < ActiveSupport::TestCase
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|
@ -219,7 +233,7 @@ class TwitterTest < ActiveSupport::TestCase
# 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
@ -227,7 +241,7 @@ 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")
@ -263,7 +277,7 @@ class TwitterTest < ActiveSupport::TestCase
# 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,7 +285,7 @@ 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")
@ -294,7 +308,7 @@ class TwitterTest < ActiveSupport::TestCase
# 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
@ -302,7 +316,7 @@ 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")
@ -312,4 +326,5 @@ class TwitterTest < ActiveSupport::TestCase
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