Skip to content

Commit

Permalink
[ci] trigger sending the mails in testsuite whenever we expect delive…
Browse files Browse the repository at this point in the history
…ries

This is otherwise not happening as we rely on clockwork
  • Loading branch information
coolo committed Oct 31, 2015
1 parent fa1d1db commit 6181e3b
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/api/app/models/event/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Event::Build < Event::Package

def my_message_id
# we put the verifymd5 sum in the message id, so new checkins get new thread, but it doesn't have to be very correct
md5 = payload['verifymd5'][0..6]
md5 = payload.fetch('verifymd5', 'NOVERIFY')[0..6]
mid = Digest::MD5.hexdigest("#{payload['project']}-#{payload['package']}-#{payload['repository']}-#{md5}")
"<build-#{mid}@#{self.class.message_domain}>"
end
Expand Down
4 changes: 2 additions & 2 deletions src/api/test/fixtures/event_mailer/project_comment
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Return-Path: <obs-email@opensuse.org>
From: Thor <tschmidt@example.com>
Sender: OBS Notification <obs-email@opensuse.org>
To: user is maintainer in hidden project <homer@nospam.net>,
Iggy Pop <Iggy@pop.org>
To: Iggy Pop <Iggy@pop.org>,
user is maintainer in hidden project <homer@nospam.net>
Message-ID: <notrandom@localhost>
Subject: New comment in project home:Iggy by tom
Mime-Version: 1.0
Expand Down
14 changes: 13 additions & 1 deletion src/api/test/functional/comments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ def test_create_request_comment
# body can't be empty
assert_xml_tag tag: 'status', attributes: { code: 'invalid_record' }

SendEventEmails.new.perform
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post create_request_comment_path(id: 2), 'Hallo'
assert_response :success
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand All @@ -104,9 +106,11 @@ def test_create_request_comment

# just check if adrian gets the mail too - he's a commenter now
login_dmayr
SendEventEmails.new.perform
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post create_request_comment_path(id: 2), 'Hallo'
assert_response :success
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand All @@ -116,6 +120,7 @@ def test_create_request_comment
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post create_request_comment_path(id: 2), 'Hallo @fred'
assert_response :success
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand All @@ -125,6 +130,7 @@ def test_create_request_comment
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post create_request_comment_path(id: 2), 'Is Fred listening now?'
assert_response :success
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand All @@ -141,9 +147,11 @@ def test_create_project_comment
# body can't be empty
assert_xml_tag tag: 'status', attributes: { code: 'invalid_record' }

SendEventEmails.new.perform
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post create_project_comment_path(project: 'Apache'), 'Beautiful project'
assert_response :success
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand All @@ -165,25 +173,29 @@ def test_create_package_comment
# body can't be empty
assert_xml_tag tag: 'status', attributes: { code: 'invalid_record' }

SendEventEmails.new.perform
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post create_package_comment_path(project: 'kde4', package: 'kdebase'), "Hola, estoy aprendiendo español"
assert_response :success
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
assert_equal 'New comment in package kde4/kdebase by tom', email.subject
assert_equal ["fred@feuerstein.de", "king@all-the-kings.org", "fred@feuerstein.de", "test_group@testsuite.org"], email.to
assert_equal ["fred@feuerstein.de", "king@all-the-kings.org", "fred@feuerstein.de", "test_group@testsuite.org"].sort, email.to.sort

get comments_package_path(project: 'kde4', package: 'kdebase')
assert_xml_tag tag: 'comment', attributes: { who: 'tom' }, content: "Hola, estoy aprendiendo español"
end

def test_create_a_comment_that_only_mentioned_people_will_notice
login_tom
SendEventEmails.new.perform
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
# Trolling
raw_post create_package_comment_path(project: 'BaseDistro', package: 'pack1'), "I preffer Apache1, don't you? @fred"
assert_response :success
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand Down
3 changes: 3 additions & 0 deletions src/api/test/functional/maintenance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1320,12 +1320,14 @@ def test_create_maintenance_project_and_release_packages
assert_response :success
assert_xml_tag( :parent => { tag: 'state' }, :tag => 'comment', :content => 'blahfasel')

SendEventEmails.new.perform
ActionMailer::Base.deliveries.clear

# leave a comment
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post create_request_comment_path(id: reqid), 'Release it now!'
assert_response :success
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand All @@ -1338,6 +1340,7 @@ def test_create_maintenance_project_and_release_packages
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post create_request_comment_path(id: reqid), 'Slave, can you release it? The master is gone'
assert_response :success
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand Down
11 changes: 11 additions & 0 deletions src/api/test/functional/request_events_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def test_request_event

Timecop.travel(2013, 8, 20, 12, 0, 0)
myid = 0
SendEventEmails.new.perform
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post '/request?cmd=create',
"<request><action type='add_role'><target project='home:tom'/><person name='Iggy' role='reviewer'/></action></request>"
assert_response :success
myid = Xmlhash.parse(@response.body)['id']
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand All @@ -43,6 +45,7 @@ def test_very_large_request_event

