Class: TestLinker

Inherits:
Object
  • Object
show all
Extended by:
LogSwitch
Includes:
Helpers, Wrapper
Defined in:
lib/test_linker.rb,
lib/test_linker/error.rb,
lib/test_linker/version.rb,
lib/test_linker/wrapper.rb

Defined Under Namespace

Modules: Helpers, Wrapper Classes: Error

Constant Summary collapse

DEFAULT_TIMEOUT =

Default value for timing out after not receiving an XMLRPC response from the server.

30
DEFAULT_API_PATH =

Path the the XMLRPC interface (via the xmlrpc.php file) on the server.

"/lib/api/xmlrpc.php"
VERSION =

test_linker version

"1.0.1"

Instance Method Summary collapse

Methods included from Helpers

#add_test_case_to_test_plan_by_name, #api_version, #build_id, #create_first_level_suite, #create_suite, #create_test_case_by_name, #find_open_cases_for_plan, #find_projects, #find_test_plans, #first_level_test_suite_id, #project_id, #suite_info, #test_info, #test_not_run?, #test_plan_id

Methods included from Wrapper

#about, #add_test_case_to_test_plan, #assign_requirements, #builds_for_test_plan, #check_dev_key, #create_build, #create_project, #create_test_case, #create_test_plan, #create_test_suite, #delete_execution, #does_user_exist, #first_level_test_suites_for_project, #full_path, #last_execution_result, #latest_build_for_test_plan, #project_by_name, #projects, #repeat, #report_test_case_result, #say_hello, #test_case, #test_case_attachments, #test_case_custom_field_design_value, #test_case_execution_result=, #test_case_id_by_name, #test_cases_for_test_plan, #test_cases_for_test_suite, #test_plan_by_name, #test_plan_platforms, #test_plans, #test_suite_by_id, #test_suites_for_test_plan, #test_suites_for_test_suite, #totals_for_test_plan, #upload_attachment, #upload_execution_attachment, #upload_project_attachment, #upload_requirement_attachment, #upload_requirement_specification_attachment, #upload_test_case_attachment, #upload_test_suite_attachment

Constructor Details

#initialize(server_url, dev_key, options = {}) ⇒ TestLinker

Returns a new instance of TestLinker.

Parameters:

  • server_url (String)

    URL to access TestLink API

  • dev_key (String)

    User key to access TestLink API

  • options (Hash) (defaults to: {})

Options Hash (options):

  • api_path (String)

    Alternate path to the xmlrpc.php file on the server.

  • timeout (Fixnum)

    Seconds to timeout after not receiving a response from the server.

  • version (String)

    Force a different API version.



36
37
38
39
40
41
42
43
# File 'lib/test_linker.rb', line 36

def initialize(server_url, dev_key, options={})
  api_path   = options[:api_path] || DEFAULT_API_PATH
  timeout    = options[:timeout] || DEFAULT_TIMEOUT
  @dev_key   = dev_key
  server_url = server_url + api_path
  @server    = XMLRPC::Client.new_from_uri(server_url, nil, timeout)
  @version   = Versionomy.parse(options[:version] || api_version)
end

Instance Method Details

#ensure_version_is(comparison, version) ⇒ Object (private)

Raises if the version set in @version doesn’t meet the comparison with the passed-in version. Returns nil if @version isn’t set, since there’s nothing to do (and something might have called to set @version).

Parameters:

  • comparison (Symbol)
  • version (String)


114
115
116
117
118
119
120
121
122
123
124
# File 'lib/test_linker.rb', line 114

def ensure_version_is(comparison, version)
  message = "Method not supported in version #{@version}."

  if @version.nil?
    return
  elsif comparison == :less_than && @version >= version
    raise TestLinker::Error, message
  elsif comparison == :greater_than_or_equal_to && @version < version
    raise TestLinker::Error, message
  end
end

#log_xml=(do_logging) ⇒ Object

Parameters:

  • do_logging (Boolean)

    false to turn XMLRPC logging off; true to turn it back on.



53
54
55
56
57
58
59
60
61
62
# File 'lib/test_linker.rb', line 53

def log_xml=(do_logging)
  if do_logging == true
    puts "WARNING: Net::HTTP warns against using this in production, so you probably shouldn't!!"
    @server.set_debug(TestLinker.logger)
  elsif do_logging == false
    @server.set_debug(nil)
  end

  @log_xml = do_logging
end

#log_xml?Boolean

Returns if logging of XMLRPC requests/responses is enabled or not.

Returns:

  • (Boolean)

    Returns if logging of XMLRPC requests/responses is enabled or not.



47
48
49
# File 'lib/test_linker.rb', line 47

def log_xml?
  @log_xml ||= false
end

#make_call(method_name, arguments, method_supported_in_version) ⇒ Object

Makes the call to the server with the given arguments. Note that this also allows for calling XMLRPC methods on the server that haven’t yet been implemented as Ruby methods here.

Examples:

Call a new method

result = make_call("tl.getWidgets", { "testplanid" => 123 }, "1.5")
raise TestLinker::Error, result["message"] if result["code"]
return result

Parameters:

  • method_name (String)

    The XMLRPC method to call.

  • arguments (Hash)

    The arguments to send to the server.

  • method_supported_in_version (String)

    The version of the API the method was added.

Returns:

  • The return type depends on the method call.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/test_linker.rb', line 77

def make_call(method_name, arguments, method_supported_in_version)
  ensure_version_is :greater_than_or_equal_to, method_supported_in_version
  
  arguments.merge!({ :devKey => @dev_key }) unless arguments.has_key? :devKey
  
  TestLinker.log "API Version: #{method_supported_in_version}"
  TestLinker.log "Calling method: '#{method_name}' with args '#{arguments.inspect}'"
  response = @server.call(method_name, arguments)
  
  TestLinker.log "response class: #{response.class}"
  if response.is_a?(Array) && response.first.is_a?(Hash)
    response.each { |r| r.symbolize_keys! }
  elsif response.is_a? Hash
    response.symbolize_keys!
  end

  TestLinker.log "Received response:"
  TestLinker.log response

  if @version.nil?
    return response
  elsif response.is_a?(Array) && response.first[:code]
    raise TestLinker::Error, "#{response.first[:code]}: #{response.first[:message]}"
  end
  
  response
end