Merge lp:~elopio/ubuntuone-testing/testability into lp:ubuntuone-testing

Proposed by Leo Arias
Status: Merged
Approved by: Rick McBride
Approved revision: 91
Merged at revision: 89
Proposed branch: lp:~elopio/ubuntuone-testing/testability
Merge into: lp:ubuntuone-testing
Diff against target: 425 lines (+397/-0)
4 files modified
ubuntuone/client/qt/tests/testabilitydriver/controlpanel/header-tests.rb (+64/-0)
ubuntuone/client/qt/tests/testabilitydriver/misc/lib/testhelper.rb (+191/-0)
ubuntuone/client/qt/tests/testabilitydriver/run-tests.rb (+64/-0)
ubuntuone/client/qt/tests/testabilitydriver/shared/actions/controlpanel.rb (+78/-0)
To merge this branch: bzr merge lp:~elopio/ubuntuone-testing/testability
Reviewer Review Type Date Requested Status
Rick McBride (community) Approve
Review via email: mp+102397@code.launchpad.net

Commit message

Added the first Qt testability tests for the control panel: connect and disconnect.

Description of the change

First testability branch.
Includes the disconnect and connect tests.

To post a comment you must log in.
Revision history for this message
Rick McBride (rmcbride) wrote :

Woohoo! Ruby

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'ubuntuone/client'
2=== added directory 'ubuntuone/client/qt'
3=== added directory 'ubuntuone/client/qt/tests'
4=== added directory 'ubuntuone/client/qt/tests/testabilitydriver'
5=== added directory 'ubuntuone/client/qt/tests/testabilitydriver/controlpanel'
6=== added file 'ubuntuone/client/qt/tests/testabilitydriver/controlpanel/header-tests.rb'
7--- ubuntuone/client/qt/tests/testabilitydriver/controlpanel/header-tests.rb 1970-01-01 00:00:00 +0000
8+++ ubuntuone/client/qt/tests/testabilitydriver/controlpanel/header-tests.rb 2012-04-17 21:50:23 +0000
9@@ -0,0 +1,64 @@
10+#!/usr/bin/env ruby1.8
11+=begin
12+/*
13+ * Copyright 2012 Canonical Ltd.
14+ *
15+ * This program is free software; you can redistribute it and/or modify
16+ * it under the terms of the GNU General Public License as published by
17+ * the Free Software Foundation; version 3.
18+ *
19+ * This program is distributed in the hope that it will be useful,
20+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
21+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+ * GNU General Public License for more details.
23+ *
24+ * You should have received a copy of the GNU General Public License
25+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
26+ */
27+=end
28+
29+require '../run-tests.rb' unless $INIT_COMPLETED
30+require $actions_path + '/controlpanel.rb'
31+
32+############################# Test Suite #############################
33+context "Header tests" do
34+
35+ # Run once at the beginning of this test suite
36+ startup do
37+ $SUT.execute_shell_command 'killall ubuntuone-control-panel-qt'
38+ end
39+
40+ # Run once at the end of this test suite
41+ teardown do
42+ $SUT.execute_shell_command 'killall ubuntuone-control-panel-qt'
43+ end
44+
45+ # Run before each test case begins
46+ setup do
47+ # Execute the application
48+ @controlpanel = $SUT.run(:name=>'python',
49+ :start_command=>'ubuntuone-control-panel-qt ' +
50+ '-testability')
51+ end
52+
53+ # Run after each test case completes
54+ teardown do
55+ $SUT.execute_shell_command 'pkill -nf ubuntuone-control-panel-qt'
56+ end
57+
58+ # Test cases
59+
60+ test "Disconnect from service" do
61+ connect_and_wait_for_file_sync_update
62+ disconnect
63+ verify_true(3, 'test disconnected') {
64+ is_disconnected?
65+ }
66+ end
67+
68+ test "Connect to service" do
69+ disconnect
70+ connect_and_wait_for_file_sync_update
71+ end
72+
73+end
74
75=== added directory 'ubuntuone/client/qt/tests/testabilitydriver/misc'
76=== added directory 'ubuntuone/client/qt/tests/testabilitydriver/misc/lib'
77=== added file 'ubuntuone/client/qt/tests/testabilitydriver/misc/lib/testhelper.rb'
78--- ubuntuone/client/qt/tests/testabilitydriver/misc/lib/testhelper.rb 1970-01-01 00:00:00 +0000
79+++ ubuntuone/client/qt/tests/testabilitydriver/misc/lib/testhelper.rb 2012-04-17 21:50:23 +0000
80@@ -0,0 +1,191 @@
81+require 'test/unit'
82+
83+dir = File.dirname(File.expand_path(__FILE__))
84+$LOAD_PATH.unshift File.expand_path(dir + '/../lib')
85+$TEST_DIR = File.dirname(File.expand_path(__FILE__))
86+
87+# Enable a startup and shutdown method for each test case
88+# From https://github.com/freerange/test_startup
89+module TestStartupAndShutdown
90+ def startup(&block)
91+ install_global_startup
92+ @__startup_blocks ||= []
93+ @__startup_blocks << block if block_given?
94+ @__startup_blocks
95+ end
96+
97+ def shutdown(&block)
98+ install_global_startup
99+ @__shutdown_blocks ||= []
100+ @__shutdown_blocks << block if block_given?
101+ @__shutdown_blocks
102+ end
103+
104+ attr_reader :__startup_blocks, :__shutdown_blocks
105+
106+ def install_global_startup
107+ extend(TestSuiteWithGlobalStartup)
108+ end
109+
110+ module TestSuiteWithGlobalStartup
111+ def suite(*args)
112+ mysuite = super
113+ these_startup_blocks = __startup_blocks
114+ these_shutdown_blocks = __shutdown_blocks
115+ mysuite.instance_eval { @__startup_blocks = these_startup_blocks }
116+ mysuite.instance_eval { @__shutdown_blocks = these_shutdown_blocks }
117+ def mysuite.run(*args)
118+ (@__startup_blocks || []).each { |block| block.call }
119+ super
120+ (@__shutdown_blocks || []).each { |block| block.call }
121+ end
122+ mysuite
123+ end
124+ end
125+end
126+
127+Test::Unit::TestCase.extend(TestStartupAndShutdown)
128+
129+##
130+# Test::Unit runs test in alphabetical order. This class instead runs them
131+# sequentially. Can specify ordering with the line
132+# execute :sequentially:
133+# Taken from http://wiki.openqa.org/download/attachments/804/testcase.rb
134+# Copyright: Bret Pettichord
135+
136+class TestCase < Test::Unit::TestCase
137+ @@order = :sequentially
138+ def initialize name
139+ throw :invalid_test if name == :default_test && self.class == TestCase
140+ super
141+ end
142+ class << self
143+ attr_accessor :test_methods, :order
144+ def test_methods
145+ @test_methods ||= []
146+ end
147+ def order
148+ @order || @@order
149+ end
150+ def default_order= order
151+ @@order = order
152+ end
153+ def sorted_test_methods
154+ case order
155+ when :alphabetically: test_methods.sort
156+ when :sequentially: test_methods
157+ when :reversed_sequentially: test_methods.reverse
158+ when :reversed_alphabetically: test_methods.sort.reverse
159+ else raise ArgumentError, "Execute option not supported: #{@order}"
160+ end
161+ end
162+ def suite
163+ suite = Test::Unit::TestSuite.new(name)
164+ sorted_test_methods.each do |test|
165+ catch :invalid_test do
166+ suite << new(test)
167+ end
168+ end
169+ if (suite.empty?)
170+ catch :invalid_test do
171+ suite << new(:default_test)
172+ end
173+ end
174+ return suite
175+ end
176+ def method_added id
177+ name = id.id2name
178+ test_methods << name if name =~ /^test./
179+ end
180+ def execute order
181+ @order = order
182+ end
183+ end
184+
185+ # Runs the individual test method represented by this
186+ # instance of the fixture, collecting statistics, failures
187+ # and errors in result. Also catches MobyBase::VerificationError
188+ # and considers them fails, not errors.
189+ def run(result)
190+ yield(STARTED, name)
191+ @_result = result
192+ begin
193+ setup
194+ __send__(@method_name)
195+ rescue Test::Unit::AssertionFailedError, MobyBase::VerificationError => e
196+ add_failure(e.message, e.backtrace)
197+ rescue Exception
198+ raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
199+ add_error($!)
200+ ensure
201+ begin
202+ teardown
203+ rescue Test::Unit::AssertionFailedError, MobyBase::VerificationError => e
204+ add_failure(e.message, e.backtrace)
205+ rescue Exception
206+ raise if PASSTHROUGH_EXCEPTIONS.include? $!.class
207+ add_error($!)
208+ end
209+ end
210+ result.add_run
211+ yield(FINISHED, name)
212+ end
213+end
214+
215+
216+##
217+# Snippit from test/spec/mini 5
218+# Allows syntatic sugar for tests in the following form:
219+#
220+#context "It's test/spec/mini!" do
221+# setup do
222+# @name = "Chris"
223+# end
224+#
225+# teardown do
226+# @name = nil
227+# end
228+#
229+# test "with Test::Unit" do
230+# assert (self.class < Test::Unit::TestCase)
231+# end
232+#
233+# test "body-less test cases"
234+#
235+# test :symbol_test_names do
236+# assert true
237+# end
238+#
239+# xtest "disabled tests" do
240+# assert disabled!
241+# end
242+#
243+# context "and of course" do
244+# test "nested contexts!" do
245+# assert_equal "Chris", @name
246+# end
247+# end
248+#end
249+#
250+# http://gist.github.com/307649 (chris@ozmm.org)
251+#
252+
253+def context(*args, &block)
254+ return super unless (name = args.first) && block
255+
256+ klass = Class.new(TestCase) do
257+ def self.test(name, &block)
258+ define_method("test_#{name.to_s.gsub(/\W/,'_')}", &block) if block
259+ end
260+ def self.xtest(*args) end
261+ def self.context(*args, &block) instance_eval(&block) end
262+ def self.setup(&block)
263+ define_method(:setup) { self.class.setups.each { |s| instance_eval(&s) } }
264+ setups << block
265+ end
266+ def self.setups; @setups ||= [] end
267+ def self.teardown(&block) define_method(:teardown, &block) end
268+ end
269+ (class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
270+ klass.class_eval &block
271+end
272
273=== added file 'ubuntuone/client/qt/tests/testabilitydriver/run-tests.rb'
274--- ubuntuone/client/qt/tests/testabilitydriver/run-tests.rb 1970-01-01 00:00:00 +0000
275+++ ubuntuone/client/qt/tests/testabilitydriver/run-tests.rb 2012-04-17 21:50:23 +0000
276@@ -0,0 +1,64 @@
277+#!/usr/bin/env ruby1.8
278+=begin
279+/*
280+ * Copyright 2011, 2012 Canonical Ltd.
281+ *
282+ * Original author:
283+ * - Gerry Boland <gerry.boland@canonical.com>
284+ *
285+ * This program is free software; you can redistribute it and/or modify
286+ * it under the terms of the GNU General Public License as published by
287+ * the Free Software Foundation; version 3.
288+ *
289+ * This program is distributed in the hope that it will be useful,
290+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
291+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
292+ * GNU General Public License for more details.
293+ *
294+ * You should have received a copy of the GNU General Public License
295+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
296+ */
297+=end
298+
299+# Testability test suite execution script
300+#
301+# Run all tests with
302+# $ ruby run-tests.rb
303+
304+# Check script being run by Ruby 1.8.x, later versions not supported by TDriver
305+abort("Aborted! Ruby 1.9 not supported, use 1.8") unless RUBY_VERSION < '1.9'
306+
307+# Time verify_* assertions should wait until they throw exception
308+TIMEOUT = 10
309+
310+# Add ./misc/lib to the list of library locations - need to calculate absolute path
311+require 'pathname'
312+$library_path = File.expand_path(File.dirname(__FILE__)) + '/misc/lib'
313+$actions_path = File.expand_path(File.dirname(__FILE__)) + '/shared/actions'
314+$LOAD_PATH.unshift $library_path
315+
316+# The following line includes the complete tdriver environment
317+require 'tdriver'
318+include TDriverVerify
319+
320+# Require unit test framework: This enables execution of test cases and also includes assertions (Test::Unit::Assertions)
321+require 'testhelper'
322+
323+# Establish connection to qttasserver
324+$SUT = TDriver.sut(:Id => "sut_qt")
325+
326+# Enable reports only with -report switch
327+include TDriverReportTestUnit if ARGV.delete('-report')
328+
329+# List of directories in which to search for test cases
330+test_directories = ['controlpanel']
331+
332+# Only run scan for tests if this script is directly called
333+if __FILE__ == $0
334+ $INIT_COMPLETED = true # Prevent this file being included by test cases
335+
336+ # Scan through the above directories and execute test cases contained.
337+ test_directories.each do | directory |
338+ Dir["#{directory}/*.rb"].each { |testCase| require testCase }
339+ end
340+end
341
342=== added directory 'ubuntuone/client/qt/tests/testabilitydriver/shared'
343=== added directory 'ubuntuone/client/qt/tests/testabilitydriver/shared/actions'
344=== added file 'ubuntuone/client/qt/tests/testabilitydriver/shared/actions/controlpanel.rb'
345--- ubuntuone/client/qt/tests/testabilitydriver/shared/actions/controlpanel.rb 1970-01-01 00:00:00 +0000
346+++ ubuntuone/client/qt/tests/testabilitydriver/shared/actions/controlpanel.rb 2012-04-17 21:50:23 +0000
347@@ -0,0 +1,78 @@
348+#!/usr/bin/env ruby1.8
349+=begin
350+/*
351+ * Copyright 2012 Canonical Ltd.
352+ *
353+ * This program is free software; you can redistribute it and/or modify
354+ * it under the terms of the GNU General Public License as published by
355+ * the Free Software Foundation; version 3.
356+ *
357+ * This program is distributed in the hope that it will be useful,
358+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
359+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
360+ * GNU General Public License for more details.
361+ *
362+ * You should have received a copy of the GNU General Public License
363+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
364+ */
365+=end
366+
367+def disconnect
368+ if is_connected?
369+ click_sync_status_button
370+ end
371+end
372+
373+def is_connected?
374+ return get_sync_status_button_text == 'Disconnect'
375+end
376+
377+private
378+def get_sync_status_button_text
379+ return get_sync_status_button.attribute('text')
380+end
381+
382+private
383+def get_sync_status_button
384+ return @controlpanel.QPushButton(:name=>'sync_status_button')
385+end
386+
387+private
388+def click_sync_status_button
389+ get_sync_status_button.tap
390+end
391+
392+def is_disconnected?
393+ return get_sync_status_button_text == 'Connect' &&
394+ get_sync_status_label_text == 'File Sync is disconnected.'
395+end
396+
397+private
398+def get_sync_status_label_text
399+ return get_sync_status_label.attribute('text')
400+end
401+
402+private
403+def get_sync_status_label
404+ return @controlpanel.QLabel(:name=>'sync_status_label')
405+end
406+
407+def connect_and_wait_for_file_sync_update
408+ if is_disconnected?
409+ click_sync_status_button
410+ end
411+ wait_for_file_sync_update
412+end
413+
414+private
415+def wait_for_file_sync_update
416+ # TODO define a timeout.
417+ verify_true(360, 'test connected') {
418+ is_connected? && is_file_sync_up_to_date?
419+ }
420+end
421+
422+private
423+def is_file_sync_up_to_date?
424+ return get_sync_status_label_text == 'File Sync is up-to-date.'
425+end

Subscribers

People subscribed via source and target branches