Timecop.travel(2013, 8, 20, 12, 0, 0)
myid = 0
SendEventEmails.new.perform
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
body = "<request>\n"
actions=1000
Expand All @@ -55,6 +58,7 @@ def test_very_large_request_event
req = Xmlhash.parse(@response.body)
assert_equal actions, req['action'].count
myid = req['id']
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand All @@ -68,10 +72,12 @@ def test_set_bugowner_event

Timecop.travel(2013, 8, 20, 12, 0, 0)
myid = 0
SendEventEmails.new.perform
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post '/request?cmd=create', "<request><action type='set_bugowner'><target project='home:tom'/><person name='Iggy'/></action></request>"
assert_response :success
myid = Xmlhash.parse(@response.body)['id']
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand All @@ -88,6 +94,7 @@ def test_set_bugowner_event
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post "/request/#{myid}?cmd=changestate&newstate=declined", ''
assert_response :success
SendEventEmails.new.perform
end
email = nil
ActionMailer::Base.deliveries.each do |m|
Expand All @@ -107,11 +114,13 @@ def test_devel_package_event

Timecop.travel(2013, 8, 20, 12, 0, 0)
myid = ''
SendEventEmails.new.perform
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post '/request?cmd=create',
"<request><action type='add_role'><target project='kde4' package='kdelibs'/><person name='Iggy' role='reviewer'/></action></request>"
assert_response :success
myid = Xmlhash.parse(@response.body)['id']
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand All @@ -124,10 +133,12 @@ def test_repository_delete_request

Timecop.travel(2013, 8, 20, 12, 0, 0)
myid = ''
SendEventEmails.new.perform
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
raw_post '/request?cmd=create', "<request><action type='delete'><target project='home:coolo' repository='standard'/></action></request>"
assert_response :success
myid = Xmlhash.parse(@response.body)['id']
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand Down
2 changes: 2 additions & 0 deletions src/api/test/functional/webui/project_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,12 @@ def verify_email(fixture_name, email)

def test_successful_comment_creation
login_tom to: '/project/show/home:Iggy'
SendEventEmails.new.perform
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
fill_in 'body', with: 'Comment Body'
find_button('Add comment').click
find('#flash-messages').must_have_text 'Comment was successfully created.'
SendEventEmails.new.perform
end
email = ActionMailer::Base.deliveries.last
verify_email('project_comment', email)
Expand Down
3 changes: 3 additions & 0 deletions src/api/test/functional/webui/request_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,12 @@ def test_comment_event

# adrian is reviewer, Iggy creator, Admin (fixture) commenter
# tom is commenter *and* author, so doesn't get mail
SendEventEmails.new.perform
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
fill_in 'body', with: 'Comment Body'
find_button('Add comment').click
page.must_have_text 'Comment Body'
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand All @@ -347,6 +349,7 @@ def test_comment_event
fill_in 'body', with: 'Another Body'
find_button('Add comment').click
page.must_have_text 'Another Body'
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand Down
5 changes: 5 additions & 0 deletions src/api/test/models/event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ def groups_for_event(e)
User.current = users(:Iggy)
req = bs_requests(:submit_from_home_project)
myid = req.id
SendEventEmails.new.perform # empty queue
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
req.addreview by_user: 'tom', comment: 'Can you check that?'
SendEventEmails.new.perform
end
email = ActionMailer::Base.deliveries.last

Expand Down Expand Up @@ -142,8 +144,10 @@ def groups_for_event(e)
User.current = users(:Iggy)
req = bs_requests(:submit_from_home_project)
myid = req.id
SendEventEmails.new.perform # empty queue
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
req.addreview by_project: 'home:Iggy', by_package: 'TestPack', comment: 'Can you check that?'
SendEventEmails.new.perform
end
email = ActionMailer::Base.deliveries.last

Expand All @@ -155,6 +159,7 @@ def groups_for_event(e)
ActionMailer::Base.deliveries.clear
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
req.addreview by_project: 'Apache', by_package: 'apache2', comment: 'Can you check that?'
SendEventEmails.new.perform
end
email = ActionMailer::Base.deliveries.last

Expand Down
3 changes: 3 additions & 0 deletions src/api/test/unit/event_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ def verify_email(fixture_name, email)
req = bs_requests(:submit_from_home_project)
Timecop.travel(2013, 8, 20, 12, 0, 0)
myid = req.id
SendEventEmails.new.perform # empty queue
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
req.addreview(by_group: 'test_group', comment: 'does it look ok?')
# trigger the send job
SendEventEmails.new.perform
end

email = ActionMailer::Base.deliveries.last
Expand Down

0 comments on commit 6181e3b

Please sign in to comment.