class ZephyrClient::Client

Constants

EXECUTION_CMD

TODO: Leverage command pattern.

ZAPI_LIST

Attributes

debug[RW]
user[RW]

Public Class Methods

new(*p) click to toggle source
# File lib/zephyr_client/base/client.rb, line 20
def initialize(*p)

  @user=nil
  puts __FILE__ + (__LINE__).to_s + " size : #{p.size}" if @debug

  if p.size==1 && p[0].is_a?(Hash)
    ;
  elsif p.size==1 && p[0].is_a?(String)
    # Load form from a JSON file
    @options = JSON.parse(File.read(p[0].to_s))
    pp @options if @debug
  elsif p.size==2
    @user=p[0]
    server=p[1]
    puts __FILE__ + (__LINE__).to_s + " ZephyrClient::Client.new(#{user}, #{server})" if @debug
    @options = {
      'site' => server,
      'context_path' => "/jira",
      'rest_base_path' => "/jira/rest/api/2",
      'ssl_verify_mode' => 1,
      'use_ssl' => true,
      'auth_type' => :basic,
      'http_debug' => true,
      'read_timeout' => 100
    }
  end

end

Public Instance Methods

connect(uri=@options['site']) click to toggle source
# File lib/zephyr_client/base/client.rb, line 53
def connect(uri=@options['site'])
  if @debug
    puts __FILE__ + (__LINE__).to_s + " [enter]:http_con(#{uri})"
    puts __FILE__ + (__LINE__).to_s + " | options"
    pp @options
  end

  ZephyrClient::Utils::connect(@options['site'], @options)
end
getCycles(id) click to toggle source
# File lib/zephyr_client/base/client.rb, line 74
def getCycles(id)
  response = sendRequest("#{ZAPI_LIST[:cycle]}/#{id}")
  puts __FILE__ + (__LINE__).to_s + " ==== Cycles #{id}  ====\n" if @debug
  response.body
end
getCyclesByProjectId(projectId, versionId) click to toggle source
# File lib/zephyr_client/base/client.rb, line 81
def getCyclesByProjectId(projectId, versionId)
  response = sendRequest("/jira/rest/zapi/latest/cycle?projectId=#{projectId}&versionId=#{versionId}")
  puts __FILE__ + (__LINE__).to_s + " ==== Cycles for Project #{projectId} ====\n"  if @debug

  QResponse.new(response)
end
getExecutions(opt) click to toggle source
# File lib/zephyr_client/base/client.rb, line 189
def getExecutions(opt)
  rc = nil
  if opt[:projectId] && opt[:versionId] && opt[:cycleId]
    response = sendRequest("/jira/rest/zapi/latest/execution?projectId=#{opt[:projectId]}&versionId=#{opt[:versionId]}&cycleId=#{opt[:cycleId]}", {'Accept' => 'application/json'})
    rc = QResponse.new(response).to_json
  end

  rc
end
getProject(projectId) click to toggle source
# File lib/zephyr_client/base/client.rb, line 95
def getProject(projectId)
  response = sendRequest("/jira/rest/api/2/project/#{projectId}")
  puts __FILE__ + (__LINE__).to_s + " ==== Project #{projectId} ====\n" if @debug

  QResponse.new(response)
end
getProjectByKey(k) click to toggle source
# File lib/zephyr_client/base/client.rb, line 103
def getProjectByKey(k)
  #puts __FILE__ + (__LINE__).to_s + " [getProjectByKey]: #{k}"
  matches=[]
  hits = getProjects().to_json
  hits.each do |p|
    if p.is_a?(Hash)
      if p.has_key?('key') && p['key']==k
        matches << p
      end

    else
      raise "UNEXPECTED::TypeError::#{p.class}"
    end
  end

  matches
end
getProjectCycles(projectId) click to toggle source
# File lib/zephyr_client/base/client.rb, line 121
def getProjectCycles(projectId)
  response = sendRequest("/jira/rest/zapi/latest/cycle?projectId=#{projectId}")
  puts __FILE__ + (__LINE__).to_s + " ==== Cycles for Project #{projectId} ====\n"

  response.body
end
getProjectPerRelease(projectKey, expected_release, cycle, debug = @debug) click to toggle source
# File lib/zephyr_client/base/client.rb, line 129
def getProjectPerRelease(projectKey, expected_release, cycle, debug = @debug)
  projectId = nil
  cycleId = nil
  versionId = nil

  hits = getProjectByKey(projectKey)


  if hits.size==1

    projectId = hits[0]['id']

    puts "\n\n=========== getProject(#{projectId} ============"  if @debug
    project = getProject(projectId).to_json

    if debug
      puts __FILE__ + (__LINE__).to_s + " hits => #{project.keys.sort.to_s}"
      pp project
      puts '*' * 72
    end

    project['versions'].each do |v|
      puts __FILE__ + (__LINE__).to_s +  " KEY #{v} => " if @debug

      if v['name'].match(/#{expected_release}/)
        puts "RELEASE: #{v['id']} : #{v['name']}" if @debug
        versionId = v['id']
      end
    end

    if versionId

      ## Find the Cycle (e.g. Sprint)
      ## We have the projectID, versionId, now let's get the CycleID
      rc = getCyclesByProjectId(projectId, versionId)
      pp rc.to_json if @debug

      rc.to_json.each_pair do |k, v|

        if v.is_a?(Hash) && v.has_key?('name') && v['name'].match(/#{cycle}/)
          cycleId = k.to_s

          if @debug
            puts __FILE__ + (__LINE__).to_s + " cycleId #{k.to_s}"
            pp k
          end

        elsif !v.is_a?(Hash)
          puts "#{k} => #{v}" if @debug
        end
      end

    end

  end

  { :projectId => projectId, :cycleId => cycleId, :versionId => versionId }
end
getProjects() click to toggle source
# File lib/zephyr_client/base/client.rb, line 89
def getProjects()
  response = sendRequest("/jira/rest/api/2/project/")
  puts __FILE__ + (__LINE__).to_s + " ==== All Projects ====\n" if @debug
  QResponse.new(response)
end
sendRequest(path, headers = {'Accept' => 'application/json'}) click to toggle source
# File lib/zephyr_client/base/client.rb, line 64
def sendRequest(path, headers = {'Accept' => 'application/json'})
  request = ZephyrClient::Utils::createRequest(@user, 'get', path, nil, headers)
  connection = connect(@options['site'])

  puts __FILE__ + (__LINE__).to_s + " connection => #{connection.class}" if @debug
  response = connection.request(request)
  response
end
setUser(u) click to toggle source
# File lib/zephyr_client/base/client.rb, line 49
def setUser(u)
  @user = u
end
updateTestStatus(id, status) click to toggle source

body = { “status” => “3”}

# File lib/zephyr_client/base/client.rb, line 201
def updateTestStatus(id, status)

  unless ZephyrClient::ZSTATUS.has_key?(status.downcase)
    raise "UNKNOWN::STATUS::#{status.to_s}"
  end

  body = "{ \"status\" : \"#{ZephyrClient::ZSTATUS[status.downcase]}\"  }"

  request = ZephyrClient::Utils::createRequest(@user, 'PUT', "#{EXECUTION_CMD}/#{id}/execute", body, {'Content-Type' => 'application/json'})
  httpReq = connect(@options['site'])
  response = httpReq.request(request)

  if ZephyrClient::Utils::isVerbose()
    puts ">>>>>  TEST STATUS <<<<<<"
    puts response
  end

  response
end