Mailinglist Archive: yast-commit (1809 mails)

< Previous Next >
[yast-commit] <web-client> network : Added a first test for the network controller.
  • From: Martin Vidner <mvidner@xxxxxxx>
  • Date: Thu, 3 Sep 2009 16:17:25 +0200
  • Message-id: <E1MjDJa-0001Lm-Qj@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit a4b8781064323cbefe8f7ac2e0805a7f8815e1b4
Author: Martin Vidner <mvidner@xxxxxxx>
Date: Thu Sep 3 16:17:25 2009 +0200

Added a first test for the network controller.
---
.../test/functional/network_controller_test.rb | 54 ++++++++++++++++++++
plugins/network/test/test_helper.rb | 17 ++++++-
2 files changed, 70 insertions(+), 1 deletions(-)

diff --git a/plugins/network/test/functional/network_controller_test.rb
b/plugins/network/test/functional/network_controller_test.rb
new file mode 100644
index 0000000..2e5384c
--- /dev/null
+++ b/plugins/network/test/functional/network_controller_test.rb
@@ -0,0 +1,54 @@
+require 'test_helper'
+require 'ostruct'
+
+class NetworkControllerTest < ActionController::TestCase
+
+ class Proxy
+ attr_accessor :result, :timeout
+ def permissions
+ return { :read => true, :execute => true }
+ end
+ end
+
+ class Proxy1 < Proxy
+ def find
+ return result
+ end
+ end
+
+ class ProxyN < Proxy
+ def find(arg)
+ return result
+ end
+ end
+
+ def setup
+ # bypass authentication
+ NetworkController.any_instance.stubs(:login_required)
+
+ # stub what the REST is supposed to return
+ @hn_proxy = Proxy1.new
+ @hn_proxy.result = OpenStruct.new("name" => "Arthur, king of the Britons")
+
+ @dns_proxy = Proxy1.new
+ @dns_proxy.result = OpenStruct.new("nameservers" => ["n1", "n2"])
+
+ @rt_proxy = ProxyN.new
+ @rt_proxy.result = OpenStruct.new("via" => 'mygw')
+
+ def x # a shorthand. return another stub
+ YaST::ServiceResource.stubs(:proxy_for)
+ end
+
x.with('org.opensuse.yast.modules.yapi.network.hostname').returns(@hn_proxy)
+ x.with('org.opensuse.yast.modules.yapi.network.dns').returns(@dns_proxy)
+ x.with('org.opensuse.yast.modules.yapi.network.routes').returns(@rt_proxy)
+ end
+
+ def test_should_show_it
+ get :index
+ assert_response :success
+ # test just the last assignment, for brevity
+ assert_not_nil assigns(:default_route)
+ end
+
+end
diff --git a/plugins/network/test/test_helper.rb
b/plugins/network/test/test_helper.rb
index cf148b8..a9445b7 100644
--- a/plugins/network/test/test_helper.rb
+++ b/plugins/network/test/test_helper.rb
@@ -1,3 +1,18 @@
+rails_parent = ENV["RAILS_PARENT"]
+unless rails_parent
+ default_parent = "../../webclient"
+ if File.directory?(default_parent)
+ $stderr.puts "Taking #{default_parent} for RAILS_PARENT"
+ rails_parent = default_parent
+ else
+ $stderr.puts "Please set RAILS_PARENT environment"
+ exit
+ end
+end
+
+ENV["RAILS_ENV"] = "test"
+require File.expand_path(rails_parent + "/config/environment")
+
require 'rubygems'
require 'active_support'
-require 'active_support/test_case'
\ No newline at end of file
+require 'active_support/test_case'
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages