Class: MyTest

Inherits:
WiseTest
  • Object
show all
Includes:
AssertHelper, DATA, HtmlHelper, HttpHelper, RobotHelper
Defined in:
lib/action/system/user_action.rb,
lib/common/pairwise.rb,
lib/common/data_house.rb,
lib/common/socket/data.rb,
lib/common/robot_helper.rb,
lib/common/http/html_helper.rb,
lib/common/http/http_helper.rb,
lib/common/http/assert_helper.rb,
lib/action/module/httpserver_action.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from HtmlHelper

#find_attr, #find_children, #find_exist?, #find_grep, #find_has?, #find_html, #find_raw_attr, #find_scan, #find_size, #find_text

Methods included from AssertHelper

#assert_attr, #assert_children, #assert_code, #assert_exist, #assert_grep, #assert_has, #assert_has_not, #assert_html, #assert_no_attr, #assert_no_exist, #assert_no_grep, #assert_no_html, #assert_no_text, #assert_ok, #assert_redirected_to, #assert_size, #assert_text

Methods included from RobotHelper

#robot

Methods included from HttpHelper

#clear_cookie, #delete, #do_encode, #dont_encode, #download, #get, #post, #print_body, #print_head, #put

Methods included from DATA

#_init_file_, #file_exist?, #file_match?, #file_match_times, #file_size?, #get_all_pack, #get_mcpack_value, #include_file_str, #same_content_value, #same_file_contents, #same_file_md5, #same_file_str

Constructor Details

#initializeMyTest

Returns a new instance of MyTest.



328
329
330
# File 'lib/common/http/assert_helper.rb', line 328

def initialize
    @cookies = {}
end

Instance Method Details

#hpricot_search(xpath, &blk) ⇒ Object

高级接口,将 Hpricot 暴露出来



340
341
342
343
# File 'lib/common/http/html_helper.rb', line 340

def hpricot_search(xpath, &blk)
    @hpricot ||= Hpricot("<tr><td>111</td><td id='q'>222</td><br/><td>333</td></tr>")
    @hpricot.search(xpath, &blk)
end

#no_test_get_mcpack_valueObject



367
368
369
370
371
372
373
374
375
376
377
# File 'lib/common/socket/data.rb', line 367

def no_test_get_mcpack_value
	puts get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'pow'
	puts get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'limitid'
	puts get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'title'
	puts get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'link'
	puts get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'pow', 2
	value = get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'pow', 1
	puts value
	puts get_mcpack_value "#{TEST_ROOT}data/mcpack.data", 'pow', 3
			
end

#no_test_same_file_contentsObject



378
379
380
381
# File 'lib/common/socket/data.rb', line 378

def no_test_same_file_contents
	puts "111"
	puts same_file_contents '/home/space/tools/app-test/search/space/module-test/case/implementor/case3/data/1.expc', '/home/space/tools/app-test/search/space/module-test/case/implementor/case3/tmp/1.recv'
end

#no_test_same_file_md5Object



382
383
384
385
# File 'lib/common/socket/data.rb', line 382

def no_test_same_file_md5
	puts "test_same_file_md5"
	puts (same_file_md5 '/home/space/tools/app-test/search/space/module-test/case/implementor/case3/data/1.expc', '/home/space/tools/app-test/search/space/module-test/case/implementor/case3/tmp/1.recv')
end

#qtest_loginObject



170
171
172
# File 'lib/action/system/user_action.rb', line 170

def 
     User.new "ruguo2","aaaa"
end

#qtest_registObject



174
175
176
# File 'lib/action/system/user_action.rb', line 174

def qtest_regist
    regist User.new "sp_tt_hy_0"
end

#testObject



395
396
397
398
# File 'lib/common/data_house.rb', line 395

def test(str)
	puts str
	puts str.encoding
end

#test1Object



108
109
110
111
112
113
114
115
116
117
# File 'lib/common/pairwise.rb', line 108

def test1
	ENV['PATH'] = ENV['PATH'] + ":#{ENV['HOME']}/app-test/search/space/super-test/tool"
	type_arr = %w{Primary Logical Single Span Stripe Mirror}
	size_arr = %w{10 100 500 5000 10000 40000}
	system_arr = %w{FAT FAT32 NTFS}
	compression_arr = %w{on off}
	pair = Pairwise.jenny(type_arr,size_arr,system_arr,compression_arr)
	puts pair.size
	p pair
end

#test2Object



101
102
103
104
105
106
# File 'lib/common/pairwise.rb', line 101

def test2
	ENV['PATH'] = ENV['PATH'] + ":#{ENV['HOME']}/app-test/search/space/super-test/tool"
	re = (Pairwise.jenny NAMES, PASSS, [1,2,3,4,5],[Object.new,Object.new])
	p re
	p re.size
end

#test_1Object



64
65
66
67
68
69
70
71
72
# File 'lib/common/robot_helper.rb', line 64

def test_1
    @cookies = {}
    puts Time.now
    robot(1000) do 
        get "http://sz-testing-space02.sz01.baidu.com:8081/st/loginok.html"
        assert_ok
    end
    puts Time.now
end

#test_2Object



73
74
75
76
77
78
79
80
# File 'lib/common/robot_helper.rb', line 73

def test_2
    @cookies = {}
    puts Time.now
    1000.times do 
        get "http://sz-testing-space02.sz01.baidu.com:8081/st/loginok.html"
    end
    puts Time.now
end

#test_httpserver_getObject



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/action/module/httpserver_action.rb', line 243

def test_httpserver_get
	server=HttpServer.new(8787)
	server.start do |request, response|
		#process request
		puts "[SERVER][get] request from client:"	
		p request.header
		p request.body

		#customize your own response
		puts "[SERVER][get] response to client:"
		#response.status=403
		response.header["Content-Type"]= "application/xhtml+xml;charset=gbk"
		response.body="hello world!<-------path:/-------->哈喽我热烈的" if request.path=='/'
		response.body="hello world!<-------path:/test/-------->哈喽我热烈的" if request.path.include? '/test/'
		p response
	end

	get "http://127.0.0.1:8787/"
	puts "[CLIENT] [1st] received from server:"
	p @response.body
	p @response.header.to_hash

	get "http://127.0.0.1:8787/test/b/"
	puts "[CLIENT] [2nd] received from server:"
	p @response.body
	p @response.header.to_hash

	server.stop
	#HttpServer.stop(8787)	
end

#test_httpserver_postObject

HttpServer.stop(8787)



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/action/module/httpserver_action.rb', line 273

def test_httpserver_post
	server=HttpServer.new(8787)
	server.start do |request, response|
		puts "[SERVER][post] request from client:"
		p request.header
		p request.content

		puts "[SERVER][post] response to client:"
		response.header["Content-Type"]= "application/xhtml+xml;charset=utf-8"
		response.body="hello world!<-------path:/-------->哈喽我热烈的" if request.path=='/'
		p response
	end

	`echo "this is a file" >/tmp/test`
	post "http://127.0.0.1:8787/", {}, {}, {"testfile"=>"/tmp/test"}
	puts "[CLIENT][post] received from server:"
	p @response.body
	p @response.header.to_hash

	server.stop
end

#test_same_file_strObject



386
387
388
389
# File 'lib/common/socket/data.rb', line 386

def test_same_file_str
	puts "test_same_file_str"
	puts (same_file_str '/home/space/tools/app-test/search/space/module-test/case/implementor/case13/data/5.expc', '/home/space/tools/app-test/search/space/module-test/case/implementor/case13/tmp/5.recv')
end